18
18
19
19
import java .util .List ;
20
20
21
- import org .assertj .core .api .Assertions ;
22
21
import org .junit .jupiter .api .Test ;
23
22
24
23
import org .springframework .context .support .GenericApplicationContext ;
25
24
import org .springframework .test .context .bean .override .BeanOverrideContextCustomizerTestUtils ;
26
25
26
+ import static org .assertj .core .api .Assertions .assertThatIllegalStateException ;
27
+
27
28
/**
28
29
* Tests for {@link TestBean}.
29
30
*
@@ -35,8 +36,9 @@ public class TestBeanTests {
35
36
void contextCustomizerCannotBeCreatedWithNoSuchBeanName () {
36
37
GenericApplicationContext context = new GenericApplicationContext ();
37
38
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 )
40
42
.withMessage ("""
41
43
Unable to override bean 'beanToOverride': there is no bean definition \
42
44
to replace with that name of type java.lang.String""" );
@@ -45,8 +47,9 @@ void contextCustomizerCannotBeCreatedWithNoSuchBeanName() {
45
47
@ Test
46
48
void contextCustomizerCannotBeCreatedWithNoSuchBeanType () {
47
49
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 )
50
53
.withMessage ("""
51
54
Unable to override bean: no bean definitions of \
52
55
type %s (as required by annotated field '%s.example')""" .formatted (
@@ -58,8 +61,9 @@ void contextCustomizerCannotBeCreatedWithTooManyBeansOfThatType() {
58
61
GenericApplicationContext context = new GenericApplicationContext ();
59
62
context .registerBean ("bean1" , String .class , () -> "example1" );
60
63
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 )
63
67
.withMessage ("""
64
68
Unable to select a bean definition to override: found 2 bean definitions \
65
69
of type %s (as required by annotated field '%s.example'): %s""" .formatted (
@@ -70,8 +74,9 @@ void contextCustomizerCannotBeCreatedWithTooManyBeansOfThatType() {
70
74
void contextCustomizerCannotBeCreatedWithBeanOfWrongType () {
71
75
GenericApplicationContext context = new GenericApplicationContext ();
72
76
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 )
75
80
.withMessage ("""
76
81
Unable to override bean 'beanToOverride': there is no bean definition \
77
82
to replace with that name of type %s""" .formatted (
@@ -81,8 +86,8 @@ void contextCustomizerCannotBeCreatedWithBeanOfWrongType() {
81
86
@ Test
82
87
void contextCustomizerCannotBeCreatedWithMissingOverrideMethod () {
83
88
GenericApplicationContext context = new GenericApplicationContext ();
84
- Assertions . assertThatIllegalStateException ()
85
- .isThrownBy (() -> BeanOverrideContextCustomizerTestUtils .configureApplicationContext (
89
+ assertThatIllegalStateException ()
90
+ .isThrownBy (() -> BeanOverrideContextCustomizerTestUtils .customizeApplicationContext (
86
91
FailureMissingDefaultOverrideMethod .class , context ))
87
92
.withMessage ("No static method found named example() or beanToOverride() in %s with return type %s"
88
93
.formatted (FailureMissingDefaultOverrideMethod .class .getName (), String .class .getName ()));
@@ -91,8 +96,8 @@ void contextCustomizerCannotBeCreatedWithMissingOverrideMethod() {
91
96
@ Test
92
97
void contextCustomizerCannotBeCreatedWithMissingExplicitOverrideMethod () {
93
98
GenericApplicationContext context = new GenericApplicationContext ();
94
- Assertions . assertThatIllegalStateException ()
95
- .isThrownBy (() -> BeanOverrideContextCustomizerTestUtils .configureApplicationContext (
99
+ assertThatIllegalStateException ()
100
+ .isThrownBy (() -> BeanOverrideContextCustomizerTestUtils .customizeApplicationContext (
96
101
FailureMissingExplicitOverrideMethod .class , context ))
97
102
.withMessage ("No static method found named createExample() in %s with return type %s"
98
103
.formatted (FailureMissingExplicitOverrideMethod .class .getName (), String .class .getName ()));
@@ -102,8 +107,8 @@ void contextCustomizerCannotBeCreatedWithMissingExplicitOverrideMethod() {
102
107
void contextCustomizerCannotBeCreatedWithFieldInParentAndMissingOverrideMethod () {
103
108
GenericApplicationContext context = new GenericApplicationContext ();
104
109
context .registerBean ("beanToOverride" , String .class , () -> "example" );
105
- Assertions . assertThatIllegalStateException ()
106
- .isThrownBy (() -> BeanOverrideContextCustomizerTestUtils .configureApplicationContext (
110
+ assertThatIllegalStateException ()
111
+ .isThrownBy (() -> BeanOverrideContextCustomizerTestUtils .customizeApplicationContext (
107
112
FailureOverrideInParentWithoutFactoryMethod .class , context ))
108
113
.withMessage ("No static method found named beanToOverride() in %s with return type %s"
109
114
.formatted (FailureOverrideInParentWithoutFactoryMethod .class .getName (), String .class .getName ()));
@@ -113,8 +118,8 @@ void contextCustomizerCannotBeCreatedWithFieldInParentAndMissingOverrideMethod()
113
118
void contextCustomizerCannotBeCreatedWitCompetingOverrideMethods () {
114
119
GenericApplicationContext context = new GenericApplicationContext ();
115
120
context .registerBean ("bean" , String .class , () -> "example" );
116
- Assertions . assertThatIllegalStateException ()
117
- .isThrownBy (() -> BeanOverrideContextCustomizerTestUtils .configureApplicationContext (
121
+ assertThatIllegalStateException ()
122
+ .isThrownBy (() -> BeanOverrideContextCustomizerTestUtils .customizeApplicationContext (
118
123
FailureCompetingOverrideMethods .class , context ))
119
124
.withMessage ("Found 2 competing static methods named example() or beanToOverride() in %s with return type %s"
120
125
.formatted (FailureCompetingOverrideMethods .class .getName (), String .class .getName ()));
0 commit comments