From 31a6e98eaf08d7568345ea038c4b089ed281c3aa Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Mon, 16 Sep 2024 15:43:54 +0200 Subject: [PATCH] =?UTF-8?q?Introduce=20@=E2=81=A0Disabled=20AOT=20tests=20?= =?UTF-8?q?for=20@=E2=81=A0TestBean=20support?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See gh-32933 --- .../test/context/aot/AotIntegrationTests.java | 16 +++++- .../convention/TestBeanJupiterTests.java | 56 +++++++++++++++++++ ...stBeanForByNameLookupIntegrationTests.java | 6 +- 3 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 spring-test/src/test/java/org/springframework/test/context/aot/samples/bean/override/convention/TestBeanJupiterTests.java diff --git a/spring-test/src/test/java/org/springframework/test/context/aot/AotIntegrationTests.java b/spring-test/src/test/java/org/springframework/test/context/aot/AotIntegrationTests.java index c8602dd4fc06..7c23d97ea3ac 100644 --- a/spring-test/src/test/java/org/springframework/test/context/aot/AotIntegrationTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/aot/AotIntegrationTests.java @@ -145,11 +145,25 @@ void endToEndTestsForEntireSpringTestModule() { runEndToEndTests(testClasses, false); } + @Disabled("Comment out to run @TestBean integration tests in AOT mode") + @Test + void endToEndTestsForTestBeanOverrideTestClasses() { + List> testClasses = List.of( + org.springframework.test.context.aot.samples.bean.override.convention.TestBeanJupiterTests.class, + org.springframework.test.context.bean.override.convention.TestBeanForByNameLookupIntegrationTests.class, + org.springframework.test.context.bean.override.convention.TestBeanForByNameLookupIntegrationTests.TestBeanFieldInEnclosingClassTests.class, + org.springframework.test.context.bean.override.convention.TestBeanForByNameLookupIntegrationTests.TestBeanFieldInEnclosingClassTests.TestBeanFieldInEnclosingClassLevel2Tests.class, + org.springframework.test.context.bean.override.convention.TestBeanForByNameLookupIntegrationTests.TestBeanFactoryMethodInEnclosingClassTests.class, + org.springframework.test.context.bean.override.convention.TestBeanForByNameLookupIntegrationTests.TestBeanFactoryMethodInEnclosingClassTests.TestBeanFactoryMethodInEnclosingClassLevel2Tests.class + ); + + runEndToEndTests(testClasses, true); + } + @Disabled("Comment out to run selected integration tests in AOT mode") @Test void endToEndTestsForSelectedTestClasses() { List> testClasses = List.of( - org.springframework.test.context.bean.override.convention.TestBeanForByNameLookupIntegrationTests.class, org.springframework.test.context.bean.override.mockito.MockitoBeanForByNameLookupIntegrationTests.class, org.springframework.test.context.junit4.SpringJUnit4ClassRunnerAppCtxTests.class, org.springframework.test.context.junit4.ParameterizedDependencyInjectionTests.class diff --git a/spring-test/src/test/java/org/springframework/test/context/aot/samples/bean/override/convention/TestBeanJupiterTests.java b/spring-test/src/test/java/org/springframework/test/context/aot/samples/bean/override/convention/TestBeanJupiterTests.java new file mode 100644 index 000000000000..464a5cdce7bb --- /dev/null +++ b/spring-test/src/test/java/org/springframework/test/context/aot/samples/bean/override/convention/TestBeanJupiterTests.java @@ -0,0 +1,56 @@ +/* + * Copyright 2002-2024 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.test.context.aot.samples.bean.override.convention; + +import org.junit.jupiter.api.Test; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.test.context.bean.override.convention.TestBean; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Sam Brannen + * @since 6.2 + */ +@SpringJUnitConfig +public class TestBeanJupiterTests { + + @TestBean + String magicBean; + + static String magicBean() { + return "enigma-override"; + } + + @Test + void tests() { + assertThat(magicBean).isEqualTo("enigma-override"); + } + + @Configuration(proxyBeanMethods = false) + static class Config { + + @Bean + String magicBean() { + return "enigma"; + } + } + +} diff --git a/spring-test/src/test/java/org/springframework/test/context/bean/override/convention/TestBeanForByNameLookupIntegrationTests.java b/spring-test/src/test/java/org/springframework/test/context/bean/override/convention/TestBeanForByNameLookupIntegrationTests.java index 41aa6b307b6f..5c051f274757 100644 --- a/spring-test/src/test/java/org/springframework/test/context/bean/override/convention/TestBeanForByNameLookupIntegrationTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/bean/override/convention/TestBeanForByNameLookupIntegrationTests.java @@ -106,7 +106,7 @@ void fieldWithMethodNameHasOverride(ApplicationContext ctx) { @Nested @DisplayName("With @TestBean in the enclosing class of the enclosing class") - class TestBeanFieldInEnclosingClassLevel2Tests { + public class TestBeanFieldInEnclosingClassLevel2Tests { @Test void fieldHasOverride(ApplicationContext ctx) { @@ -130,7 +130,7 @@ void fieldWithMethodNameHasOverride(ApplicationContext ctx) { @Nested @DisplayName("With factory method in enclosing class") - class TestBeanFactoryMethodInEnclosingClassTests { + public class TestBeanFactoryMethodInEnclosingClassTests { @TestBean(methodName = "nestedField", name = "nestedField") String nestedField2; @@ -143,7 +143,7 @@ void fieldHasOverride(ApplicationContext ctx) { @Nested @DisplayName("With factory method in the enclosing class of the enclosing class") - class TestBeanFactoryMethodInEnclosingClassLevel2Tests { + public class TestBeanFactoryMethodInEnclosingClassLevel2Tests { @TestBean(methodName = "nestedField", name = "nestedField") String nestedField2;