diff --git a/extensions/mongodb-client/deployment/pom.xml b/extensions/mongodb-client/deployment/pom.xml index e97646dc79fd8..36b104c57bf4b 100644 --- a/extensions/mongodb-client/deployment/pom.xml +++ b/extensions/mongodb-client/deployment/pom.xml @@ -91,6 +91,11 @@ awaitility test + + org.mockito + mockito-core + test + org.assertj assertj-core diff --git a/extensions/mongodb-client/deployment/src/main/java/io/quarkus/mongodb/deployment/MongoClientProcessor.java b/extensions/mongodb-client/deployment/src/main/java/io/quarkus/mongodb/deployment/MongoClientProcessor.java index 2dd946cf874e2..68003f57ea613 100644 --- a/extensions/mongodb-client/deployment/src/main/java/io/quarkus/mongodb/deployment/MongoClientProcessor.java +++ b/extensions/mongodb-client/deployment/src/main/java/io/quarkus/mongodb/deployment/MongoClientProcessor.java @@ -126,18 +126,18 @@ AdditionalIndexedClassesBuildItem includeMongoCommandListener(MongoClientBuildTi } @BuildStep - AdditionalIndexedClassesBuildItem includeMongoCommandMetricListener( + void includeMongoCommandMetricListener( + BuildProducer additionalIndexedClasses, MongoClientBuildTimeConfig buildTimeConfig, Optional metricsCapability) { if (!buildTimeConfig.metricsEnabled) { - return new AdditionalIndexedClassesBuildItem(); + return; } boolean withMicrometer = metricsCapability.map(cap -> cap.metricsSupported(MetricsFactory.MICROMETER)) .orElse(false); if (withMicrometer) { - return new AdditionalIndexedClassesBuildItem(MicrometerCommandListener.class.getName()); + additionalIndexedClasses.produce(new AdditionalIndexedClassesBuildItem(MicrometerCommandListener.class.getName())); } - return new AdditionalIndexedClassesBuildItem(); } @BuildStep diff --git a/extensions/mongodb-client/deployment/src/test/java/io/quarkus/mongodb/deployment/MongoClientProcessorTest.java b/extensions/mongodb-client/deployment/src/test/java/io/quarkus/mongodb/deployment/MongoClientProcessorTest.java index 86dae2cdda77f..ad437dc2dc882 100644 --- a/extensions/mongodb-client/deployment/src/test/java/io/quarkus/mongodb/deployment/MongoClientProcessorTest.java +++ b/extensions/mongodb-client/deployment/src/test/java/io/quarkus/mongodb/deployment/MongoClientProcessorTest.java @@ -1,12 +1,16 @@ package io.quarkus.mongodb.deployment; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; import java.util.Optional; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; +import org.mockito.ArgumentCaptor; +import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.builditem.AdditionalIndexedClassesBuildItem; import io.quarkus.deployment.metrics.MetricsCapabilityBuildItem; import io.quarkus.runtime.metrics.MetricsFactory; @@ -14,6 +18,7 @@ class MongoClientProcessorTest { private final MongoClientProcessor buildStep = new MongoClientProcessor(); + @SuppressWarnings("unchecked") @ParameterizedTest @CsvSource({ "true, true, true", // Metrics enabled and Micrometer supported @@ -25,13 +30,16 @@ void testIncludeMongoCommandMetricListener(boolean metricsEnabled, boolean micro MongoClientBuildTimeConfig config = config(metricsEnabled); Optional capability = capability(metricsEnabled, micrometerSupported); - AdditionalIndexedClassesBuildItem result = buildStep.includeMongoCommandMetricListener(config, capability); + BuildProducer buildProducer = mock(BuildProducer.class); + buildStep.includeMongoCommandMetricListener(buildProducer, config, capability); if (expectedResult) { - assertThat(result.getClassesToIndex()) + var captor = ArgumentCaptor.forClass(AdditionalIndexedClassesBuildItem.class); + verify(buildProducer, times(1)).produce(captor.capture()); + assertThat(captor.getAllValues().get(0).getClassesToIndex()) .containsExactly("io.quarkus.mongodb.metrics.MicrometerCommandListener"); } else { - assertThat(result.getClassesToIndex()).isEmpty(); + verify(buildProducer, never()).produce(any(AdditionalIndexedClassesBuildItem.class)); } }