Harmonize test class names
This commit harmonizes the class names of the bean override support by using a consistent prefix for integration test, inspire from the one that was used in Spring Boot
This commit is contained in:
@@ -149,8 +149,8 @@ class AotIntegrationTests extends AbstractAotTests {
|
||||
@Test
|
||||
void endToEndTestsForSelectedTestClasses() {
|
||||
List<Class<?>> testClasses = List.of(
|
||||
org.springframework.test.context.bean.override.convention.TestBeanIntegrationTests.class,
|
||||
org.springframework.test.context.bean.override.mockito.MockitoBeanIntegrationTests.class,
|
||||
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
|
||||
);
|
||||
|
||||
@@ -39,7 +39,6 @@ import static org.junit.platform.testkit.engine.TestExecutionResultConditions.me
|
||||
* @author Simon Baslé
|
||||
* @author Sam Brannen
|
||||
* @since 6.2
|
||||
* @see TestBeanByTypeIntegrationTests
|
||||
*/
|
||||
class FailingTestBeanByTypeIntegrationTests {
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ import static org.junit.platform.testkit.engine.TestExecutionResultConditions.me
|
||||
* @author Simon Baslé
|
||||
* @author Sam Brannen
|
||||
* @since 6.2
|
||||
* @see TestBeanInheritanceIntegrationTests
|
||||
*/
|
||||
class FailingTestBeanInheritanceIntegrationTests {
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@ import static org.springframework.test.context.junit.EngineTestKitUtils.rootCaus
|
||||
* @author Simon Baslé
|
||||
* @author Sam Brannen
|
||||
* @since 6.2
|
||||
* @see TestBeanIntegrationTests
|
||||
*/
|
||||
class FailingTestBeanIntegrationTests {
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* {@link TestBean @TestBean} integration tests for success scenarios.
|
||||
* Integration tests for {@link TestBean} that use by-name lookup.
|
||||
*
|
||||
* @author Simon Baslé
|
||||
* @author Sam Brannen
|
||||
@@ -36,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @see FailingTestBeanIntegrationTests
|
||||
*/
|
||||
@SpringJUnitConfig
|
||||
public class TestBeanIntegrationTests {
|
||||
public class TestBeanForByNameLookupIntegrationTests {
|
||||
|
||||
@TestBean(name = "field")
|
||||
String field;
|
||||
@@ -90,48 +90,48 @@ public class TestBeanIntegrationTests {
|
||||
@Test
|
||||
void fieldHasOverride(ApplicationContext ctx) {
|
||||
assertThat(ctx.getBean("nestedField")).as("applicationContext").isEqualTo("nestedFieldOverride");
|
||||
assertThat(TestBeanIntegrationTests.this.nestedField).isEqualTo("nestedFieldOverride");
|
||||
assertThat(nestedField).isEqualTo("nestedFieldOverride");
|
||||
}
|
||||
|
||||
@Test
|
||||
void renamedFieldHasOverride(ApplicationContext ctx) {
|
||||
assertThat(ctx.getBean("nestedField")).as("applicationContext").isEqualTo("nestedFieldOverride");
|
||||
assertThat(TestBeanIntegrationTests.this.renamed2).isEqualTo("nestedFieldOverride");
|
||||
assertThat(renamed2).isEqualTo("nestedFieldOverride");
|
||||
}
|
||||
|
||||
@Test
|
||||
void fieldWithMethodNameHasOverride(ApplicationContext ctx) {
|
||||
assertThat(ctx.getBean("methodRenamed2")).as("applicationContext").isEqualTo("nestedFieldOverride");
|
||||
assertThat(TestBeanIntegrationTests.this.methodRenamed2).isEqualTo("nestedFieldOverride");
|
||||
assertThat(methodRenamed2).isEqualTo("nestedFieldOverride");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@DisplayName("With @TestBean in the enclosing class of the enclosing class")
|
||||
public class TestBeanFieldInEnclosingClassLevel2Tests {
|
||||
class TestBeanFieldInEnclosingClassLevel2Tests {
|
||||
|
||||
@Test
|
||||
void fieldHasOverride(ApplicationContext ctx) {
|
||||
assertThat(ctx.getBean("nestedField")).as("applicationContext").isEqualTo("nestedFieldOverride");
|
||||
assertThat(TestBeanIntegrationTests.this.nestedField).isEqualTo("nestedFieldOverride");
|
||||
assertThat(nestedField).isEqualTo("nestedFieldOverride");
|
||||
}
|
||||
|
||||
@Test
|
||||
void renamedFieldHasOverride(ApplicationContext ctx) {
|
||||
assertThat(ctx.getBean("nestedField")).as("applicationContext").isEqualTo("nestedFieldOverride");
|
||||
assertThat(TestBeanIntegrationTests.this.renamed2).isEqualTo("nestedFieldOverride");
|
||||
assertThat(renamed2).isEqualTo("nestedFieldOverride");
|
||||
}
|
||||
|
||||
@Test
|
||||
void fieldWithMethodNameHasOverride(ApplicationContext ctx) {
|
||||
assertThat(ctx.getBean("methodRenamed2")).as("applicationContext").isEqualTo("nestedFieldOverride");
|
||||
assertThat(TestBeanIntegrationTests.this.methodRenamed2).isEqualTo("nestedFieldOverride");
|
||||
assertThat(methodRenamed2).isEqualTo("nestedFieldOverride");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@DisplayName("With factory method in enclosing class")
|
||||
public class TestBeanFactoryMethodInEnclosingClassTests {
|
||||
class TestBeanFactoryMethodInEnclosingClassTests {
|
||||
|
||||
@TestBean(methodName = "nestedField", name = "nestedField")
|
||||
String nestedField2;
|
||||
@@ -144,7 +144,7 @@ public class TestBeanIntegrationTests {
|
||||
|
||||
@Nested
|
||||
@DisplayName("With factory method in the enclosing class of the enclosing class")
|
||||
public class TestBeanFactoryMethodInEnclosingClassLevel2Tests {
|
||||
class TestBeanFactoryMethodInEnclosingClassLevel2Tests {
|
||||
|
||||
@TestBean(methodName = "nestedField", name = "nestedField")
|
||||
String nestedField2;
|
||||
@@ -30,7 +30,7 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* {@link TestBean @TestBean} "by type" integration tests for success scenarios.
|
||||
* Integration tests for {@link TestBean} that use by-type lookup.
|
||||
*
|
||||
* @author Simon Baslé
|
||||
* @author Sam Brannen
|
||||
@@ -38,7 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @see FailingTestBeanByTypeIntegrationTests
|
||||
*/
|
||||
@SpringJUnitConfig
|
||||
public class TestBeanByTypeIntegrationTests {
|
||||
class TestBeanForByTypeLookupIntegrationTests {
|
||||
|
||||
@TestBean
|
||||
ExampleService anyNameForService;
|
||||
@@ -28,7 +28,7 @@ import org.springframework.test.context.bean.override.convention.AbstractTestBea
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* {@link TestBean @TestBean} inheritance integration tests for success scenarios.
|
||||
* Integration tests for {@link TestBean} that use inheritance.
|
||||
*
|
||||
* <p>Tests inheritance within a class hierarchy as well as "inheritance" within
|
||||
* an enclosing class hierarchy.
|
||||
@@ -38,7 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @since 6.2
|
||||
* @see FailingTestBeanInheritanceIntegrationTests
|
||||
*/
|
||||
public class TestBeanInheritanceIntegrationTests {
|
||||
class TestBeanForInheritanceIntegrationTests {
|
||||
|
||||
static Pojo enclosingClassBeanOverride() {
|
||||
return new FakePojo("in enclosing test class");
|
||||
@@ -46,7 +46,7 @@ public class TestBeanInheritanceIntegrationTests {
|
||||
|
||||
@Nested
|
||||
@DisplayName("Nested, concrete inherited tests with correct @TestBean setup")
|
||||
public class NestedConcreteTestBeanIntegrationTests extends AbstractTestBeanIntegrationTestCase {
|
||||
class NestedConcreteTestBeanIntegrationTests extends AbstractTestBeanIntegrationTestCase {
|
||||
|
||||
@Autowired
|
||||
ApplicationContext ctx;
|
||||
@@ -25,14 +25,14 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* {@link TestBean @TestBean} integration tests for test bean factory methods
|
||||
* Integration tests for {@link TestBean} that use a bean factory methods
|
||||
* defined in implemented interfaces.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 6.2
|
||||
*/
|
||||
@SpringJUnitConfig
|
||||
public class TestBeanInterfaceIntegrationTests implements TestBeanFactory {
|
||||
class TestBeanForInterfaceIntegrationTests implements TestBeanFactory {
|
||||
|
||||
@TestBean(methodName = "createTestMessage")
|
||||
String message;
|
||||
@@ -26,14 +26,14 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* {@link TestBean @TestBean} integration tests with multiple levels of
|
||||
* Integration tests for {@link TestBean} that use multiple levels of
|
||||
* {@link Nested @Nested} test classes.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 6.2
|
||||
*/
|
||||
@SpringJUnitConfig
|
||||
class MultipleNestingLevelsTestBeanIntegrationTests {
|
||||
class TestBeanForMultipleNestingLevelsIntegrationTests {
|
||||
|
||||
@TestBean(name = "field0", methodName = "testField0")
|
||||
String field0;
|
||||
@@ -39,7 +39,6 @@ import static org.junit.platform.testkit.engine.TestExecutionResultConditions.me
|
||||
* @author Simon Baslé
|
||||
* @author Sam Brannen
|
||||
* @since 6.2
|
||||
* @see MockitoBeanByTypeIntegrationTests
|
||||
*/
|
||||
class FailingMockitoBeanByTypeIntegrationTests {
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@ import static org.junit.platform.testkit.engine.TestExecutionResultConditions.me
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 6.2
|
||||
* @see MockitoSpyBeanByTypeIntegrationTests
|
||||
*/
|
||||
class FailingMockitoSpyBeanByTypeIntegrationTests {
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@ import static org.junit.platform.testkit.engine.TestExecutionResultConditions.me
|
||||
* @author Simon Baslé
|
||||
* @author Sam Brannen
|
||||
* @since 6.2
|
||||
* @see MockitoSpyBeanIntegrationTests
|
||||
*/
|
||||
class FailingMockitoSpyBeanIntegrationTests {
|
||||
|
||||
|
||||
@@ -30,8 +30,11 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link MockitoBean} that use by-name lookup.
|
||||
*/
|
||||
@SpringJUnitConfig
|
||||
public class MockitoBeanIntegrationTests {
|
||||
public class MockitoBeanForByNameLookupIntegrationTests {
|
||||
|
||||
@MockitoBean(name = "field")
|
||||
ExampleService field;
|
||||
@@ -92,7 +95,7 @@ public class MockitoBeanIntegrationTests {
|
||||
assertThat(ctx.getBean("nestedField"))
|
||||
.isInstanceOf(ExampleService.class)
|
||||
.satisfies(o -> assertThat(Mockito.mockingDetails(o).isMock()).as("isMock").isTrue())
|
||||
.isSameAs(MockitoBeanIntegrationTests.this.nestedField);
|
||||
.isSameAs(nestedField);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -100,7 +103,7 @@ public class MockitoBeanIntegrationTests {
|
||||
assertThat(ctx.getBean("nestedField"))
|
||||
.isInstanceOf(ExampleService.class)
|
||||
.satisfies(o -> assertThat(Mockito.mockingDetails(o).isMock()).as("isMock").isTrue())
|
||||
.isSameAs(MockitoBeanIntegrationTests.this.renamed2);
|
||||
.isSameAs(renamed2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -108,7 +111,7 @@ public class MockitoBeanIntegrationTests {
|
||||
assertThat(ctx.getBean("nestedNonExistingBean"))
|
||||
.isInstanceOf(ExampleService.class)
|
||||
.satisfies(o -> assertThat(Mockito.mockingDetails(o).isMock()).as("isMock").isTrue())
|
||||
.isSameAs(MockitoBeanIntegrationTests.this.nonExisting2);
|
||||
.isSameAs(nonExisting2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
/**
|
||||
* {@link MockitoBean @MockitoBean} "by type" integration tests for success scenarios.
|
||||
* Integration tests for {@link MockitoBean} that use by-type lookup.
|
||||
*
|
||||
* @author Simon Baslé
|
||||
* @author Sam Brannen
|
||||
@@ -47,7 +47,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
* @see FailingMockitoBeanByTypeIntegrationTests
|
||||
*/
|
||||
@SpringJUnitConfig
|
||||
public class MockitoBeanByTypeIntegrationTests {
|
||||
public class MockitoBeanForByTypeLookupIntegrationTests {
|
||||
|
||||
@MockitoBean
|
||||
AnotherService serviceIsNotABean;
|
||||
@@ -29,40 +29,40 @@ import org.springframework.test.context.bean.override.example.ExampleService;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
|
||||
/**
|
||||
* Tests for {@link MockitoBeanOverrideProcessorTests}
|
||||
*/
|
||||
public class MockitoBeanOverrideProcessorTests {
|
||||
|
||||
private final MockitoBeanOverrideProcessor processor = new MockitoBeanOverrideProcessor();
|
||||
|
||||
@Test
|
||||
void mockAnnotationCreatesMockMetadata() throws NoSuchFieldException {
|
||||
MockitoBeanOverrideProcessor processor = new MockitoBeanOverrideProcessor();
|
||||
MockitoBean annotation = AnnotationUtils.synthesizeAnnotation(MockitoBean.class);
|
||||
Class<?> clazz = MockitoConf.class;
|
||||
Field field = clazz.getField("a");
|
||||
|
||||
OverrideMetadata object = processor.createMetadata(annotation, clazz, field);
|
||||
OverrideMetadata object = this.processor.createMetadata(annotation, clazz, field);
|
||||
|
||||
assertThat(object).isExactlyInstanceOf(MockitoBeanOverrideMetadata.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void spyAnnotationCreatesSpyMetadata() throws NoSuchFieldException {
|
||||
MockitoBeanOverrideProcessor processor = new MockitoBeanOverrideProcessor();
|
||||
MockitoSpyBean annotation = AnnotationUtils.synthesizeAnnotation(MockitoSpyBean.class);
|
||||
Class<?> clazz = MockitoConf.class;
|
||||
Field field = clazz.getField("a");
|
||||
|
||||
OverrideMetadata object = processor.createMetadata(annotation, clazz, field);
|
||||
OverrideMetadata object = this.processor.createMetadata(annotation, clazz, field);
|
||||
|
||||
assertThat(object).isExactlyInstanceOf(MockitoSpyBeanOverrideMetadata.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void otherAnnotationThrows() throws NoSuchFieldException {
|
||||
MockitoBeanOverrideProcessor processor = new MockitoBeanOverrideProcessor();
|
||||
Class<?> clazz = MockitoConf.class;
|
||||
Field field = clazz.getField("a");
|
||||
Annotation annotation = field.getAnnotation(Nullable.class);
|
||||
|
||||
assertThatIllegalStateException().isThrownBy(() -> processor.createMetadata(annotation, clazz, field))
|
||||
assertThatIllegalStateException().isThrownBy(() -> this.processor.createMetadata(annotation, clazz, field))
|
||||
.withMessage("Invalid annotation passed to MockitoBeanOverrideProcessor: expected " +
|
||||
"@MockitoBean/@MockitoSpyBean on field %s.%s", field.getDeclaringClass().getName(),
|
||||
field.getName());
|
||||
|
||||
@@ -22,20 +22,23 @@ import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.bean.override.example.ExampleService;
|
||||
import org.springframework.test.context.bean.override.example.RealExampleService;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoSpyBeanForByNameLookupIntegrationTests.Config;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* {@link MockitoSpyBean @MockitoSpyBean} integration tests for success scenarios.
|
||||
* Integration tests for {@link MockitoSpyBean} that use by-name lookup.
|
||||
*
|
||||
* @author Simon Baslé
|
||||
* @since 6.2
|
||||
* @see FailingMockitoSpyBeanIntegrationTests
|
||||
*/
|
||||
@SpringJUnitConfig(MockitoBeanIntegrationTests.Config.class)
|
||||
public class MockitoSpyBeanIntegrationTests {
|
||||
@SpringJUnitConfig(Config.class)
|
||||
public class MockitoSpyBeanForByNameLookupIntegrationTests {
|
||||
|
||||
@MockitoSpyBean(name = "field")
|
||||
ExampleService field;
|
||||
@@ -57,7 +60,7 @@ public class MockitoSpyBeanIntegrationTests {
|
||||
.satisfies(o -> assertThat(Mockito.mockingDetails(o).isSpy()).as("isSpy").isTrue())
|
||||
.isSameAs(this.field);
|
||||
|
||||
assertThat(this.field.greeting()).as("spied greeting").isEqualTo("Hello Field");
|
||||
assertThat(this.field.greeting()).isEqualTo("Hello Field");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -67,7 +70,7 @@ public class MockitoSpyBeanIntegrationTests {
|
||||
.satisfies(o -> assertThat(Mockito.mockingDetails(o).isSpy()).as("isSpy").isTrue())
|
||||
.isSameAs(this.renamed1);
|
||||
|
||||
assertThat(this.renamed1.greeting()).as("spied greeting").isEqualTo("Hello Field");
|
||||
assertThat(this.renamed1.greeting()).isEqualTo("Hello Field");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@@ -79,11 +82,9 @@ public class MockitoSpyBeanIntegrationTests {
|
||||
assertThat(ctx.getBean("nestedField"))
|
||||
.isInstanceOf(ExampleService.class)
|
||||
.satisfies(o -> assertThat(Mockito.mockingDetails(o).isSpy()).as("isSpy").isTrue())
|
||||
.isSameAs(MockitoSpyBeanIntegrationTests.this.nestedField);
|
||||
.isSameAs(nestedField);
|
||||
|
||||
assertThat(MockitoSpyBeanIntegrationTests.this.nestedField.greeting())
|
||||
.as("spied greeting")
|
||||
.isEqualTo("Hello Nested Field");
|
||||
assertThat(nestedField.greeting()).isEqualTo("Hello Nested Field");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -91,11 +92,23 @@ public class MockitoSpyBeanIntegrationTests {
|
||||
assertThat(ctx.getBean("nestedField"))
|
||||
.isInstanceOf(ExampleService.class)
|
||||
.satisfies(o -> assertThat(Mockito.mockingDetails(o).isSpy()).as("isSpy").isTrue())
|
||||
.isSameAs(MockitoSpyBeanIntegrationTests.this.renamed2);
|
||||
.isSameAs(renamed2);
|
||||
|
||||
assertThat(MockitoSpyBeanIntegrationTests.this.renamed2.greeting())
|
||||
.as("spied greeting")
|
||||
.isEqualTo("Hello Nested Field");
|
||||
assertThat(renamed2.greeting()).isEqualTo("Hello Nested Field");
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class Config {
|
||||
|
||||
@Bean("field")
|
||||
ExampleService bean1() {
|
||||
return new RealExampleService("Hello Field");
|
||||
}
|
||||
|
||||
@Bean("nestedField")
|
||||
ExampleService bean2() {
|
||||
return new RealExampleService("Hello Nested Field");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
/**
|
||||
* {@link MockitoSpyBean @MockitoSpyBean} "by type" integration tests for success scenarios.
|
||||
* Integration tests for {@link MockitoSpyBean} that use by-type lookup.
|
||||
*
|
||||
* @author Simon Baslé
|
||||
* @author Sam Brannen
|
||||
@@ -44,7 +44,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
* @see FailingMockitoSpyBeanByTypeIntegrationTests
|
||||
*/
|
||||
@SpringJUnitConfig
|
||||
public class MockitoSpyBeanByTypeIntegrationTests {
|
||||
public class MockitoSpyBeanForByTypeLookupIntegrationTests {
|
||||
|
||||
@MockitoSpyBean
|
||||
ExampleService anyNameForService;
|
||||
Reference in New Issue
Block a user