diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfigurationTests.java index e52ed84b50..88e0a2a1af 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfigurationTests.java @@ -93,20 +93,25 @@ public class MetricFilterAutoConfigurationTests { public void recordsHttpInteractions() throws Exception { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( Config.class, MetricFilterAutoConfiguration.class); - Filter filter = context.getBean(Filter.class); - final MockHttpServletRequest request = new MockHttpServletRequest("GET", - "/test/path"); - final MockHttpServletResponse response = new MockHttpServletResponse(); - FilterChain chain = mock(FilterChain.class); - willAnswer((invocation) -> { - response.setStatus(200); - return null; - }).given(chain).doFilter(request, response); - filter.doFilter(request, response, chain); - verify(context.getBean(CounterService.class)).increment("status.200.test.path"); - verify(context.getBean(GaugeService.class)).submit(eq("response.test.path"), - anyDouble()); - context.close(); + try { + Filter filter = context.getBean(Filter.class); + MockHttpServletRequest request = new MockHttpServletRequest("GET", + "/test/path"); + MockHttpServletResponse response = new MockHttpServletResponse(); + FilterChain chain = mock(FilterChain.class); + willAnswer((invocation) -> { + response.setStatus(200); + return null; + }).given(chain).doFilter(request, response); + filter.doFilter(request, response, chain); + verify(context.getBean(CounterService.class)) + .increment("status.200.test.path"); + verify(context.getBean(GaugeService.class)).submit(eq("response.test.path"), + anyDouble()); + } + finally { + context.close(); + } } @Test @@ -355,9 +360,8 @@ public class MetricFilterAutoConfigurationTests { .applyTo(context); context.refresh(); Filter filter = context.getBean(Filter.class); - final MockHttpServletRequest request = new MockHttpServletRequest("PUT", - "/test/path"); - final MockHttpServletResponse response = new MockHttpServletResponse(); + MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/test/path"); + MockHttpServletResponse response = new MockHttpServletResponse(); FilterChain chain = mock(FilterChain.class); willAnswer((invocation) -> { response.setStatus(200); @@ -383,9 +387,8 @@ public class MetricFilterAutoConfigurationTests { "endpoints.metrics.filter.counter-submissions=").applyTo(context); context.refresh(); Filter filter = context.getBean(Filter.class); - final MockHttpServletRequest request = new MockHttpServletRequest("PUT", - "/test/path"); - final MockHttpServletResponse response = new MockHttpServletResponse(); + MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/test/path"); + MockHttpServletResponse response = new MockHttpServletResponse(); FilterChain chain = mock(FilterChain.class); willAnswer((invocation) -> { response.setStatus(200); @@ -402,28 +405,32 @@ public class MetricFilterAutoConfigurationTests { public void whenExceptionIsThrownResponseStatusIsUsedWhenResponseHasBeenCommitted() throws Exception { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); - context.register(Config.class, MetricFilterAutoConfiguration.class); - context.refresh(); - Filter filter = context.getBean(Filter.class); - final MockHttpServletRequest request = new MockHttpServletRequest("GET", - "/test/path"); - final MockHttpServletResponse response = new MockHttpServletResponse(); - FilterChain chain = mock(FilterChain.class); - willAnswer((invocation) -> { - response.setStatus(200); - response.setCommitted(true); - throw new IOException(); - }).given(chain).doFilter(request, response); try { - filter.doFilter(request, response, chain); - fail(); + context.register(Config.class, MetricFilterAutoConfiguration.class); + context.refresh(); + Filter filter = context.getBean(Filter.class); + MockHttpServletRequest request = new MockHttpServletRequest("GET", + "/test/path"); + MockHttpServletResponse response = new MockHttpServletResponse(); + FilterChain chain = mock(FilterChain.class); + willAnswer((invocation) -> { + response.setStatus(200); + response.setCommitted(true); + throw new IOException(); + }).given(chain).doFilter(request, response); + try { + filter.doFilter(request, response, chain); + fail(); + } + catch (IOException ex) { + // Continue + } + verify(context.getBean(CounterService.class)) + .increment(eq("status.200.test.path")); } - catch (IOException ex) { - // Continue + finally { + context.close(); } - verify(context.getBean(CounterService.class)) - .increment(eq("status.200.test.path")); - context.close(); } @Configuration diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/template/PathBasedTemplateAvailabilityProvider.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/template/PathBasedTemplateAvailabilityProvider.java index 9217b4f4ba..2fc7c19cca 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/template/PathBasedTemplateAvailabilityProvider.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/template/PathBasedTemplateAvailabilityProvider.java @@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.template; import java.util.List; -import org.springframework.boot.autoconfigure.template.PathBasedTemplateAvailabilityProvider.TemplateAvailabilityProperties; import org.springframework.boot.context.properties.bind.Binder; import org.springframework.core.env.Environment; import org.springframework.core.io.ResourceLoader; @@ -33,19 +32,21 @@ import org.springframework.util.ClassUtils; * @author Madhura Bhave * @since 1.4.6 */ -public abstract class PathBasedTemplateAvailabilityProvider +public abstract class PathBasedTemplateAvailabilityProvider implements TemplateAvailabilityProvider { private final String className; - private final Class propertiesClass; + private final Class propertiesClass; private final String propertyPrefix; + @SuppressWarnings("unchecked") public PathBasedTemplateAvailabilityProvider(String className, - Class propertiesClass, String propertyPrefix) { + Class propertiesClass, + String propertyPrefix) { this.className = className; - this.propertiesClass = propertiesClass; + this.propertiesClass = (Class) propertiesClass; this.propertyPrefix = propertyPrefix; } @@ -54,9 +55,10 @@ public abstract class PathBasedTemplateAvailabilityProvider content = new JsonContent<>(getClass(), TYPE, JSON); assertThat(content.assertThat()).isInstanceOf(JsonContentAssert.class); diff --git a/spring-boot/src/main/java/org/springframework/boot/context/properties/source/UnboundElementsSourceFilter.java b/spring-boot/src/main/java/org/springframework/boot/context/properties/source/UnboundElementsSourceFilter.java index 2a0955c735..288513f747 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/properties/source/UnboundElementsSourceFilter.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/properties/source/UnboundElementsSourceFilter.java @@ -46,7 +46,7 @@ public class UnboundElementsSourceFilter public Boolean apply(ConfigurationPropertySource configurationPropertySource) { Object underlyingSource = configurationPropertySource.getUnderlyingSource(); if (underlyingSource instanceof PropertySource) { - String name = ((PropertySource) underlyingSource).getName(); + String name = ((PropertySource) underlyingSource).getName(); return !BENIGN_PROPERTY_SOURCE_NAMES.contains(name); } diff --git a/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowReactiveWebServerFactory.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowReactiveWebServerFactory.java index 046631c913..de14b42dd5 100644 --- a/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowReactiveWebServerFactory.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowReactiveWebServerFactory.java @@ -117,8 +117,8 @@ public class UndertowReactiveWebServerFactory extends AbstractReactiveWebServerF /** * Set {@link UndertowBuilderCustomizer}s that should be applied to the Undertow - * {@link Undertow.Builder}. Calling this method will replace any existing - * customizers. + * {@link io.undertow.Undertow.Builder Builder}. Calling this method will replace any + * existing customizers. * @param customizers the customizers to set */ public void setBuilderCustomizers( @@ -129,7 +129,7 @@ public class UndertowReactiveWebServerFactory extends AbstractReactiveWebServerF /** * Returns a mutable collection of the {@link UndertowBuilderCustomizer}s that will be - * applied to the Undertow {@link Undertow.Builder} . + * applied to the Undertow {@link io.undertow.Undertow.Builder Builder}. * @return the customizers that will be applied */ public Collection getBuilderCustomizers() { @@ -138,7 +138,7 @@ public class UndertowReactiveWebServerFactory extends AbstractReactiveWebServerF /** * Add {@link UndertowBuilderCustomizer}s that should be used to customize the - * Undertow {@link Undertow.Builder}. + * Undertow {@link io.undertow.Undertow.Builder Builder}. * @param customizers the customizers to add */ public void addBuilderCustomizers(UndertowBuilderCustomizer... customizers) {