@@ -23,104 +23,104 @@ class ClassPathScannerTest {
2323 private ClassPathScanner sut = new ClassPathScanner ();
2424
2525 @ Nested
26- @ DisplayName ("trying to resolve a random implementation of an interface" )
27- class FindRandomClassForInterface {
26+ @ DisplayName ("trying to resolve all implementations of an interface class " )
27+ class FindAllClassesForInterface {
2828
2929 @ Test
30- @ DisplayName ("returns an empty Optional if none was found" )
31- void returnsAnEmptyOptionalIfNoneWasFound () {
32- var actual = sut .findRandomClassFor (SpecimenType .fromClass (InterfaceWithoutImplementation .class ));
30+ @ DisplayName ("returns an empty list if none was found" )
31+ void returnsAnEmptyListIfNoneWasFound () {
32+ var actual = sut .findAllClassesFor (SpecimenType .fromClass (InterfaceWithoutImplementation .class ));
3333
3434 assertThat (actual ).isEmpty ();
3535 }
3636
3737 @ Test
38- @ DisplayName ("returns an empty Optional if not an interface nor abstract" )
39- void returnsAnEmptyOptionalIfNotAnInterfaceNorAbstract () {
40- var actual = sut .findRandomClassFor (SpecimenType .fromClass (String .class ));
38+ @ DisplayName ("returns an empty list if not an interface nor abstract" )
39+ void returnsAnEmptyListIfNotAnInterfaceNorAbstract () {
40+ var actual = sut .findAllClassesFor (SpecimenType .fromClass (String .class ));
4141
4242 assertThat (actual ).isEmpty ();
4343 }
4444
4545 @ Test
46- @ DisplayName ("returns an empty Optional if exception was thrown" )
47- void returnsAnEmptyOptionalIfExceptionWasThrown () {
46+ @ DisplayName ("returns an empty list if exception was thrown" )
47+ void returnsAnEmptyListIfExceptionWasThrown () {
4848 var throwingType = Mockito .mock (SpecimenType .class );
4949 doThrow (new IllegalArgumentException ("expected for test" )).when (throwingType ).isInterface ();
5050
51- var actual = sut .findRandomClassFor (throwingType );
51+ var actual = sut .findAllClassesFor (throwingType );
5252
5353 assertThat (actual ).isEmpty ();
5454 }
5555
5656 @ Test
57- @ DisplayName ("returns a SpecimenType representing an implementing class" )
58- void returnsASpecimenTypeRepresentingAnImplementingClass () {
59- var actual = sut .findRandomClassFor (SpecimenType .fromClass (InterfaceWithImplementation .class ));
57+ @ DisplayName ("returns a list of SpecimenType all representing an implementing class" )
58+ void returnsSpecimenTypesRepresentingImplementingClasses () {
59+ var actual = sut .findAllClassesFor (SpecimenType .fromClass (InterfaceWithImplementation .class ));
6060
61- assertThat (actual ).isNotEmpty ( );
62- assertThat (actual .get ().asClass ()).isEqualTo (InterfaceWithImplementationImpl .class );
61+ assertThat (actual ).hasSize ( 1 );
62+ assertThat (actual .get (0 ).asClass ()).isEqualTo (InterfaceWithImplementationImpl .class );
6363 }
6464
6565 @ Test
66- @ DisplayName ("returns a SpecimenType representing an implementing generic class" )
67- void returnsASpecimenTypeRepresentingAnImplementingGenericClass () {
68- var actual = sut .findRandomClassFor (new SpecimenType <GenericInterfaceTUWithGenericImplementationU <String , Integer >>() {});
66+ @ DisplayName ("returns a list of SpecimenType all representing an implementing generic class" )
67+ void returnsSpecimenTypesRepresentingGenericImplementations () {
68+ var actual = sut .findAllClassesFor (new SpecimenType <GenericInterfaceTUWithGenericImplementationU <String , Integer >>() {});
6969
70- assertThat (actual ).isNotEmpty ( );
71- assertThat (actual .get ().asClass ()).isEqualTo (GenericInterfaceTUWithGenericImplementationUImpl .class );
72- assertThat (actual .get ().getGenericTypeArgument (0 ).asClass ()).isEqualTo (Integer .class );
70+ assertThat (actual ).hasSize ( 1 );
71+ assertThat (actual .get (0 ).asClass ()).isEqualTo (GenericInterfaceTUWithGenericImplementationUImpl .class );
72+ assertThat (actual .get (0 ).getGenericTypeArgument (0 ).asClass ()).isEqualTo (Integer .class );
7373 }
7474 }
7575
7676 @ Nested
77- @ DisplayName ("trying to resolve a random implementation of an abstract class" )
78- class FindRandomClassForAbstractClass {
77+ @ DisplayName ("trying to resolve all subclasses of an abstract class" )
78+ class FindAllClassesForAbstractClass {
7979
8080 @ Test
81- @ DisplayName ("returns an empty Optional if none was found" )
82- void returnsAnEmptyOptionalIfNoneWasFound () {
83- var actual = sut .findRandomClassFor (SpecimenType .fromClass (AbstractClassWithoutImplementation .class ));
81+ @ DisplayName ("returns an empty list if none was found" )
82+ void returnsAnEmptyListIfNoneWasFound () {
83+ var actual = sut .findAllClassesFor (SpecimenType .fromClass (AbstractClassWithoutImplementation .class ));
8484
8585 assertThat (actual ).isEmpty ();
8686 }
8787
8888 @ Test
89- @ DisplayName ("returns an empty Optional if not an interface nor abstract" )
90- void returnsAnEmptyOptionalIfNotAnInterfaceNorAbstract () {
91- var actual = sut .findRandomClassFor (SpecimenType .fromClass (String .class ));
89+ @ DisplayName ("returns an empty list if not an interface nor abstract" )
90+ void returnsAnEmptyListIfNotAnInterfaceNorAbstract () {
91+ var actual = sut .findAllClassesFor (SpecimenType .fromClass (String .class ));
9292
9393 assertThat (actual ).isEmpty ();
9494 }
9595
9696 @ Test
97- @ DisplayName ("returns an empty Optional if exception was thrown" )
98- void returnsAnEmptyOptionalIfExceptionWasThrown () {
97+ @ DisplayName ("returns an empty list if exception was thrown" )
98+ void returnsAnEmptyListIfExceptionWasThrown () {
9999 var throwingType = Mockito .mock (SpecimenType .class );
100100 doThrow (new IllegalArgumentException ("expected for test" )).when (throwingType ).isInterface ();
101101
102- var actual = sut .findRandomClassFor (throwingType );
102+ var actual = sut .findAllClassesFor (throwingType );
103103
104104 assertThat (actual ).isEmpty ();
105105 }
106106
107107 @ Test
108- @ DisplayName ("returns a SpecimenType representing an extending class " )
109- void returnsASpecimenTypeRepresentingAnImplementingClass () {
110- var actual = sut .findRandomClassFor (SpecimenType .fromClass (AbstractClassWithImplementation .class ));
108+ @ DisplayName ("returns SpecimenTypes all representing a subclass " )
109+ void returnsSpecimenTypesRepresentingSubclasses () {
110+ var actual = sut .findAllClassesFor (SpecimenType .fromClass (AbstractClassWithImplementation .class ));
111111
112- assertThat (actual ).isNotEmpty ( );
113- assertThat (actual .get ().asClass ()).isEqualTo (AbstractClassWithImplementationImpl .class );
112+ assertThat (actual ).hasSize ( 1 );
113+ assertThat (actual .get (0 ).asClass ()).isEqualTo (AbstractClassWithImplementationImpl .class );
114114 }
115115
116116 @ Test
117- @ DisplayName ("returns a SpecimenType representing an implementing generic class" )
118- void returnsASpecimenTypeRepresentingAnImplementingGenericClass () {
119- var actual = sut .findRandomClassFor (new SpecimenType <GenericAbstractClassTUWithGenericImplementationU <String , Integer >>() {});
117+ @ DisplayName ("returns SpecimenTypes all representing an implementing generic class" )
118+ void returnsSpecimenTypesRepresentingGenericSubclasses () {
119+ var actual = sut .findAllClassesFor (new SpecimenType <GenericAbstractClassTUWithGenericImplementationU <String , Integer >>() {});
120120
121- assertThat (actual ).isNotEmpty ( );
122- assertThat (actual .get ().asClass ()).isEqualTo (GenericAbstractClassTUWithGenericImplementationUImpl .class );
123- assertThat (actual .get ().getGenericTypeArgument (0 ).asClass ()).isEqualTo (Integer .class );
121+ assertThat (actual ).hasSize ( 1 );
122+ assertThat (actual .get (0 ).asClass ()).isEqualTo (GenericAbstractClassTUWithGenericImplementationUImpl .class );
123+ assertThat (actual .get (0 ).getGenericTypeArgument (0 ).asClass ()).isEqualTo (Integer .class );
124124 }
125125 }
126126}
0 commit comments