44
55import java .lang .reflect .Constructor ;
66import java .util .ArrayList ;
7- import java .util .Optional ;
87
98import static org .hamcrest .MatcherAssert .assertThat ;
109import static org .hamcrest .Matchers .equalTo ;
1110import static org .hamcrest .Matchers .instanceOf ;
1211import static org .hamcrest .Matchers .notNullValue ;
12+ import static org .hamcrest .Matchers .nullValue ;
1313import static org .junit .jupiter .api .Assertions .assertThrows ;
1414
1515/**
@@ -20,12 +20,24 @@ class ConstructorUtilsTest {
2020 @ Test
2121 void shouldReturnConstructorIfApplicable () throws NoSuchMethodException {
2222 // given / when
23- Optional < Constructor <Sample >> constr1 = ConstructorUtils .tryFindConstructor (Sample .class , int .class , String .class );
24- Optional < Constructor <Sample >> constr2 = ConstructorUtils .tryFindConstructor (Sample .class , int .class , long .class );
23+ Constructor <Sample > constr1 = ConstructorUtils .getConstructorOrNull (Sample .class , int .class , String .class );
24+ Constructor <Sample > constr2 = ConstructorUtils .getConstructorOrNull (Sample .class , int .class , long .class );
2525
2626 // then
27- assertThat (constr1 , equalTo (Optional .of (Sample .class .getDeclaredConstructor (int .class , String .class ))));
28- assertThat (constr2 , equalTo (Optional .empty ()));
27+ assertThat (constr1 , equalTo (Sample .class .getDeclaredConstructor (int .class , String .class )));
28+ assertThat (constr2 , nullValue ());
29+ }
30+
31+ @ Test
32+ void shouldCompileWithWildcard () {
33+ // given
34+ Class <?> clazz = Sample .class ;
35+
36+ // when
37+ Constructor <?> result = ConstructorUtils .getConstructorOrNull (clazz , String [].class );
38+
39+ // then
40+ assertThat (result , nullValue ());
2941 }
3042
3143 @ Test
0 commit comments