diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsPropertiesConfigAdapterTests.java index 6b5de57c7f..54ab9c2aba 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsPropertiesConfigAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2023 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. @@ -30,6 +30,10 @@ import static org.assertj.core.api.Assertions.assertThat; class AppOpticsPropertiesConfigAdapterTests extends StepRegistryPropertiesConfigAdapterTests { + AppOpticsPropertiesConfigAdapterTests() { + super(AppOpticsPropertiesConfigAdapter.class); + } + @Override protected AppOpticsProperties createProperties() { return new AppOpticsProperties(); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/atlas/AtlasPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/atlas/AtlasPropertiesConfigAdapterTests.java index 6b72df2739..418f85609e 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/atlas/AtlasPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/atlas/AtlasPropertiesConfigAdapterTests.java @@ -20,6 +20,8 @@ import java.time.Duration; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -27,7 +29,12 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Mirko Sobeck */ -class AtlasPropertiesConfigAdapterTests { +class AtlasPropertiesConfigAdapterTests + extends AbstractPropertiesConfigAdapterTests { + + AtlasPropertiesConfigAdapterTests() { + super(AtlasPropertiesConfigAdapter.class); + } @Test void whenPropertiesStepIsSetAdapterStepReturnsIt() { @@ -130,4 +137,11 @@ class AtlasPropertiesConfigAdapterTests { assertThat(new AtlasPropertiesConfigAdapter(properties).lwcIgnorePublishStep()).isFalse(); } + @Test + @Override + protected void adapterOverridesAllConfigMethods() { + adapterOverridesAllConfigMethodsExcept("autoStart", "commonTags", "debugRegistry", "publisher", "rollupPolicy", + "validTagCharacters"); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogPropertiesConfigAdapterTests.java index b47892c439..c95c74b465 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogPropertiesConfigAdapterTests.java @@ -31,6 +31,10 @@ import static org.assertj.core.api.Assertions.assertThat; class DatadogPropertiesConfigAdapterTests extends StepRegistryPropertiesConfigAdapterTests { + DatadogPropertiesConfigAdapterTests() { + super(DatadogPropertiesConfigAdapter.class); + } + @Override protected DatadogProperties createProperties() { return new DatadogProperties(); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/dynatrace/DynatracePropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/dynatrace/DynatracePropertiesConfigAdapterTests.java index 16a8dd2bf9..eab487b493 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/dynatrace/DynatracePropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/dynatrace/DynatracePropertiesConfigAdapterTests.java @@ -21,6 +21,8 @@ import java.util.HashMap; import io.micrometer.dynatrace.DynatraceApiVersion; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -29,7 +31,12 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Andy Wilkinson * @author Georg Pirklbauer */ -class DynatracePropertiesConfigAdapterTests { +class DynatracePropertiesConfigAdapterTests + extends AbstractPropertiesConfigAdapterTests { + + DynatracePropertiesConfigAdapterTests() { + super(DynatracePropertiesConfigAdapter.class); + } @Test void whenPropertiesUriIsSetAdapterUriReturnsIt() { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesConfigAdapterTests.java index 8e53133703..0738af1280 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesConfigAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2023 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. @@ -18,6 +18,8 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.elastic; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -25,7 +27,12 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Andy Wilkinson */ -class ElasticPropertiesConfigAdapterTests { +class ElasticPropertiesConfigAdapterTests + extends AbstractPropertiesConfigAdapterTests { + + ElasticPropertiesConfigAdapterTests() { + super(ElasticPropertiesConfigAdapter.class); + } @Test void whenPropertiesHostsIsSetAdapterHostsReturnsIt() { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaPropertiesConfigAdapterTests.java index d837b00192..b808f1b7c6 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaPropertiesConfigAdapterTests.java @@ -22,6 +22,8 @@ import java.util.concurrent.TimeUnit; import info.ganglia.gmetric4j.gmetric.GMetric.UDPAddressingMode; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -29,7 +31,12 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Mirko Sobeck */ -class GangliaPropertiesConfigAdapterTests { +class GangliaPropertiesConfigAdapterTests + extends AbstractPropertiesConfigAdapterTests { + + GangliaPropertiesConfigAdapterTests() { + super(GangliaPropertiesConfigAdapter.class); + } @Test void whenPropertiesEnabledIsSetAdapterEnabledReturnsIt() { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphitePropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphitePropertiesConfigAdapterTests.java index ef2de2d69d..fe27c3cb27 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphitePropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphitePropertiesConfigAdapterTests.java @@ -22,6 +22,8 @@ import java.util.concurrent.TimeUnit; import io.micrometer.graphite.GraphiteProtocol; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -29,7 +31,12 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Mirko Sobeck */ -class GraphitePropertiesConfigAdapterTests { +class GraphitePropertiesConfigAdapterTests + extends AbstractPropertiesConfigAdapterTests { + + GraphitePropertiesConfigAdapterTests() { + super(GraphitePropertiesConfigAdapter.class); + } @Test void whenPropertiesEnabledIsSetAdapterEnabledReturnsIt() { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/humio/HumioPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/humio/HumioPropertiesConfigAdapterTests.java index 37b99bb9bc..9eb31796ac 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/humio/HumioPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/humio/HumioPropertiesConfigAdapterTests.java @@ -20,6 +20,8 @@ import java.util.Collections; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -27,7 +29,12 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Andy Wilkinson */ -class HumioPropertiesConfigAdapterTests { +class HumioPropertiesConfigAdapterTests + extends AbstractPropertiesConfigAdapterTests { + + HumioPropertiesConfigAdapterTests() { + super(HumioPropertiesConfigAdapter.class); + } @Test void whenApiTokenIsSetAdapterApiTokenReturnsIt() { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/influx/InfluxPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/influx/InfluxPropertiesConfigAdapterTests.java index 2d86262c66..b545bb3e1a 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/influx/InfluxPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/influx/InfluxPropertiesConfigAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2023 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. @@ -19,6 +19,8 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.influx; import io.micrometer.influx.InfluxApiVersion; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -26,7 +28,12 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Stephane Nicoll */ -class InfluxPropertiesConfigAdapterTests { +class InfluxPropertiesConfigAdapterTests + extends AbstractPropertiesConfigAdapterTests { + + InfluxPropertiesConfigAdapterTests() { + super(InfluxPropertiesConfigAdapter.class); + } @Test void adaptInfluxV1BasicConfig() { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxPropertiesConfigAdapterTests.java index 6ee12bfd5a..87ef86171e 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxPropertiesConfigAdapterTests.java @@ -20,6 +20,8 @@ import java.time.Duration; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -27,7 +29,12 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Mirko Sobeck */ -class JmxPropertiesConfigAdapterTests { +class JmxPropertiesConfigAdapterTests + extends AbstractPropertiesConfigAdapterTests { + + JmxPropertiesConfigAdapterTests() { + super(JmxPropertiesConfigAdapter.class); + } @Test void whenPropertiesStepIsSetAdapterStepReturnsIt() { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/kairos/KairosPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/kairos/KairosPropertiesConfigAdapterTests.java index 94e6617c26..02c4e7019c 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/kairos/KairosPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/kairos/KairosPropertiesConfigAdapterTests.java @@ -30,6 +30,10 @@ import static org.assertj.core.api.Assertions.assertThat; class KairosPropertiesConfigAdapterTests extends StepRegistryPropertiesConfigAdapterTests { + KairosPropertiesConfigAdapterTests() { + super(KairosPropertiesConfigAdapter.class); + } + @Override protected KairosProperties createProperties() { return new KairosProperties(); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/newrelic/NewRelicPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/newrelic/NewRelicPropertiesConfigAdapterTests.java index f3e3e80df5..1b3dd086dd 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/newrelic/NewRelicPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/newrelic/NewRelicPropertiesConfigAdapterTests.java @@ -31,6 +31,10 @@ import static org.assertj.core.api.Assertions.assertThat; class NewRelicPropertiesConfigAdapterTests extends StepRegistryPropertiesConfigAdapterTests { + NewRelicPropertiesConfigAdapterTests() { + super(NewRelicPropertiesConfigAdapter.class); + } + @Override protected NewRelicProperties createProperties() { return new NewRelicProperties(); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusPropertiesConfigAdapterTests.java index 4fa2176884..68929bf7b6 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusPropertiesConfigAdapterTests.java @@ -21,6 +21,8 @@ import java.time.Duration; import io.micrometer.prometheus.HistogramFlavor; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -28,7 +30,12 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Mirko Sobeck */ -class PrometheusPropertiesConfigAdapterTests { +class PrometheusPropertiesConfigAdapterTests + extends AbstractPropertiesConfigAdapterTests { + + PrometheusPropertiesConfigAdapterTests() { + super(PrometheusPropertiesConfigAdapter.class); + } @Test void whenPropertiesDescriptionsIsSetAdapterDescriptionsReturnsIt() { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/properties/AbstractPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/properties/AbstractPropertiesConfigAdapterTests.java new file mode 100644 index 0000000000..01082a6e16 --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/properties/AbstractPropertiesConfigAdapterTests.java @@ -0,0 +1,95 @@ +/* + * Copyright 2012-2023 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.actuate.autoconfigure.metrics.export.properties; + +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.Set; +import java.util.TreeSet; +import java.util.stream.Collectors; + +import io.micrometer.core.instrument.config.validate.Validated; +import org.junit.jupiter.api.Test; + +import org.springframework.core.annotation.AnnotatedElementUtils; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Base class for testing properties config adapters. + * + * @param

the properties used by the adapter + * @param the adapter under test + * @author Andy Wilkinson + * @author Mirko Sobeck + */ +public abstract class AbstractPropertiesConfigAdapterTests> { + + private final Class adapter; + + protected AbstractPropertiesConfigAdapterTests(Class adapter) { + this.adapter = adapter; + } + + @Test + protected void adapterOverridesAllConfigMethods() { + adapterOverridesAllConfigMethodsExcept(); + } + + protected final void adapterOverridesAllConfigMethodsExcept(String... nonConfigMethods) { + Class config = findImplementedConfig(); + Set expectedConfigMethodNames = Arrays.stream(config.getDeclaredMethods()) + .filter(Method::isDefault) + .filter(this::hasNoParameters) + .filter(this::isNotValidationMethod) + .filter(this::isNotDeprecated) + .map(Method::getName) + .collect(Collectors.toCollection(TreeSet::new)); + expectedConfigMethodNames.removeAll(Arrays.asList(nonConfigMethods)); + Set actualConfigMethodNames = new TreeSet<>(); + Class currentClass = this.adapter; + while (!Object.class.equals(currentClass)) { + actualConfigMethodNames.addAll(Arrays.stream(currentClass.getDeclaredMethods()) + .map(Method::getName) + .filter(expectedConfigMethodNames::contains) + .toList()); + currentClass = currentClass.getSuperclass(); + } + assertThat(actualConfigMethodNames).containsExactlyInAnyOrderElementsOf(expectedConfigMethodNames); + } + + private Class findImplementedConfig() { + Class[] interfaces = this.adapter.getInterfaces(); + if (interfaces.length == 1) { + return interfaces[0]; + } + throw new IllegalStateException(this.adapter + " is not a config implementation"); + } + + private boolean isNotDeprecated(Method method) { + return !AnnotatedElementUtils.hasAnnotation(method, Deprecated.class); + } + + private boolean hasNoParameters(Method method) { + return method.getParameterCount() == 0; + } + + private boolean isNotValidationMethod(Method method) { + return !Validated.class.equals(method.getReturnType()); + } + +} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/properties/PushRegistryPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/properties/PushRegistryPropertiesConfigAdapterTests.java index 94c604a3f1..4b18da38c9 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/properties/PushRegistryPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/properties/PushRegistryPropertiesConfigAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 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. @@ -30,7 +30,12 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Stephane Nicoll * @author Artsiom Yudovin */ -public abstract class PushRegistryPropertiesConfigAdapterTests

> { +public abstract class PushRegistryPropertiesConfigAdapterTests

> + extends AbstractPropertiesConfigAdapterTests> { + + protected PushRegistryPropertiesConfigAdapterTests(Class adapter) { + super(adapter); + } protected abstract P createProperties(); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/properties/StepRegistryPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/properties/StepRegistryPropertiesConfigAdapterTests.java index a0a9754b03..5124af840e 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/properties/StepRegistryPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/properties/StepRegistryPropertiesConfigAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2023 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. @@ -27,4 +27,8 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.properties public abstract class StepRegistryPropertiesConfigAdapterTests

> extends PushRegistryPropertiesConfigAdapterTests { + protected StepRegistryPropertiesConfigAdapterTests(Class adapter) { + super(adapter); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFxPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFxPropertiesConfigAdapterTests.java index 2dd2b882e8..4fa086069d 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFxPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFxPropertiesConfigAdapterTests.java @@ -31,6 +31,10 @@ import static org.assertj.core.api.Assertions.assertThat; class SignalFxPropertiesConfigAdapterTests extends StepRegistryPropertiesConfigAdapterTests { + protected SignalFxPropertiesConfigAdapterTests() { + super(SignalFxPropertiesConfigAdapter.class); + } + @Override protected SignalFxProperties createProperties() { SignalFxProperties signalFxProperties = new SignalFxProperties(); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimplePropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimplePropertiesConfigAdapterTests.java index 5b7ba9a650..5f977dc51c 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimplePropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimplePropertiesConfigAdapterTests.java @@ -21,6 +21,8 @@ import java.time.Duration; import io.micrometer.core.instrument.simple.CountingMode; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -28,7 +30,12 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Mirko Sobeck */ -class SimplePropertiesConfigAdapterTests { +class SimplePropertiesConfigAdapterTests + extends AbstractPropertiesConfigAdapterTests { + + SimplePropertiesConfigAdapterTests() { + super(SimplePropertiesConfigAdapter.class); + } @Test void whenPropertiesStepIsSetAdapterStepReturnsIt() { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverPropertiesConfigAdapterTests.java index 5fa7d7093f..3c9b8a3aca 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverPropertiesConfigAdapterTests.java @@ -21,6 +21,8 @@ import java.util.Map; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -28,7 +30,12 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Johannes Graf */ -class StackdriverPropertiesConfigAdapterTests { +class StackdriverPropertiesConfigAdapterTests + extends AbstractPropertiesConfigAdapterTests { + + StackdriverPropertiesConfigAdapterTests() { + super(StackdriverPropertiesConfigAdapter.class); + } @Test void whenPropertiesProjectIdIsSetAdapterProjectIdReturnsIt() { @@ -70,4 +77,10 @@ class StackdriverPropertiesConfigAdapterTests { .isEqualTo("external.googleapis.com/prometheus"); } + @Test + @Override + protected void adapterOverridesAllConfigMethods() { + adapterOverridesAllConfigMethodsExcept("credentials"); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdPropertiesConfigAdapterTests.java index 9eae3d00dc..4fdfddfa90 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdPropertiesConfigAdapterTests.java @@ -22,6 +22,8 @@ import io.micrometer.statsd.StatsdFlavor; import io.micrometer.statsd.StatsdProtocol; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -29,7 +31,12 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Johnny Lim */ -class StatsdPropertiesConfigAdapterTests { +class StatsdPropertiesConfigAdapterTests + extends AbstractPropertiesConfigAdapterTests { + + protected StatsdPropertiesConfigAdapterTests() { + super(StatsdPropertiesConfigAdapter.class); + } @Test void whenPropertiesEnabledIsSetAdapterEnabledReturnsIt() { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontPropertiesConfigAdapterTests.java index 2281c17bed..54234f8787 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontPropertiesConfigAdapterTests.java @@ -35,6 +35,10 @@ import static org.assertj.core.api.Assertions.assertThat; class WavefrontPropertiesConfigAdapterTests extends PushRegistryPropertiesConfigAdapterTests { + protected WavefrontPropertiesConfigAdapterTests() { + super(WavefrontPropertiesConfigAdapter.class); + } + @Override protected WavefrontProperties.Metrics.Export createProperties() { return new WavefrontProperties.Metrics.Export();