diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/web/TestController.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/web/TestController.java index 824f0a2c83d..42d81a70dd1 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/web/TestController.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/web/TestController.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,7 +49,7 @@ public class TestController { @Timed @GetMapping("test3") public String test3() { - return "test2"; + return "test3"; } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/web/servlet/WebMvcMetricsAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/web/servlet/WebMvcMetricsAutoConfigurationTests.java index 18df57e9459..d2c1448c5a3 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/web/servlet/WebMvcMetricsAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/web/servlet/WebMvcMetricsAutoConfigurationTests.java @@ -71,8 +71,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @ExtendWith(OutputCaptureExtension.class) class WebMvcMetricsAutoConfigurationTests { - private WebApplicationContextRunner contextRunner = new WebApplicationContextRunner().with(MetricsRun.simple()) - .withConfiguration(AutoConfigurations.of(WebMvcMetricsAutoConfiguration.class)); + private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner() + .with(MetricsRun.simple()).withConfiguration(AutoConfigurations.of(WebMvcMetricsAutoConfiguration.class)); @Test void backsOffWhenMeterRegistryIsMissing() { @@ -183,11 +183,12 @@ class WebMvcMetricsAutoConfigurationTests { .contains(LongTaskTimingHandlerInterceptor.class)); } + private MeterRegistry getInitializedMeterRegistry(AssertableWebApplicationContext context) throws Exception { + return getInitializedMeterRegistry(context, "/test0", "/test1", "/test2"); + } + private MeterRegistry getInitializedMeterRegistry(AssertableWebApplicationContext context, String... urls) throws Exception { - if (urls.length == 0) { - urls = new String[] { "/test0", "/test1", "/test2" }; - } assertThat(context).hasSingleBean(FilterRegistrationBean.class); Filter filter = context.getBean(FilterRegistrationBean.class).getFilter(); assertThat(filter).isInstanceOf(WebMvcMetricsFilter.class); diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetricsFilter.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetricsFilter.java index 6961091714b..df3fc1f506b 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetricsFilter.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetricsFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -144,11 +144,11 @@ public class WebMvcMetricsFilter extends OncePerRequestFilter { Builder builder = this.autoTimer.builder(this.metricName); timerSample.stop(getTimer(builder, handler, request, response, exception)); } - return; - } - for (Timed annotation : annotations) { - Builder builder = Timer.builder(annotation, this.metricName); - timerSample.stop(getTimer(builder, handler, request, response, exception)); + } else { + for (Timed annotation : annotations) { + Builder builder = Timer.builder(annotation, this.metricName); + timerSample.stop(getTimer(builder, handler, request, response, exception)); + } } }