31
31
32
32
import static org .assertj .core .api .Assertions .assertThat ;
33
33
import static org .assertj .core .api .Assertions .assertThatException ;
34
- import static org .mockito .Mockito .times ;
35
34
import static org .mockito .Mockito .verify ;
36
35
import static org .mockito .Mockito .verifyNoMoreInteractions ;
37
36
@@ -50,11 +49,11 @@ public class MockitoSpyBeanForByTypeLookupIntegrationTests {
50
49
51
50
@ MockitoSpyBean
52
51
@ Qualifier ("prefer" )
53
- StringBuilder ambiguous ;
52
+ StringHolder ambiguous ;
54
53
55
54
@ MockitoSpyBean
56
55
@ CustomQualifier
57
- StringBuilder ambiguousMeta ;
56
+ StringHolder ambiguousMeta ;
58
57
59
58
60
59
@ Test
@@ -65,7 +64,7 @@ void overrideIsFoundByType(ApplicationContext ctx) {
65
64
.isSameAs (ctx .getBean (ExampleService .class ));
66
65
67
66
assertThat (this .anyNameForService .greeting ()).isEqualTo ("Production hello" );
68
- verify (this .anyNameForService , times ( 1 ) ).greeting ();
67
+ verify (this .anyNameForService ).greeting ();
69
68
verifyNoMoreInteractions (this .anyNameForService );
70
69
}
71
70
@@ -76,13 +75,14 @@ void overrideIsFoundByTypeAndDisambiguatedByQualifier(ApplicationContext ctx) {
76
75
.isSameAs (ctx .getBean ("ambiguous2" ));
77
76
78
77
assertThatException ()
79
- .isThrownBy (() -> ctx .getBean (StringBuilder .class ))
78
+ .isThrownBy (() -> ctx .getBean (StringHolder .class ))
80
79
.withMessageEndingWith ("but found 2: ambiguous1,ambiguous2" );
81
80
82
- assertThat (this .ambiguous .toString ()).isEqualTo ("bean3" );
83
- assertThat (this .ambiguous .length ()).isEqualTo (5 );
84
- verify (this .ambiguous , times (1 )).length ();
85
- verifyNoMoreInteractions (this .ambiguous ); //mockito doesn't verify toString
81
+ assertThat (this .ambiguous .getValue ()).isEqualTo ("bean3" );
82
+ assertThat (this .ambiguous .size ()).isEqualTo (5 );
83
+ verify (this .ambiguous ).getValue ();
84
+ verify (this .ambiguous ).size ();
85
+ verifyNoMoreInteractions (this .ambiguous );
86
86
}
87
87
88
88
@ Test
@@ -92,12 +92,13 @@ void overrideIsFoundByTypeAndDisambiguatedByMetaQualifier(ApplicationContext ctx
92
92
.isSameAs (ctx .getBean ("ambiguous1" ));
93
93
94
94
assertThatException ()
95
- .isThrownBy (() -> ctx .getBean (StringBuilder .class ))
95
+ .isThrownBy (() -> ctx .getBean (StringHolder .class ))
96
96
.withMessageEndingWith ("but found 2: ambiguous1,ambiguous2" );
97
97
98
- assertThat (this .ambiguousMeta .toString ()).isEqualTo ("bean2" );
99
- assertThat (this .ambiguousMeta .length ()).isEqualTo (5 );
100
- verify (this .ambiguousMeta , times (1 )).length ();
98
+ assertThat (this .ambiguousMeta .getValue ()).isEqualTo ("bean2" );
99
+ assertThat (this .ambiguousMeta .size ()).isEqualTo (5 );
100
+ verify (this .ambiguousMeta ).getValue ();
101
+ verify (this .ambiguousMeta ).size ();
101
102
verifyNoMoreInteractions (this .ambiguousMeta ); //mockito doesn't verify toString
102
103
}
103
104
@@ -113,15 +114,32 @@ ExampleService bean1() {
113
114
@ Bean ("ambiguous1" )
114
115
@ Order (1 )
115
116
@ CustomQualifier
116
- StringBuilder bean2 () {
117
- return new StringBuilder ("bean2" );
117
+ StringHolder bean2 () {
118
+ return new StringHolder ("bean2" );
118
119
}
119
120
120
121
@ Bean ("ambiguous2" )
121
122
@ Order (2 )
122
123
@ Qualifier ("prefer" )
123
- StringBuilder bean3 () {
124
- return new StringBuilder ("bean3" );
124
+ StringHolder bean3 () {
125
+ return new StringHolder ("bean3" );
126
+ }
127
+ }
128
+
129
+ static class StringHolder {
130
+
131
+ private final String value ;
132
+
133
+ StringHolder (String value ) {
134
+ this .value = value ;
135
+ }
136
+
137
+ public String getValue () {
138
+ return this .value ;
139
+ }
140
+
141
+ public int size () {
142
+ return this .value .length ();
125
143
}
126
144
}
127
145
0 commit comments