1515import com .google .common .reflect .TypeToken ;
1616import org .assertj .assertions .generator .data .EnemyReport ;
1717import org .assertj .assertions .generator .data .Name ;
18- import org .assertj .assertions .generator .data .lotr .TolkienCharacter ;
1918import org .assertj .assertions .generator .data .nba .Player ;
2019import org .assertj .assertions .generator .data .nba .team .Coach ;
21- import org .junit .Test ;
20+ import org .junit .jupiter . api . Test ;
2221
23- import java .lang .reflect .Field ;
2422import java .util .Arrays ;
2523import java .util .Collections ;
2624
2725import static org .assertj .assertions .generator .util .ClassUtil .propertyNameOf ;
2826import static org .assertj .core .api .Assertions .assertThat ;
27+ import static org .assertj .core .api .Assertions .catchException ;
28+ import static org .assertj .core .api .BDDAssertions .then ;
2929
30- public class FieldDescriptionTest {
30+ class FieldDescriptionTest {
3131
3232 private static final TypeToken <Player > PLAYER_TYPE = TypeToken .of (Player .class );
3333 private FieldDescription fieldDescription ;
3434
3535 @ Test
36- public void should_create_valid_typename_from_class () throws Exception {
36+ void should_create_valid_typename_from_class () throws Exception {
3737 fieldDescription = new FieldDescription (Player .class .getDeclaredField ("name" ), PLAYER_TYPE );
3838 assertThat (fieldDescription .getName ()).isEqualTo ("name" );
3939 assertThat (fieldDescription .getTypeName ()).isEqualTo (Name .class .getName ());
@@ -42,21 +42,21 @@ public void should_create_valid_typename_from_class() throws Exception {
4242 }
4343
4444 @ Test
45- public void should_create_valid_typename_from_class_for_user_defined_type_in_same_package () throws Exception {
45+ void should_create_valid_typename_from_class_for_user_defined_type_in_same_package () throws Exception {
4646 fieldDescription = new FieldDescription (Coach .class .getDeclaredField ("team" ), TypeToken .of (Coach .class ));
4747 assertThat (fieldDescription .getName ()).isEqualTo ("team" );
4848 assertThat (fieldDescription .getTypeName ()).isEqualTo ("Team" );
4949 assertThat (fieldDescription .getFullyQualifiedTypeName ()).isEqualTo ("org.assertj.assertions.generator.data.nba.team.Team" );
5050 }
5151
5252 @ Test
53- public void should_show_information_in_toString () throws Exception {
53+ void should_show_information_in_toString () throws Exception {
5454 fieldDescription = new FieldDescription (Player .class .getDeclaredField ("name" ), PLAYER_TYPE );
5555 assertThat (fieldDescription .toString ()).contains ("name" , Player .class .getName (), Name .class .getName ());
5656 }
5757
5858 @ Test
59- public void should_detect_real_number_correctly () throws Exception {
59+ void should_detect_real_number_correctly () throws Exception {
6060 fieldDescription = new FieldDescription (Player .class .getDeclaredField ("sizeDouble" ), PLAYER_TYPE );
6161 assertThat (fieldDescription .isRealNumberType ()).as ("double" ).isTrue ();
6262 fieldDescription = new FieldDescription (Player .class .getDeclaredField ("sizeAsDoubleWrapper" ), PLAYER_TYPE );
@@ -76,28 +76,28 @@ public void should_detect_real_number_correctly() throws Exception {
7676 }
7777
7878 @ Test
79- public void should_generate_default_predicate_correctly () throws Exception {
79+ void should_generate_default_predicate_correctly () throws Exception {
8080 fieldDescription = new FieldDescription (Player .class .getDeclaredField ("bad" ), PLAYER_TYPE );
8181 assertThat (fieldDescription .getNegativePredicate ()).as ("negative" ).isEqualTo ("isNotBad" );
8282 assertThat (fieldDescription .getPredicate ()).as ("positive" ).isEqualTo ("isBad" );
8383 }
8484
8585 @ Test
86- public void should_describe_array_field_correctly () throws Exception {
86+ void should_describe_array_field_correctly () throws Exception {
8787 fieldDescription = new FieldDescription (Player .class .getDeclaredField ("previousTeamNames" ), PLAYER_TYPE );
8888 assertThat (fieldDescription .getTypeName ()).isEqualTo ("String[]" );
8989 assertThat (fieldDescription .getElementTypeName ()).isEqualTo ("String" );
9090 }
9191
9292 @ Test
93- public void should_generate_readable_predicate_for_javadoc () throws Exception {
93+ void should_generate_readable_predicate_for_javadoc () throws Exception {
9494 fieldDescription = new FieldDescription (Player .class .getDeclaredField ("bad" ), PLAYER_TYPE );
9595 assertThat (fieldDescription .getPredicateForJavadoc ()).isEqualTo ("is bad" );
9696 assertThat (fieldDescription .getNegativePredicateForJavadoc ()).isEqualTo ("is not bad" );
9797 }
9898
9999 @ Test
100- public void should_generate_readable_predicate_for_error_message () throws Exception {
100+ void should_generate_readable_predicate_for_error_message () throws Exception {
101101 fieldDescription = new FieldDescription (Player .class .getDeclaredField ("bad" ), PLAYER_TYPE );
102102 assertThat (fieldDescription .getPredicateForErrorMessagePart1 ()).isEqualTo ("is bad" );
103103 assertThat (fieldDescription .getPredicateForErrorMessagePart2 ()).isEqualTo ("is not" );
@@ -137,7 +137,7 @@ public int getBadGetter() {
137137 }
138138
139139 @ Test
140- public void should_find_getter_method_for_predicate_field () throws Exception {
140+ void should_find_getter_method_for_predicate_field () throws Exception {
141141
142142 fieldDescription = new FieldDescription (FieldPropertyNames .class .getDeclaredField ("isBoolean" ), FIELD_PROP_TYPE );
143143
@@ -155,15 +155,15 @@ public void should_find_getter_method_for_predicate_field() throws Exception {
155155 }
156156
157157 @ Test
158- public void should_return_property_of_field () throws Exception {
158+ void should_return_property_of_field () throws Exception {
159159 assertThat (propertyNameOf (FieldPropertyNames .class .getDeclaredField ("isBoolean" ))).isEqualTo ("boolean" );
160160 assertThat (propertyNameOf (EnemyReport .class .getDeclaredField ("realTarget" ))).isEqualTo ("realTarget" );
161161 assertThat (propertyNameOf (EnemyReport .class .getDeclaredField ("privateTarget" ))).isEqualTo ("privateTarget" );
162162 assertThat (propertyNameOf (EnemyReport .class .getDeclaredField ("isTarget" ))).isEqualTo ("target" );
163163 }
164164
165165 @ Test
166- public void should_find_getter_method_for_field () throws Exception {
166+ void should_find_getter_method_for_field () throws Exception {
167167
168168 fieldDescription = new FieldDescription (FieldPropertyNames .class .getDeclaredField ("stringProp" ), FIELD_PROP_TYPE );
169169
@@ -179,7 +179,7 @@ public void should_find_getter_method_for_field() throws Exception {
179179 }
180180
181181 @ Test
182- public void should_not_find_getter_method_for_mismatched_return_type () throws Exception {
182+ void should_not_find_getter_method_for_mismatched_return_type () throws Exception {
183183
184184 fieldDescription = new FieldDescription (FieldPropertyNames .class .getDeclaredField ("badGetter" ), FIELD_PROP_TYPE );
185185
@@ -195,7 +195,7 @@ public void should_not_find_getter_method_for_mismatched_return_type() throws Ex
195195 }
196196
197197 @ Test
198- public void should_not_find_getter_method_for_missing_getter () throws Exception {
198+ void should_not_find_getter_method_for_missing_getter () throws Exception {
199199
200200 fieldDescription = new FieldDescription (FieldPropertyNames .class .getDeclaredField ("onlyField" ), FIELD_PROP_TYPE );
201201
@@ -211,20 +211,24 @@ public void should_not_find_getter_method_for_missing_getter() throws Exception
211211 // @Test
212212 // public void should_not_find_getter_method_for_non_existent_field()
213213
214- @ Test ( expected = NullPointerException . class )
215- public void should_fail_find_with_npe_for_null_field_desc () throws Exception {
216-
214+ @ Test
215+ void should_fail_find_with_npe_for_null_field_desc () {
216+ // GIVEN
217217 ClassDescription classDesc = new ClassDescription (FIELD_PROP_TYPE );
218-
219- classDesc .hasGetterForField (null );
218+ // WHEN
219+ Exception exception = catchException (() -> classDesc .hasGetterForField (null ));
220+ // THEN
221+ then (exception ).isInstanceOf (NullPointerException .class );
220222 }
221223
222- @ Test ( expected = NullPointerException . class )
223- public void should_fail_has_with_npe_for_null_field_desc () throws Exception {
224-
224+ @ Test
225+ void should_fail_has_with_npe_for_null_field_desc () {
226+ // GIVEN
225227 ClassDescription classDesc = new ClassDescription (FIELD_PROP_TYPE );
226-
227- classDesc .hasGetterForField (null );
228+ // WHEN
229+ Exception exception = catchException (() -> classDesc .hasGetterForField (null ));
230+ // THEN
231+ then (exception ).isInstanceOf (NullPointerException .class );
228232 }
229233
230234}
0 commit comments