Skip to content

Commit 3cfdb78

Browse files
committed
Introduce JUnit Jupiter
1 parent 42d8d53 commit 3cfdb78

File tree

6 files changed

+70
-61
lines changed

6 files changed

+70
-61
lines changed

pom.xml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<maven.compiler.source>1.8</maven.compiler.source>
2525
<maven.compiler.target>1.8</maven.compiler.target>
2626
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
27-
<!-- Needed to properly bring in the Maven dependencies, see http://maven.apache.org/surefire/maven-surefire-plugin/examples/class-loading.html) -->
27+
<!-- Needed to properly bring in the Maven dependencies, see http://maven.apache.org/surefire/maven-surefire-plugin/examples/class-loading.html -->
2828
<surefire.useSystemClassLoader>false</surefire.useSystemClassLoader>
2929
</properties>
3030

@@ -36,9 +36,10 @@
3636
<version>33.3.1-jre</version>
3737
</dependency>
3838
<dependency>
39-
<groupId>junit</groupId>
40-
<artifactId>junit</artifactId>
41-
<version>4.13.2</version>
39+
<groupId>org.junit</groupId>
40+
<artifactId>junit-bom</artifactId>
41+
<version>5.11.1</version>
42+
<scope>test</scope>
4243
</dependency>
4344
</dependencies>
4445
</dependencyManagement>
@@ -76,17 +77,22 @@
7677
<version>2.17.0</version>
7778
<scope>test</scope>
7879
</dependency>
79-
<dependency>
80-
<groupId>junit</groupId>
81-
<artifactId>junit</artifactId>
82-
<scope>test</scope>
83-
</dependency>
8480
<dependency>
8581
<groupId>org.assertj</groupId>
8682
<artifactId>assertj-core</artifactId>
8783
<version>3.26.3</version>
8884
<scope>test</scope>
8985
</dependency>
86+
<dependency>
87+
<groupId>org.junit.jupiter</groupId>
88+
<artifactId>junit-jupiter</artifactId>
89+
<scope>test</scope>
90+
</dependency>
91+
<dependency>
92+
<groupId>org.junit.vintage</groupId>
93+
<artifactId>junit-vintage-engine</artifactId>
94+
<scope>test</scope>
95+
</dependency>
9096
</dependencies>
9197

9298
<build>

src/test/java/org/assertj/assertions/generator/PlayerAssertTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414

1515
// import static org.assertj.assertions.generator.data.PlayerAssert.assertThat;
1616

17-
import org.junit.Test;
17+
import org.junit.jupiter.api.Test;
1818

1919
public class PlayerAssertTest {
2020

2121
@Test
22-
public void test() {
22+
void test() {
2323
// uncomment to test
2424
// Player tonyParker = new Player(new Name("Tony", "Parker"), "Spurs");
2525
// tonyParker.setAssistsPerGame(9);

src/test/java/org/assertj/assertions/generator/TemplateTest.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
*/
1313
package org.assertj.assertions.generator;
1414

15+
import org.junit.jupiter.api.Test;
16+
1517
import static org.assertj.assertions.generator.BaseAssertionGenerator.TEMPLATES_DIR;
1618
import static org.assertj.assertions.generator.DefaultTemplateRegistryProducer.DEFAULT_HAS_ASSERTION_TEMPLATE;
1719
import static org.assertj.assertions.generator.Template.Type.ASSERT_CLASS;
@@ -22,13 +24,10 @@
2224
import java.io.File;
2325
import java.net.URL;
2426

25-
import org.junit.Test;
26-
27-
public class TemplateTest {
27+
class TemplateTest {
2828

29-
@SuppressWarnings("unused")
3029
@Test
31-
public void should_throw_an_exception_when_url_is_a_directory() {
30+
void should_throw_an_exception_when_url_is_a_directory() {
3231
URL templateURL = getClass().getClassLoader().getResource(TEMPLATES_DIR);
3332
try {
3433
new Template(ASSERT_CLASS, templateURL);
@@ -39,14 +38,14 @@ public void should_throw_an_exception_when_url_is_a_directory() {
3938
}
4039

4140
@Test
42-
public void should_create_template_from_url() {
41+
void should_create_template_from_url() {
4342
URL templateURL = getClass().getClassLoader().getResource(TEMPLATES_DIR + DEFAULT_HAS_ASSERTION_TEMPLATE);
4443
Template template = new Template(ASSERT_CLASS, templateURL);
4544
assertThat(template.getContent()).isNotEmpty();
4645
}
4746

4847
@Test
49-
public void should_create_template_from_file() {
48+
void should_create_template_from_file() {
5049
File templateFile = new File(TEMPLATES_DIR, DEFAULT_HAS_ASSERTION_TEMPLATE);
5150
Template template = new Template(HAS, templateFile);
5251
assertThat(template.getContent()).isNotEmpty();

src/test/java/org/assertj/assertions/generator/description/FieldDescriptionTest.java

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,25 @@
1515
import com.google.common.reflect.TypeToken;
1616
import org.assertj.assertions.generator.data.EnemyReport;
1717
import org.assertj.assertions.generator.data.Name;
18-
import org.assertj.assertions.generator.data.lotr.TolkienCharacter;
1918
import org.assertj.assertions.generator.data.nba.Player;
2019
import 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;
2422
import java.util.Arrays;
2523
import java.util.Collections;
2624

2725
import static org.assertj.assertions.generator.util.ClassUtil.propertyNameOf;
2826
import 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
}

src/test/java/org/assertj/assertions/generator/description/GetterDescriptionTest.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
import org.assertj.assertions.generator.data.Movie;
1717
import org.assertj.assertions.generator.data.lotr.TolkienCharacter;
1818
import org.assertj.assertions.generator.data.nba.Player;
19-
import org.junit.BeforeClass;
20-
import org.junit.Test;
19+
import org.junit.jupiter.api.BeforeAll;
20+
import org.junit.jupiter.api.Test;
2121

2222
import java.lang.reflect.Method;
2323

@@ -31,13 +31,13 @@ public class GetterDescriptionTest {
3131

3232
private static Method PLAYER_GET_POINTS_METHOD;
3333

34-
@BeforeClass
35-
public static void setupClass() throws Exception {
34+
@BeforeAll
35+
static void setupClass() throws Exception {
3636
PLAYER_GET_POINTS_METHOD = Player.class.getMethod("getPoints");
3737
}
3838

3939
@Test
40-
public void should_create_valid_typename_from_class() throws Exception {
40+
void should_create_valid_typename_from_class() throws Exception {
4141
getterDescription = new GetterDescription("points", PLAYER_TYPE_DESCRIPTION, PLAYER_GET_POINTS_METHOD);
4242
assertThat(getterDescription.getName()).isEqualTo("points");
4343
assertThat(getterDescription.getTypeName()).isEqualTo("java.util.List");
@@ -46,37 +46,37 @@ public void should_create_valid_typename_from_class() throws Exception {
4646
}
4747

4848
@Test
49-
public void should_create_valid_typename_from_class_for_user_defined_type_in_same_package() throws Exception {
49+
void should_create_valid_typename_from_class_for_user_defined_type_in_same_package() throws Exception {
5050
getterDescription = new GetterDescription("race", TypeToken.of(TolkienCharacter.class), TolkienCharacter.class.getMethod("getRace"));
5151
assertThat(getterDescription.getName()).isEqualTo("race");
5252
assertThat(getterDescription.getTypeName()).isEqualTo("Race");
5353
assertThat(getterDescription.getFullyQualifiedTypeName()).isEqualTo("org.assertj.assertions.generator.data.lotr.Race");
5454
}
5555

5656
@Test
57-
public void should_create_valid_typename_from_class_for_user_defined_type_in_different_package() throws Exception {
57+
void should_create_valid_typename_from_class_for_user_defined_type_in_different_package() throws Exception {
5858
getterDescription = new GetterDescription("name", PLAYER_TYPE_DESCRIPTION, Player.class.getMethod("getName"));
5959
assertThat(getterDescription.getName()).isEqualTo("name");
6060
assertThat(getterDescription.getTypeName()).isEqualTo("org.assertj.assertions.generator.data.Name");
6161
assertThat(getterDescription.getFullyQualifiedTypeName()).isEqualTo("org.assertj.assertions.generator.data.Name");
6262
}
6363

6464
@Test
65-
public void should_show_information_in_toString() throws Exception {
65+
void should_show_information_in_toString() throws Exception {
6666
getterDescription = new GetterDescription("points", PLAYER_TYPE_DESCRIPTION, PLAYER_GET_POINTS_METHOD);
6767
assertThat(getterDescription.toString()).contains("points").contains("List<int[]>");
6868
}
6969

7070
@Test
71-
public void should_not_be_predicate() throws Exception {
71+
void should_not_be_predicate() throws Exception {
7272
getterDescription = new GetterDescription("points", PLAYER_TYPE_DESCRIPTION, PLAYER_GET_POINTS_METHOD);
7373
assertThat(getterDescription.isPredicate()).as("points").isFalse();
7474
getterDescription = new GetterDescription("rookie", PLAYER_TYPE_DESCRIPTION, Player.class.getMethod("isRookie"));
7575
assertThat(getterDescription.isPredicate()).as("rookie").isTrue();
7676
}
7777

7878
@Test
79-
public void should_generate_predicate_for_javadoc() throws Exception {
79+
void should_generate_predicate_for_javadoc() throws Exception {
8080
getterDescription = new GetterDescription("rookie", PLAYER_TYPE_DESCRIPTION, Player.class.getMethod("isRookie"));
8181
assertThat(getterDescription.getPredicateForJavadoc()).isEqualTo("is rookie");
8282
assertThat(getterDescription.getNegativePredicateForJavadoc()).isEqualTo("is not rookie");
@@ -115,7 +115,7 @@ public void should_generate_predicate_for_javadoc() throws Exception {
115115
}
116116

117117
@Test
118-
public void should_generate_predicate_for_error_message() throws Exception {
118+
void should_generate_predicate_for_error_message() throws Exception {
119119
getterDescription = new GetterDescription("rookie", PLAYER_TYPE_DESCRIPTION, Player.class.getMethod("isRookie"));
120120
assertThat(getterDescription.getPredicateForErrorMessagePart1()).isEqualTo("is rookie");
121121
assertThat(getterDescription.getPredicateForErrorMessagePart2()).isEqualTo("is not");
@@ -154,7 +154,7 @@ public void should_generate_predicate_for_error_message() throws Exception {
154154
}
155155

156156
@Test
157-
public void should_describe_inner_class_getter_correctly() throws Exception {
157+
void should_describe_inner_class_getter_correctly() throws Exception {
158158
Method getPublicCategory = Movie.class.getMethod("getPublicCategory");
159159
getterDescription = new GetterDescription("publicCategory", TypeToken.of(Movie.class), getPublicCategory);
160160
assertThat(getterDescription.getName()).isEqualTo("publicCategory");

src/test/java/org/assertj/assertions/generator/util/StringUtilTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
*/
1313
package org.assertj.assertions.generator.util;
1414

15+
import org.junit.jupiter.api.Test;
16+
1517
import static org.assertj.assertions.generator.util.StringUtil.camelCaseToWords;
1618
import static org.assertj.core.api.Assertions.assertThat;
1719

18-
import org.junit.Test;
19-
20-
public class StringUtilTest {
20+
class StringUtilTest {
2121

2222
@Test
23-
public void testCamelCaseToWords() throws Exception {
23+
void testCamelCaseToWords() throws Exception {
2424
assertThat(camelCaseToWords("BestPlayer")).isEqualTo("best player");
2525
assertThat(camelCaseToWords("Run")).isEqualTo("run");
2626
assertThat(camelCaseToWords("RunFasterThanLight")).isEqualTo("run faster than light");

0 commit comments

Comments
 (0)