diff --git a/spring-modulith-integration-test/src/test/java/com/acme/myproject/moduleA/ApplicationModuleTestIntegrationTests.java b/spring-modulith-integration-test/src/test/java/com/acme/myproject/moduleA/ApplicationModuleTestIntegrationTests.java new file mode 100644 index 00000000..7734269a --- /dev/null +++ b/spring-modulith-integration-test/src/test/java/com/acme/myproject/moduleA/ApplicationModuleTestIntegrationTests.java @@ -0,0 +1,39 @@ +/* + * Copyright 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 com.acme.myproject.moduleA; + +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.springframework.modulith.test.ApplicationModuleTest; + +/** + * Integration tests for {@link ApplicationModuleTest}. + * + * @author Oliver Drotbohm + */ +@ApplicationModuleTest(verifyAutomatically = false) +class ApplicationModuleTestIntegrationTests { + + @Test // GH-173 + void bootstrapsFirstLevelTestMethod() {} + + @Nested + class SomeNestedClass { + + @Test // GH-173 + void bootstrapsSecondLevelMestMethod() {} + } +} diff --git a/spring-modulith-test/src/main/java/org/springframework/modulith/test/ModuleContextCustomizerFactory.java b/spring-modulith-test/src/main/java/org/springframework/modulith/test/ModuleContextCustomizerFactory.java index 3afe698b..7be11938 100644 --- a/spring-modulith-test/src/main/java/org/springframework/modulith/test/ModuleContextCustomizerFactory.java +++ b/spring-modulith-test/src/main/java/org/springframework/modulith/test/ModuleContextCustomizerFactory.java @@ -25,12 +25,12 @@ import java.util.stream.Stream; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.modulith.core.ApplicationModule; import org.springframework.test.context.ContextConfigurationAttributes; import org.springframework.test.context.ContextCustomizer; import org.springframework.test.context.ContextCustomizerFactory; import org.springframework.test.context.MergedContextConfiguration; +import org.springframework.test.context.TestContextAnnotationUtils; /** * @author Oliver Drotbohm @@ -45,9 +45,9 @@ class ModuleContextCustomizerFactory implements ContextCustomizerFactory { public ContextCustomizer createContextCustomizer(Class testClass, List configAttributes) { - var moduleTest = AnnotatedElementUtils.getMergedAnnotation(testClass, ApplicationModuleTest.class); + var moduleTest = TestContextAnnotationUtils.findAnnotationDescriptor(testClass, ApplicationModuleTest.class); - return moduleTest == null ? null : new ModuleContextCustomizer(testClass); + return moduleTest == null ? null : new ModuleContextCustomizer(moduleTest.getRootDeclaringClass()); } static class ModuleContextCustomizer implements ContextCustomizer {