@@ -71,15 +71,39 @@ void createContextCustomizerWhenEnclosingClassHasServiceConnectionsReturnsCustom
71
71
}
72
72
73
73
@ Test
74
- void createContextCustomizerWhenClassHasNonStaticServiceConnectionFailsWithHepfulException () {
74
+ void createContextCustomizerWhenInterfaceHasServiceConnectionsReturnsCustomizer () {
75
+ ServiceConnectionContextCustomizer customizer = (ServiceConnectionContextCustomizer ) this .factory
76
+ .createContextCustomizer (ServiceConnectionsInterface .class , null );
77
+ assertThat (customizer ).isNotNull ();
78
+ assertThat (customizer .getSources ()).hasSize (2 );
79
+ }
80
+
81
+ @ Test
82
+ void createContextCustomizerWhenSuperclassHasServiceConnectionsReturnsCustomizer () {
83
+ ServiceConnectionContextCustomizer customizer = (ServiceConnectionContextCustomizer ) this .factory
84
+ .createContextCustomizer (ServiceConnectionsSubclass .class , null );
85
+ assertThat (customizer ).isNotNull ();
86
+ assertThat (customizer .getSources ()).hasSize (2 );
87
+ }
88
+
89
+ @ Test
90
+ void createContextCustomizerWhenImplementedInterfaceHasServiceConnectionsReturnsCustomizer () {
91
+ ServiceConnectionContextCustomizer customizer = (ServiceConnectionContextCustomizer ) this .factory
92
+ .createContextCustomizer (ServiceConnectionsImpl .class , null );
93
+ assertThat (customizer ).isNotNull ();
94
+ assertThat (customizer .getSources ()).hasSize (2 );
95
+ }
96
+
97
+ @ Test
98
+ void createContextCustomizerWhenClassHasNonStaticServiceConnectionFailsWithHelpfulException () {
75
99
assertThatIllegalStateException ()
76
100
.isThrownBy (() -> this .factory .createContextCustomizer (NonStaticServiceConnection .class , null ))
77
101
.withMessage ("@ServiceConnection field 'service' must be static" );
78
102
79
103
}
80
104
81
105
@ Test
82
- void createContextCustomizerWhenClassHasAnnotationOnNonConnectionFieldFailsWithHepfulException () {
106
+ void createContextCustomizerWhenClassHasAnnotationOnNonConnectionFieldFailsWithHelpfulException () {
83
107
assertThatIllegalStateException ()
84
108
.isThrownBy (() -> this .factory .createContextCustomizer (ServiceConnectionOnWrongFieldType .class , null ))
85
109
.withMessage ("Field 'service2' in " + ServiceConnectionOnWrongFieldType .class .getName ()
@@ -141,6 +165,27 @@ class NestedClass {
141
165
142
166
}
143
167
168
+ interface ServiceConnectionsInterface {
169
+
170
+ @ ServiceConnection
171
+ Container <?> service1 = new MockContainer ();
172
+
173
+ @ ServiceConnection
174
+ Container <?> service2 = new MockContainer ();
175
+
176
+ default void dummy () {
177
+ }
178
+
179
+ }
180
+
181
+ static class ServiceConnectionsSubclass extends ServiceConnections {
182
+
183
+ }
184
+
185
+ static class ServiceConnectionsImpl implements ServiceConnectionsInterface {
186
+
187
+ }
188
+
144
189
static class NonStaticServiceConnection {
145
190
146
191
@ ServiceConnection
0 commit comments