3535import org .springframework .boot .web .embedded .jetty .JettyServletWebServerFactory ;
3636import org .springframework .boot .web .reactive .context .AnnotationConfigReactiveWebServerApplicationContext ;
3737import org .springframework .boot .web .servlet .context .AnnotationConfigServletWebServerApplicationContext ;
38+ import org .springframework .context .ConfigurableApplicationContext ;
3839import org .springframework .context .annotation .Bean ;
3940import org .springframework .context .annotation .Configuration ;
4041import org .springframework .http .server .reactive .HttpHandler ;
@@ -57,8 +58,7 @@ void autoConfiguresThreadPoolMetricsWithEmbeddedServletJetty() {
5758 ServletWebServerFactoryAutoConfiguration .class ))
5859 .withUserConfiguration (ServletWebServerConfiguration .class , MeterRegistryConfiguration .class )
5960 .run ((context ) -> {
60- context .publishEvent (new ApplicationStartedEvent (new SpringApplication (), null ,
61- context .getSourceApplicationContext ()));
61+ context .publishEvent (createApplicationStartedEvent (context .getSourceApplicationContext ()));
6262 assertThat (context ).hasSingleBean (JettyServerThreadPoolMetricsBinder .class );
6363 SimpleMeterRegistry registry = context .getBean (SimpleMeterRegistry .class );
6464 assertThat (registry .find ("jetty.threads.config.min" ).meter ()).isNotNull ();
@@ -72,8 +72,7 @@ void autoConfiguresThreadPoolMetricsWithEmbeddedReactiveJetty() {
7272 ReactiveWebServerFactoryAutoConfiguration .class ))
7373 .withUserConfiguration (ReactiveWebServerConfiguration .class , MeterRegistryConfiguration .class )
7474 .run ((context ) -> {
75- context .publishEvent (new ApplicationStartedEvent (new SpringApplication (), null ,
76- context .getSourceApplicationContext ()));
75+ context .publishEvent (createApplicationStartedEvent (context .getSourceApplicationContext ()));
7776 SimpleMeterRegistry registry = context .getBean (SimpleMeterRegistry .class );
7877 assertThat (registry .find ("jetty.threads.config.min" ).meter ()).isNotNull ();
7978 });
@@ -94,8 +93,7 @@ void autoConfiguresConnectionMetricsWithEmbeddedServletJetty() {
9493 ServletWebServerFactoryAutoConfiguration .class ))
9594 .withUserConfiguration (ServletWebServerConfiguration .class , MeterRegistryConfiguration .class )
9695 .run ((context ) -> {
97- context .publishEvent (new ApplicationStartedEvent (new SpringApplication (), null ,
98- context .getSourceApplicationContext ()));
96+ context .publishEvent (createApplicationStartedEvent (context .getSourceApplicationContext ()));
9997 assertThat (context ).hasSingleBean (JettyConnectionMetricsBinder .class );
10098 SimpleMeterRegistry registry = context .getBean (SimpleMeterRegistry .class );
10199 assertThat (registry .find ("jetty.connections.messages.in" ).meter ()).isNotNull ();
@@ -109,8 +107,7 @@ void autoConfiguresConnectionMetricsWithEmbeddedReactiveJetty() {
109107 ReactiveWebServerFactoryAutoConfiguration .class ))
110108 .withUserConfiguration (ReactiveWebServerConfiguration .class , MeterRegistryConfiguration .class )
111109 .run ((context ) -> {
112- context .publishEvent (new ApplicationStartedEvent (new SpringApplication (), null ,
113- context .getSourceApplicationContext ()));
110+ context .publishEvent (createApplicationStartedEvent (context .getSourceApplicationContext ()));
114111 SimpleMeterRegistry registry = context .getBean (SimpleMeterRegistry .class );
115112 assertThat (registry .find ("jetty.connections.messages.in" ).meter ()).isNotNull ();
116113 });
@@ -124,8 +121,7 @@ void allowsCustomJettyConnectionMetricsBinderToBeUsed() {
124121 .withUserConfiguration (ServletWebServerConfiguration .class , CustomJettyConnectionMetricsBinder .class ,
125122 MeterRegistryConfiguration .class )
126123 .run ((context ) -> {
127- context .publishEvent (new ApplicationStartedEvent (new SpringApplication (), null ,
128- context .getSourceApplicationContext ()));
124+ context .publishEvent (createApplicationStartedEvent (context .getSourceApplicationContext ()));
129125 assertThat (context ).hasSingleBean (JettyConnectionMetricsBinder .class )
130126 .hasBean ("customJettyConnectionMetricsBinder" );
131127 SimpleMeterRegistry registry = context .getBean (SimpleMeterRegistry .class );
@@ -143,8 +139,7 @@ void autoConfiguresSslHandshakeMetricsWithEmbeddedServletJetty() {
143139 .withPropertyValues ("server.ssl.enabled: true" , "server.ssl.key-store: src/test/resources/test.jks" ,
144140 "server.ssl.key-store-password: secret" , "server.ssl.key-password: password" )
145141 .run ((context ) -> {
146- context .publishEvent (new ApplicationStartedEvent (new SpringApplication (), null ,
147- context .getSourceApplicationContext ()));
142+ context .publishEvent (createApplicationStartedEvent (context .getSourceApplicationContext ()));
148143 assertThat (context ).hasSingleBean (JettySslHandshakeMetricsBinder .class );
149144 SimpleMeterRegistry registry = context .getBean (SimpleMeterRegistry .class );
150145 assertThat (registry .find ("jetty.ssl.handshakes" ).meter ()).isNotNull ();
@@ -160,8 +155,7 @@ void autoConfiguresSslHandshakeMetricsWithEmbeddedReactiveJetty() {
160155 .withPropertyValues ("server.ssl.enabled: true" , "server.ssl.key-store: src/test/resources/test.jks" ,
161156 "server.ssl.key-store-password: secret" , "server.ssl.key-password: password" )
162157 .run ((context ) -> {
163- context .publishEvent (new ApplicationStartedEvent (new SpringApplication (), null ,
164- context .getSourceApplicationContext ()));
158+ context .publishEvent (createApplicationStartedEvent (context .getSourceApplicationContext ()));
165159 SimpleMeterRegistry registry = context .getBean (SimpleMeterRegistry .class );
166160 assertThat (registry .find ("jetty.ssl.handshakes" ).meter ()).isNotNull ();
167161 });
@@ -177,8 +171,7 @@ void allowsCustomJettySslHandshakeMetricsBinderToBeUsed() {
177171 .withPropertyValues ("server.ssl.enabled: true" , "server.ssl.key-store: src/test/resources/test.jks" ,
178172 "server.ssl.key-store-password: secret" , "server.ssl.key-password: password" )
179173 .run ((context ) -> {
180- context .publishEvent (new ApplicationStartedEvent (new SpringApplication (), null ,
181- context .getSourceApplicationContext ()));
174+ context .publishEvent (createApplicationStartedEvent (context .getSourceApplicationContext ()));
182175 assertThat (context ).hasSingleBean (JettySslHandshakeMetricsBinder .class )
183176 .hasBean ("customJettySslHandshakeMetricsBinder" );
184177 SimpleMeterRegistry registry = context .getBean (SimpleMeterRegistry .class );
@@ -213,6 +206,10 @@ void doesNotAutoConfigureSslHandshakeMetricsWhenSslEnabledPropertySetToFalse() {
213206 .run ((context ) -> assertThat (context ).doesNotHaveBean (JettySslHandshakeMetricsBinder .class ));
214207 }
215208
209+ private ApplicationStartedEvent createApplicationStartedEvent (ConfigurableApplicationContext context ) {
210+ return new ApplicationStartedEvent (new SpringApplication (), null , context , null );
211+ }
212+
216213 @ Configuration (proxyBeanMethods = false )
217214 static class MeterRegistryConfiguration {
218215
0 commit comments