Skip to content

Commit b105fdc

Browse files
committed
Polishing
1 parent b64edb2 commit b105fdc

17 files changed

+79
-71
lines changed

spring-jms/src/test/java/org/springframework/jms/core/JmsTemplateObservationTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
import jakarta.jms.Session;
2828
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
2929
import org.apache.activemq.artemis.junit.EmbeddedActiveMQExtension;
30-
import org.assertj.core.api.Assertions;
3130
import org.junit.jupiter.api.AfterEach;
3231
import org.junit.jupiter.api.BeforeEach;
3332
import org.junit.jupiter.api.Test;
3433
import org.junit.jupiter.api.extension.RegisterExtension;
3534

3635
import static io.micrometer.observation.tck.TestObservationRegistryAssert.assertThat;
36+
import static org.assertj.core.api.Assertions.assertThat;
3737

3838
/**
3939
* Tests for Observability related {@link JmsTemplate}.
@@ -127,7 +127,7 @@ public Message createMessage(Session session) throws JMSException {
127127
});
128128

129129
String responseBody = response.getBody(String.class);
130-
Assertions.assertThat(responseBody).isEqualTo("response content");
130+
assertThat(responseBody).isEqualTo("response content");
131131

132132
assertThat(registry).hasNumberOfObservationsWithNameEqualTo("jms.message.publish", 2);
133133
assertThat(registry).hasObservationWithNameEqualTo("jms.message.process").that()

spring-jms/src/test/java/org/springframework/jms/listener/MessageListenerContainerObservationTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import jakarta.jms.MessageListener;
2727
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
2828
import org.apache.activemq.artemis.junit.EmbeddedActiveMQExtension;
29-
import org.assertj.core.api.Assertions;
3029
import org.junit.jupiter.api.AfterEach;
3130
import org.junit.jupiter.api.BeforeEach;
3231
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -37,6 +36,7 @@
3736
import org.springframework.jms.core.JmsTemplate;
3837

3938
import static io.micrometer.observation.tck.TestObservationRegistryAssert.assertThat;
39+
import static org.assertj.core.api.Assertions.assertThat;
4040
import static org.junit.jupiter.api.Named.named;
4141
import static org.junit.jupiter.params.provider.Arguments.arguments;
4242

@@ -101,7 +101,7 @@ void shouldHaveObservationScopeInErrorHandler(AbstractMessageListenerContainer l
101101
JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
102102
jmsTemplate.convertAndSend("spring.test.observation", "message content");
103103
latch.await(2, TimeUnit.SECONDS);
104-
Assertions.assertThat(observationInErrorHandler.get()).isNotNull();
104+
assertThat(observationInErrorHandler.get()).isNotNull();
105105
assertThat(registry).hasObservationWithNameEqualTo("jms.message.process")
106106
.that()
107107
.hasHighCardinalityKeyValue("messaging.destination.name", "spring.test.observation")

spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideProcessor.java

+1
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,5 @@ public interface BeanOverrideProcessor {
4848
* given field
4949
*/
5050
OverrideMetadata createMetadata(Annotation overrideAnnotation, Class<?> testClass, Field field);
51+
5152
}

spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideContextCustomizerTestUtils.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
*/
3434
public abstract class BeanOverrideContextCustomizerTestUtils {
3535

36-
3736
private static final BeanOverrideContextCustomizerFactory factory = new BeanOverrideContextCustomizerFactory();
3837

3938
/**
@@ -49,12 +48,12 @@ public static ContextCustomizer createContextCustomizer(Class<?> testClass) {
4948
}
5049

5150
/**
52-
* Configure the given {@linkplain ConfigurableApplicationContext application
51+
* Customize the given {@linkplain ConfigurableApplicationContext application
5352
* context} for the given {@code testClass}.
5453
* @param testClass the test to process
55-
* @param context the context to configure
54+
* @param context the context to customize
5655
*/
57-
public static void configureApplicationContext(Class<?> testClass, ConfigurableApplicationContext context) {
56+
public static void customizeApplicationContext(Class<?> testClass, ConfigurableApplicationContext context) {
5857
ContextCustomizer contextCustomizer = createContextCustomizer(testClass);
5958
if (contextCustomizer != null) {
6059
contextCustomizer.customizeContext(context, mock(MergedContextConfiguration.class));

spring-test/src/test/java/org/springframework/test/context/bean/override/convention/TestBeanForInheritanceIntegrationTests.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ Pojo pojo2() {
128128
@DisplayName("Nested, concrete inherited tests with correct @TestBean setup")
129129
class NestedConcreteTestBeanIntegrationTests extends AbstractTestBeanIntegrationTestCase {
130130

131-
132131
@Autowired
133132
ApplicationContext ctx;
134133

@@ -141,6 +140,7 @@ class NestedConcreteTestBeanIntegrationTests extends AbstractTestBeanIntegration
141140
static Pojo someBean() {
142141
return new FakePojo("someBeanOverride");
143142
}
143+
144144
// Hides otherBean() defined in AbstractTestBeanIntegrationTestCase.
145145
static Pojo otherBean() {
146146
return new FakePojo("otherBean in subclass");
@@ -169,4 +169,5 @@ void fieldInNestedClassWithFactoryMethodInEnclosingClass() {
169169
assertThat(this.pojo2.getValue()).as("injection point").isEqualTo("in enclosing test class");
170170
}
171171
}
172+
172173
}

spring-test/src/test/java/org/springframework/test/context/bean/override/convention/TestBeanForInterfaceIntegrationTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
import static org.assertj.core.api.Assertions.assertThat;
2727

2828
/**
29-
* Integration tests for {@link TestBean} that use a bean factory methods
30-
* defined in implemented interfaces.
29+
* Integration tests for {@link TestBean} that use bean factory methods defined
30+
* in implemented interfaces.
3131
*
3232
* @author Sam Brannen
3333
* @since 6.2

spring-test/src/test/java/org/springframework/test/context/bean/override/convention/TestBeanOverrideProcessorTests.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ void createMetaDataForConventionBasedFactoryMethod() throws Exception {
124124
TestBean overrideAnnotation = field.getAnnotation(TestBean.class);
125125
assertThat(overrideAnnotation).isNotNull();
126126

127-
assertThatIllegalStateException().isThrownBy(() -> this.processor.createMetadata(
128-
overrideAnnotation, clazz, field))
127+
assertThatIllegalStateException()
128+
.isThrownBy(() -> this.processor.createMetadata(overrideAnnotation, clazz, field))
129129
.withMessage("No static method found named field() or someField() in %s with return type %s",
130130
clazz.getName(), returnType.getName());
131131
}
@@ -136,7 +136,8 @@ void failToCreateMetadataForOtherAnnotation() throws NoSuchFieldException {
136136
Field field = clazz.getField("field");
137137
NonNull badAnnotation = AnnotationUtils.synthesizeAnnotation(NonNull.class);
138138

139-
assertThatIllegalStateException().isThrownBy(() -> this.processor.createMetadata(badAnnotation, clazz, field))
139+
assertThatIllegalStateException()
140+
.isThrownBy(() -> this.processor.createMetadata(badAnnotation, clazz, field))
140141
.withMessage("Invalid annotation passed to TestBeanOverrideProcessor: expected @TestBean" +
141142
" on field %s.%s", field.getDeclaringClass().getName(), field.getName());
142143
}

spring-test/src/test/java/org/springframework/test/context/bean/override/convention/TestBeanTests.java

+22-17
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818

1919
import java.util.List;
2020

21-
import org.assertj.core.api.Assertions;
2221
import org.junit.jupiter.api.Test;
2322

2423
import org.springframework.context.support.GenericApplicationContext;
2524
import org.springframework.test.context.bean.override.BeanOverrideContextCustomizerTestUtils;
2625

26+
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
27+
2728
/**
2829
* Tests for {@link TestBean}.
2930
*
@@ -35,8 +36,9 @@ public class TestBeanTests {
3536
void contextCustomizerCannotBeCreatedWithNoSuchBeanName() {
3637
GenericApplicationContext context = new GenericApplicationContext();
3738
context.registerBean("anotherBean", String.class, () -> "example");
38-
BeanOverrideContextCustomizerTestUtils.configureApplicationContext(FailureByNameLookup.class, context);
39-
Assertions.assertThatIllegalStateException().isThrownBy(context::refresh)
39+
BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(FailureByNameLookup.class, context);
40+
assertThatIllegalStateException()
41+
.isThrownBy(context::refresh)
4042
.withMessage("""
4143
Unable to override bean 'beanToOverride': there is no bean definition \
4244
to replace with that name of type java.lang.String""");
@@ -45,8 +47,9 @@ void contextCustomizerCannotBeCreatedWithNoSuchBeanName() {
4547
@Test
4648
void contextCustomizerCannotBeCreatedWithNoSuchBeanType() {
4749
GenericApplicationContext context = new GenericApplicationContext();
48-
BeanOverrideContextCustomizerTestUtils.configureApplicationContext(FailureByTypeLookup.class, context);
49-
Assertions.assertThatIllegalStateException().isThrownBy(context::refresh)
50+
BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(FailureByTypeLookup.class, context);
51+
assertThatIllegalStateException()
52+
.isThrownBy(context::refresh)
5053
.withMessage("""
5154
Unable to override bean: no bean definitions of \
5255
type %s (as required by annotated field '%s.example')""".formatted(
@@ -58,8 +61,9 @@ void contextCustomizerCannotBeCreatedWithTooManyBeansOfThatType() {
5861
GenericApplicationContext context = new GenericApplicationContext();
5962
context.registerBean("bean1", String.class, () -> "example1");
6063
context.registerBean("bean2", String.class, () -> "example2");
61-
BeanOverrideContextCustomizerTestUtils.configureApplicationContext(FailureByTypeLookup.class, context);
62-
Assertions.assertThatIllegalStateException().isThrownBy(context::refresh)
64+
BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(FailureByTypeLookup.class, context);
65+
assertThatIllegalStateException()
66+
.isThrownBy(context::refresh)
6367
.withMessage("""
6468
Unable to select a bean definition to override: found 2 bean definitions \
6569
of type %s (as required by annotated field '%s.example'): %s""".formatted(
@@ -70,8 +74,9 @@ void contextCustomizerCannotBeCreatedWithTooManyBeansOfThatType() {
7074
void contextCustomizerCannotBeCreatedWithBeanOfWrongType() {
7175
GenericApplicationContext context = new GenericApplicationContext();
7276
context.registerBean("beanToOverride", Integer.class, () -> 42);
73-
BeanOverrideContextCustomizerTestUtils.configureApplicationContext(FailureByNameLookup.class, context);
74-
Assertions.assertThatIllegalStateException().isThrownBy(context::refresh)
77+
BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(FailureByNameLookup.class, context);
78+
assertThatIllegalStateException()
79+
.isThrownBy(context::refresh)
7580
.withMessage("""
7681
Unable to override bean 'beanToOverride': there is no bean definition \
7782
to replace with that name of type %s""".formatted(
@@ -81,8 +86,8 @@ void contextCustomizerCannotBeCreatedWithBeanOfWrongType() {
8186
@Test
8287
void contextCustomizerCannotBeCreatedWithMissingOverrideMethod() {
8388
GenericApplicationContext context = new GenericApplicationContext();
84-
Assertions.assertThatIllegalStateException()
85-
.isThrownBy(() -> BeanOverrideContextCustomizerTestUtils.configureApplicationContext(
89+
assertThatIllegalStateException()
90+
.isThrownBy(() -> BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(
8691
FailureMissingDefaultOverrideMethod.class, context))
8792
.withMessage("No static method found named example() or beanToOverride() in %s with return type %s"
8893
.formatted(FailureMissingDefaultOverrideMethod.class.getName(), String.class.getName()));
@@ -91,8 +96,8 @@ void contextCustomizerCannotBeCreatedWithMissingOverrideMethod() {
9196
@Test
9297
void contextCustomizerCannotBeCreatedWithMissingExplicitOverrideMethod() {
9398
GenericApplicationContext context = new GenericApplicationContext();
94-
Assertions.assertThatIllegalStateException()
95-
.isThrownBy(() -> BeanOverrideContextCustomizerTestUtils.configureApplicationContext(
99+
assertThatIllegalStateException()
100+
.isThrownBy(() -> BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(
96101
FailureMissingExplicitOverrideMethod.class, context))
97102
.withMessage("No static method found named createExample() in %s with return type %s"
98103
.formatted(FailureMissingExplicitOverrideMethod.class.getName(), String.class.getName()));
@@ -102,8 +107,8 @@ void contextCustomizerCannotBeCreatedWithMissingExplicitOverrideMethod() {
102107
void contextCustomizerCannotBeCreatedWithFieldInParentAndMissingOverrideMethod() {
103108
GenericApplicationContext context = new GenericApplicationContext();
104109
context.registerBean("beanToOverride", String.class, () -> "example");
105-
Assertions.assertThatIllegalStateException()
106-
.isThrownBy(() -> BeanOverrideContextCustomizerTestUtils.configureApplicationContext(
110+
assertThatIllegalStateException()
111+
.isThrownBy(() -> BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(
107112
FailureOverrideInParentWithoutFactoryMethod.class, context))
108113
.withMessage("No static method found named beanToOverride() in %s with return type %s"
109114
.formatted(FailureOverrideInParentWithoutFactoryMethod.class.getName(), String.class.getName()));
@@ -113,8 +118,8 @@ void contextCustomizerCannotBeCreatedWithFieldInParentAndMissingOverrideMethod()
113118
void contextCustomizerCannotBeCreatedWitCompetingOverrideMethods() {
114119
GenericApplicationContext context = new GenericApplicationContext();
115120
context.registerBean("bean", String.class, () -> "example");
116-
Assertions.assertThatIllegalStateException()
117-
.isThrownBy(() -> BeanOverrideContextCustomizerTestUtils.configureApplicationContext(
121+
assertThatIllegalStateException()
122+
.isThrownBy(() -> BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(
118123
FailureCompetingOverrideMethods.class, context))
119124
.withMessage("Found 2 competing static methods named example() or beanToOverride() in %s with return type %s"
120125
.formatted(FailureCompetingOverrideMethods.class.getName(), String.class.getName()));

spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoBeanContextCustomizerEqualityTests.java

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
*/
3333
class MockitoBeanContextCustomizerEqualityTests {
3434

35-
3635
@Test
3736
void contextCustomizerWithSameMockByNameInDifferentClassIsEqual() {
3837
assertThat(createContextCustomizer(Case1ByName.class)).isEqualTo(createContextCustomizer(Case2ByName.class));

spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoBeanForBeanFactoryIntegrationTests.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@
1717
package org.springframework.test.context.bean.override.mockito;
1818

1919
import org.junit.jupiter.api.Test;
20-
import org.junit.jupiter.api.extension.ExtendWith;
2120

2221
import org.springframework.beans.factory.FactoryBean;
2322
import org.springframework.beans.factory.annotation.Autowired;
2423
import org.springframework.context.ApplicationContext;
2524
import org.springframework.context.annotation.Bean;
2625
import org.springframework.context.annotation.Configuration;
27-
import org.springframework.test.context.junit.jupiter.SpringExtension;
26+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
2827

2928
import static org.assertj.core.api.Assertions.assertThat;
3029
import static org.mockito.BDDMockito.given;
@@ -35,11 +34,9 @@
3534
*
3635
* @author Phillip Webb
3736
*/
38-
@ExtendWith(SpringExtension.class)
37+
@SpringJUnitConfig
3938
class MockitoBeanForBeanFactoryIntegrationTests {
4039

41-
// spring-boot/gh-7439
42-
4340
@MockitoBean
4441
private TestFactoryBean testFactoryBean;
4542

spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoBeanForByTypeLookupIntegrationTests.java

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ void overrideIsFoundByTypeAndDisambiguatedByMetaQualifier(ApplicationContext ctx
122122
verifyNoMoreInteractions(this.ambiguousMeta);
123123
}
124124

125+
125126
interface AnotherService {
126127

127128
String hello();

spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoBeanOverrideProcessorTests.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ void otherAnnotationThrows() throws NoSuchFieldException {
6262
Field field = clazz.getField("a");
6363
Annotation annotation = field.getAnnotation(Nullable.class);
6464

65-
assertThatIllegalStateException().isThrownBy(() -> this.processor.createMetadata(annotation, clazz, field))
65+
assertThatIllegalStateException()
66+
.isThrownBy(() -> this.processor.createMetadata(annotation, clazz, field))
6667
.withMessage("Invalid annotation passed to MockitoBeanOverrideProcessor: expected " +
6768
"@MockitoBean/@MockitoSpyBean on field %s.%s", field.getDeclaringClass().getName(),
6869
field.getName());

spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoMockBeanTests.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818

1919
import java.util.List;
2020

21-
import org.assertj.core.api.Assertions;
2221
import org.junit.jupiter.api.Test;
2322

2423
import org.springframework.context.support.GenericApplicationContext;
2524
import org.springframework.test.context.bean.override.BeanOverrideContextCustomizerTestUtils;
2625

26+
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
27+
2728
/**
2829
* Tests for {@link MockitoBean}.
2930
*
@@ -36,8 +37,9 @@ void contextCustomizerCannotBeCreatedWithTooManyCandidates() {
3637
GenericApplicationContext context = new GenericApplicationContext();
3738
context.registerBean("bean1", String.class, () -> "example1");
3839
context.registerBean("bean2", String.class, () -> "example2");
39-
BeanOverrideContextCustomizerTestUtils.configureApplicationContext(ByTypeSingleLookup.class, context);
40-
Assertions.assertThatIllegalStateException().isThrownBy(context::refresh)
40+
BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(ByTypeSingleLookup.class, context);
41+
assertThatIllegalStateException()
42+
.isThrownBy(context::refresh)
4143
.withMessage("""
4244
Unable to select a bean definition to override: found 2 bean definitions \
4345
of type %s (as required by annotated field '%s.example'): %s""".formatted(
@@ -51,4 +53,5 @@ static class ByTypeSingleLookup {
5153
String example;
5254

5355
}
56+
5457
}

spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoSpyBeanTests.java

+11-7
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818

1919
import java.util.List;
2020

21-
import org.assertj.core.api.Assertions;
2221
import org.junit.jupiter.api.Test;
2322

2423
import org.springframework.context.support.GenericApplicationContext;
2524
import org.springframework.test.context.bean.override.BeanOverrideContextCustomizerTestUtils;
2625

26+
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
27+
2728
/**
2829
* Tests for {@link MockitoSpyBean}.
2930
*
@@ -35,8 +36,9 @@ class MockitoSpyBeanTests {
3536
void contextCustomizerCannotBeCreatedWithNoSuchBeanName() {
3637
GenericApplicationContext context = new GenericApplicationContext();
3738
context.registerBean("present", String.class, () -> "example");
38-
BeanOverrideContextCustomizerTestUtils.configureApplicationContext(ByNameSingleLookup.class, context);
39-
Assertions.assertThatIllegalStateException().isThrownBy(context::refresh)
39+
BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(ByNameSingleLookup.class, context);
40+
assertThatIllegalStateException()
41+
.isThrownBy(context::refresh)
4042
.withMessage("""
4143
Unable to override bean 'beanToSpy' by wrapping: \
4244
there is no existing bean instance with that name of type %s""".formatted(
@@ -46,8 +48,9 @@ void contextCustomizerCannotBeCreatedWithNoSuchBeanName() {
4648
@Test
4749
void contextCustomizerCannotBeCreatedWithNoSuchBeanType() {
4850
GenericApplicationContext context = new GenericApplicationContext();
49-
BeanOverrideContextCustomizerTestUtils.configureApplicationContext(ByTypeSingleLookup.class, context);
50-
Assertions.assertThatIllegalStateException().isThrownBy(context::refresh)
51+
BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(ByTypeSingleLookup.class, context);
52+
assertThatIllegalStateException()
53+
.isThrownBy(context::refresh)
5154
.withMessage("""
5255
Unable to select a bean to override by wrapping: found 0 bean instances of \
5356
type %s (as required by annotated field '%s.example')""".formatted(
@@ -59,8 +62,9 @@ void contextCustomizerCannotBeCreatedWithTooManyBeansOfThatType() {
5962
GenericApplicationContext context = new GenericApplicationContext();
6063
context.registerBean("bean1", String.class, () -> "example1");
6164
context.registerBean("bean2", String.class, () -> "example2");
62-
BeanOverrideContextCustomizerTestUtils.configureApplicationContext(ByTypeSingleLookup.class, context);
63-
Assertions.assertThatIllegalStateException().isThrownBy(context::refresh)
65+
BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(ByTypeSingleLookup.class, context);
66+
assertThatIllegalStateException()
67+
.isThrownBy(context::refresh)
6468
.withMessage("""
6569
Unable to select a bean to override by wrapping: found 2 bean instances \
6670
of type %s (as required by annotated field '%s.example'): %s""".formatted(

0 commit comments

Comments
 (0)