Skip to content

Commit 861aa17

Browse files
authored
Merge pull request #39 from imsweb/junit5
Convert to JUnit5
2 parents e0b8fbb + 8498c23 commit 861aa17

13 files changed

Lines changed: 196 additions & 162 deletions

File tree

build.gradle

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ dependencies {
4646
// newer version of dependency to fix vulnerability until converter-jackson is updated
4747
api 'com.fasterxml.jackson.core:jackson-databind:2.13.4'
4848

49-
testImplementation 'junit:junit:4.13.2'
49+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0'
50+
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.9.0'
51+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0'
5052
testImplementation 'org.assertj:assertj-core:3.23.1'
5153
testImplementation 'com.google.code.bean-matchers:bean-matchers:0.14'
5254
}
@@ -75,6 +77,10 @@ tasks.withType(Javadoc) {
7577
options.addStringOption('charSet', 'UTF-8')
7678
}
7779

80+
test {
81+
useJUnitPlatform()
82+
}
83+
7884
checkstyle {
7985
toolVersion '8.29'
8086
configFile = file("config/checkstyle/checkstyle.xml")

src/test/java/com/imsweb/seerapi/client/ObjectMapperTest.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,40 @@
33
import java.io.IOException;
44
import java.util.Collections;
55

6-
import org.junit.Assert;
7-
import org.junit.Test;
6+
import org.junit.jupiter.api.Test;
87

98
import com.fasterxml.jackson.databind.ObjectMapper;
109

1110
import com.imsweb.seerapi.client.disease.Disease;
1211
import com.imsweb.seerapi.client.disease.SiteRange;
1312
import com.imsweb.seerapi.client.disease.YearRange;
1413

15-
public class ObjectMapperTest {
14+
import static org.junit.jupiter.api.Assertions.assertEquals;
15+
import static org.junit.jupiter.api.Assertions.assertFalse;
16+
import static org.junit.jupiter.api.Assertions.assertTrue;
17+
18+
class ObjectMapperTest {
1619

1720
@Test
18-
public void testMapper() throws IOException {
21+
void testMapper() throws IOException {
1922
Range range = new Range("10", "40");
2023

2124
ObjectMapper mapper = SeerApi.getMapper();
2225

2326
String json = mapper.writeValueAsString(range);
2427

25-
Assert.assertTrue(json.contains("low"));
26-
Assert.assertFalse(json.contains("lowValue"));
28+
assertTrue(json.contains("low"));
29+
assertFalse(json.contains("lowValue"));
2730

2831
// now test reading that back in
2932
range = mapper.readValue(json, Range.class);
3033

31-
Assert.assertEquals("10", range.getLowValue());
32-
Assert.assertEquals("40", range.getHighValue());
34+
assertEquals("10", range.getLowValue());
35+
assertEquals("40", range.getHighValue());
3336
}
3437

3538
@Test
36-
public void testDiseaseMapping() throws IOException {
39+
void testDiseaseMapping() throws IOException {
3740
Disease partial = new Disease();
3841

3942
partial.setType(Disease.Type.HEMATO);
@@ -49,13 +52,13 @@ public void testDiseaseMapping() throws IOException {
4952

5053
String json = mapper.writeValueAsString(partial);
5154

52-
Assert.assertTrue(json.contains("icdO3_morphology"));
53-
Assert.assertFalse(json.contains("icdO3Morphology"));
55+
assertTrue(json.contains("icdO3_morphology"));
56+
assertFalse(json.contains("icdO3Morphology"));
5457

5558
// now test reading that back in
5659
partial = mapper.readValue(json, Disease.class);
5760

58-
Assert.assertEquals("9840/3", partial.getIcdO3Morphology());
61+
assertEquals("9840/3", partial.getIcdO3Morphology());
5962
}
6063

6164
}

src/test/java/com/imsweb/seerapi/client/SeerApiTest.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,26 @@
55

66
import java.io.IOException;
77

8-
import org.junit.Test;
8+
import org.junit.jupiter.api.Test;
99

10-
public class SeerApiTest {
10+
import retrofit2.Call;
1111

12-
@Test(expected = NotAuthorizedException.class)
13-
public void testBadApiKeyAndURL() throws IOException {
14-
new SeerApi.Builder().url("https://api.seer.cancer.gov/rest/").apiKey("BAD KEY").connect().siteRecode().version().execute();
12+
import com.imsweb.seerapi.client.shared.Version;
13+
14+
import static org.junit.jupiter.api.Assertions.assertThrows;
15+
16+
class SeerApiTest {
17+
18+
@Test
19+
void testBadApiKeyAndURL() {
20+
Call<Version> call = new SeerApi.Builder().url("https://api.seer.cancer.gov/rest/").apiKey("BAD KEY").connect().siteRecode().version();
21+
assertThrows(NotAuthorizedException.class, call::execute);
1522
}
1623

17-
@Test(expected = NotAuthorizedException.class)
18-
public void testBadApiKey() throws IOException {
19-
new SeerApi.Builder().apiKey("BAD KEY").connect().siteRecode().version().execute();
24+
@Test
25+
void testBadApiKey() throws IOException {
26+
Call<Version> call = new SeerApi.Builder().apiKey("BAD KEY").connect().siteRecode().version();
27+
assertThrows(NotAuthorizedException.class, call::execute);
2028
}
2129

2230
}

src/test/java/com/imsweb/seerapi/client/disease/DiseaseTest.java

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,38 @@
99

1010
import org.hamcrest.CoreMatchers;
1111
import org.hamcrest.MatcherAssert;
12-
import org.junit.BeforeClass;
13-
import org.junit.Test;
12+
import org.junit.jupiter.api.BeforeAll;
13+
import org.junit.jupiter.api.Test;
1414

1515
import com.imsweb.seerapi.client.SeerApi;
1616
import com.imsweb.seerapi.client.publishable.PublishableSearch;
1717

1818
import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanConstructor;
1919
import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertNotNull;
22-
import static org.junit.Assert.assertNull;
23-
import static org.junit.Assert.assertTrue;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertNotNull;
22+
import static org.junit.jupiter.api.Assertions.assertNull;
23+
import static org.junit.jupiter.api.Assertions.assertTrue;
2424

25-
public class DiseaseTest {
25+
class DiseaseTest {
2626

2727
private static DiseaseService _DISEASE;
2828

29-
@BeforeClass
29+
@BeforeAll
3030
public static void setup() {
3131
_DISEASE = new SeerApi.Builder().connect().disease();
3232
}
3333

3434
@Test
35-
public void testDiseaseTypeCategory() {
35+
void testDiseaseTypeCategory() {
3636
assertEquals(Disease.Type.SOLID_TUMOR, Disease.Type.valueOf("SOLID_TUMOR"));
3737
}
3838

3939
@Test
40-
public void testDiseaseVersions() throws IOException {
40+
void testDiseaseVersions() throws IOException {
4141
List<DiseaseVersion> versions = _DISEASE.versions().execute().body();
4242

43+
assertNotNull(versions);
4344
assertEquals(1, versions.size());
4445
DiseaseVersion version = versions.get(0);
4546
assertEquals("latest", version.getName());
@@ -49,27 +50,30 @@ public void testDiseaseVersions() throws IOException {
4950
}
5051

5152
@Test
52-
public void testDiseasePrimarySites() throws IOException {
53+
void testDiseasePrimarySites() throws IOException {
5354
List<PrimarySite> sites = _DISEASE.primarySites().execute().body();
5455

56+
assertNotNull(sites);
5557
assertTrue(sites.size() > 0);
5658
assertEquals("C000", sites.get(0).getValue());
5759
assertEquals("External upper lip", sites.get(0).getLabel());
5860
}
5961

6062
@Test
61-
public void testDiseasePrimarySiteCode() throws IOException {
63+
void testDiseasePrimarySiteCode() throws IOException {
6264
List<PrimarySite> sites = _DISEASE.primarySiteCode("C021").execute().body();
6365

66+
assertNotNull(sites);
6467
assertTrue(sites.size() > 0);
6568
assertEquals("C021", sites.get(0).getValue());
6669
assertEquals("Border of tongue", sites.get(0).getLabel());
6770
}
6871

6972
@Test
70-
public void testDiseaseSiteCateogires() throws IOException {
73+
void testDiseaseSiteCateogires() throws IOException {
7174
List<SiteCategory> categories = _DISEASE.siteCategories().execute().body();
7275

76+
assertNotNull(categories);
7377
assertTrue(categories.size() > 0);
7478
assertEquals("head-and-neck", categories.get(0).getId());
7579
assertEquals("Head and Neck", categories.get(0).getLabel());
@@ -80,7 +84,7 @@ public void testDiseaseSiteCateogires() throws IOException {
8084

8185
@SuppressWarnings("java:S5961")
8286
@Test
83-
public void testDiseaseById() throws IOException {
87+
void testDiseaseById() throws IOException {
8488
Disease disease = _DISEASE.getById("latest", "51f6cf58e3e27c3994bd5408").execute().body();
8589

8690
assertNotNull(disease);
@@ -141,7 +145,7 @@ public void testDiseaseById() throws IOException {
141145
}
142146

143147
@Test
144-
public void testDiseaseSamePrimary() throws IOException {
148+
void testDiseaseSamePrimary() throws IOException {
145149
SamePrimaries same = _DISEASE.samePrimaries("latest", "9870/3", "9872/3", "2010", "2010").execute().body();
146150

147151
assertNotNull(same);
@@ -163,7 +167,7 @@ public void testDiseaseSamePrimary() throws IOException {
163167
}
164168

165169
@Test
166-
public void testDiseaseSearch() throws IOException {
170+
void testDiseaseSearch() throws IOException {
167171
DiseaseSearch search = new DiseaseSearch("basophilic", Disease.Type.HEMATO);
168172

169173
DiseaseSearchResults results = _DISEASE.search("latest", search.paramMap()).execute().body();
@@ -212,7 +216,7 @@ public void testDiseaseSearch() throws IOException {
212216
}
213217

214218
@Test
215-
public void testDiseaseSearchIterate() throws IOException {
219+
void testDiseaseSearchIterate() throws IOException {
216220
DiseaseSearch search = new DiseaseSearch();
217221
search.setOutputType(PublishableSearch.OutputType.FULL);
218222
search.setCount(100);
@@ -235,7 +239,7 @@ public void testDiseaseSearchIterate() throws IOException {
235239
}
236240

237241
@Test
238-
public void testDiseaseReportability() throws IOException {
242+
void testDiseaseReportability() throws IOException {
239243
Disease partial = new Disease();
240244

241245
partial.setType(Disease.Type.HEMATO);
@@ -254,7 +258,7 @@ public void testDiseaseReportability() throws IOException {
254258
}
255259

256260
@Test
257-
public void testDiseaseChangelog() throws IOException {
261+
void testDiseaseChangelog() throws IOException {
258262
DiseaseChangelogResults results = _DISEASE.diseaseChangelogs("latest", null, "2013-07-30", 1).execute().body();
259263

260264
assertNotNull(results);
@@ -279,7 +283,7 @@ public void testDiseaseChangelog() throws IOException {
279283
}
280284

281285
@Test
282-
public void testBeans() {
286+
void testBeans() {
283287
MatcherAssert.assertThat(Disease.class, CoreMatchers.allOf(hasValidBeanConstructor(), hasValidGettersAndSetters()));
284288
MatcherAssert.assertThat(DiseaseVersion.class, CoreMatchers.allOf(hasValidBeanConstructor(), hasValidGettersAndSetters()));
285289
MatcherAssert.assertThat(DiseaseChangelog.class, CoreMatchers.allOf(hasValidBeanConstructor(), hasValidGettersAndSetters()));

src/test/java/com/imsweb/seerapi/client/glossary/GlossaryTest.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
import org.hamcrest.CoreMatchers;
1313
import org.hamcrest.MatcherAssert;
14-
import org.junit.BeforeClass;
15-
import org.junit.Test;
14+
import org.junit.jupiter.api.BeforeAll;
15+
import org.junit.jupiter.api.Test;
1616

1717
import com.imsweb.seerapi.client.SeerApi;
1818
import com.imsweb.seerapi.client.publishable.PublishableSearch;
@@ -21,27 +21,27 @@
2121
import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanConstructor;
2222
import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
2323
import static com.imsweb.seerapi.client.glossary.Glossary.Category.GENERAL;
24-
import static org.junit.Assert.assertEquals;
25-
import static org.junit.Assert.assertNotNull;
26-
import static org.junit.Assert.assertNull;
27-
import static org.junit.Assert.assertTrue;
24+
import static org.junit.jupiter.api.Assertions.assertEquals;
25+
import static org.junit.jupiter.api.Assertions.assertNotNull;
26+
import static org.junit.jupiter.api.Assertions.assertNull;
27+
import static org.junit.jupiter.api.Assertions.assertTrue;
2828

29-
public class GlossaryTest {
29+
class GlossaryTest {
3030

3131
private static GlossaryService _GLOSSARY;
3232

33-
@BeforeClass
33+
@BeforeAll
3434
public static void setup() {
3535
_GLOSSARY = new SeerApi.Builder().connect().glossary();
3636
}
3737

3838
@Test
39-
public void testGlossaryCategory() {
39+
void testGlossaryCategory() {
4040
assertEquals(Glossary.Category.SOLID_TUMOR, Glossary.Category.valueOf("SOLID_TUMOR"));
4141
}
4242

4343
@Test
44-
public void testGlossaryVersions() throws IOException {
44+
void testGlossaryVersions() throws IOException {
4545
List<GlossaryVersion> versions = _GLOSSARY.versions().execute().body();
4646

4747
assertNotNull(versions);
@@ -54,7 +54,7 @@ public void testGlossaryVersions() throws IOException {
5454
}
5555

5656
@Test
57-
public void testGlossaryById() throws IOException {
57+
void testGlossaryById() throws IOException {
5858
GlossarySearchResults results = _GLOSSARY.search("latest", "Lymphangiogram").execute().body();
5959
assertNotNull(results);
6060
assertTrue(results.getCount() > 0);
@@ -73,7 +73,7 @@ public void testGlossaryById() throws IOException {
7373
}
7474

7575
@Test
76-
public void testGlossaryChangelog() throws IOException {
76+
void testGlossaryChangelog() throws IOException {
7777
GlossaryChangelogResults results = _GLOSSARY.changelogs("latest", null, null, 1).execute().body();
7878

7979
assertNotNull(results);
@@ -104,7 +104,7 @@ public void testGlossaryChangelog() throws IOException {
104104
}
105105

106106
@Test
107-
public void testGlossarySearch() throws IOException {
107+
void testGlossarySearch() throws IOException {
108108
String term = "killer";
109109
GlossarySearch search = new GlossarySearch(term);
110110

@@ -135,7 +135,7 @@ public void testGlossarySearch() throws IOException {
135135
}
136136

137137
@Test
138-
public void testGlossarySearchIterate() throws IOException {
138+
void testGlossarySearchIterate() throws IOException {
139139
GlossarySearch search = new GlossarySearch();
140140
search.setOutputType(PublishableSearch.OutputType.FULL);
141141
search.setCount(25);
@@ -160,7 +160,7 @@ public void testGlossarySearchIterate() throws IOException {
160160
}
161161

162162
@Test
163-
public void testGlossaryMatch() throws IOException {
163+
void testGlossaryMatch() throws IOException {
164164
String text = "This text contains summary stage which should be found.";
165165

166166
Set<KeywordMatch> matches = _GLOSSARY.match(text, null, true).execute().body();
@@ -173,7 +173,7 @@ public void testGlossaryMatch() throws IOException {
173173
}
174174

175175
@Test
176-
public void testBeans() {
176+
void testBeans() {
177177
MatcherAssert.assertThat(Glossary.class, CoreMatchers.allOf(hasValidBeanConstructor(), hasValidGettersAndSetters()));
178178
MatcherAssert.assertThat(GlossaryVersion.class, CoreMatchers.allOf(hasValidBeanConstructor(), hasValidGettersAndSetters()));
179179
MatcherAssert.assertThat(GlossaryResource.class, CoreMatchers.allOf(hasValidBeanConstructor(), hasValidGettersAndSetters()));

0 commit comments

Comments
 (0)