@@ -71,15 +71,39 @@ void createContextCustomizerWhenEnclosingClassHasServiceConnectionsReturnsCustom
7171 }
7272
7373 @ 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 () {
7599 assertThatIllegalStateException ()
76100 .isThrownBy (() -> this .factory .createContextCustomizer (NonStaticServiceConnection .class , null ))
77101 .withMessage ("@ServiceConnection field 'service' must be static" );
78102
79103 }
80104
81105 @ Test
82- void createContextCustomizerWhenClassHasAnnotationOnNonConnectionFieldFailsWithHepfulException () {
106+ void createContextCustomizerWhenClassHasAnnotationOnNonConnectionFieldFailsWithHelpfulException () {
83107 assertThatIllegalStateException ()
84108 .isThrownBy (() -> this .factory .createContextCustomizer (ServiceConnectionOnWrongFieldType .class , null ))
85109 .withMessage ("Field 'service2' in " + ServiceConnectionOnWrongFieldType .class .getName ()
@@ -141,6 +165,27 @@ class NestedClass {
141165
142166 }
143167
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+
144189 static class NonStaticServiceConnection {
145190
146191 @ ServiceConnection
0 commit comments