Skip to content

Commit b7efe5e

Browse files
authored
Merge pull request #86 from ral-facilities/junit5
Upgrade to JUnit 5
2 parents 408a2b0 + b004c85 commit b7efe5e

File tree

11 files changed

+162
-136
lines changed

11 files changed

+162
-136
lines changed

.github/workflows/ci-build.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ jobs:
1313
matrix:
1414
java_version:
1515
- 11
16-
# Errors with `java.lang.IllegalArgumentException: ArquillianServletRunnerEE9 not found. Could not determine ContextRoot from ProtocolMetadata, please contact DeployableContainer developer.`
17-
# Bumping various Arquillian dependencies does not fix, leave as just Java 11
18-
# - 17
16+
- 21
1917

2018
steps:
2119
- name: Setup Java

pom.xml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
<dependency>
127127
<groupId>org.jboss.arquillian</groupId>
128128
<artifactId>arquillian-bom</artifactId>
129-
<version>1.7.0.Final</version>
129+
<version>1.9.5.Final</version>
130130
<scope>import</scope>
131131
<type>pom</type>
132132
</dependency>
@@ -153,14 +153,14 @@
153153
<version>1.2.13</version>
154154
</dependency>
155155
<dependency>
156-
<groupId>junit</groupId>
157-
<artifactId>junit</artifactId>
158-
<version>4.13.2</version>
156+
<groupId>org.junit.jupiter</groupId>
157+
<artifactId>junit-jupiter</artifactId>
158+
<version>5.13.1</version>
159159
<scope>test</scope>
160160
</dependency>
161161
<dependency>
162-
<groupId>org.jboss.arquillian.junit</groupId>
163-
<artifactId>arquillian-junit-container</artifactId>
162+
<groupId>org.jboss.arquillian.junit5</groupId>
163+
<artifactId>arquillian-junit5-container</artifactId>
164164
<scope>test</scope>
165165
</dependency>
166166
<!-- required for @Transactional annotation -->
@@ -208,13 +208,13 @@
208208
<dependency>
209209
<groupId>org.omnifaces.arquillian</groupId>
210210
<artifactId>arquillian-glassfish-server-embedded</artifactId>
211-
<version>1.4</version>
211+
<version>1.8</version>
212212
<scope>test</scope>
213213
</dependency>
214214
<dependency>
215215
<groupId>org.glassfish.main.extras</groupId>
216216
<artifactId>glassfish-embedded-all</artifactId>
217-
<version>7.0.5</version>
217+
<version>7.0.25</version>
218218
<scope>test</scope>
219219
</dependency>
220220
<dependency>
@@ -242,9 +242,11 @@
242242
GlassFish to retarget the derby log file -->
243243
<plugin>
244244
<artifactId>maven-surefire-plugin</artifactId>
245-
<version>2.19.1</version>
245+
<version>3.5.3</version>
246246
<configuration>
247-
<argLine>-Xmx768m -XX:MaxMetaspaceSize=256m</argLine>
247+
<!-- Required for jdk 17+ -->
248+
<argLine>--add-opens java.base/java.lang=ALL-UNNAMED</argLine>
249+
248250
<systemPropertyVariables>
249251
<java.util.logging.config.file>
250252
${project.build.testOutputDirectory}/logging.properties

src/test/java/org/icatproject/topcat/AdminResourceTest.java

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,46 @@
11
package org.icatproject.topcat;
22

3-
import java.util.*;
3+
import java.net.URLEncoder;
4+
import java.util.ArrayList;
45
import java.util.Date;
5-
import java.io.File;
6-
import java.lang.reflect.*;
6+
import java.util.HashMap;
7+
import java.util.List;
8+
import java.util.Map;
9+
10+
import jakarta.inject.Inject;
11+
import jakarta.json.JsonObject;
12+
import jakarta.ejb.EJB;
13+
import jakarta.ws.rs.core.Response;
714

815
import org.jboss.arquillian.container.test.api.Deployment;
9-
import org.jboss.arquillian.junit.Arquillian;
16+
import org.jboss.arquillian.junit5.container.annotation.ArquillianTest;
1017
import org.jboss.shrinkwrap.api.ShrinkWrap;
1118
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
1219
import org.jboss.shrinkwrap.api.spec.JavaArchive;
1320

14-
import static org.junit.Assert.*;
15-
import org.junit.*;
16-
import org.junit.runner.RunWith;
17-
import jakarta.inject.Inject;
21+
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertFalse;
23+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
24+
import static org.junit.jupiter.api.Assertions.assertNotNull;
25+
import static org.junit.jupiter.api.Assertions.assertNull;
26+
import static org.junit.jupiter.api.Assertions.fail;
1827

19-
import jakarta.json.*;
20-
import jakarta.ws.rs.core.Response;
21-
import jakarta.ejb.EJB;
28+
import org.junit.jupiter.api.BeforeAll;
29+
import org.junit.jupiter.api.BeforeEach;
30+
import org.junit.jupiter.api.Test;
2231

2332
import org.icatproject.topcat.httpclient.HttpClient;
24-
import org.icatproject.topcat.domain.*;
25-
import org.icatproject.topcat.exceptions.BadRequestException;
33+
import org.icatproject.topcat.domain.Download;
34+
import org.icatproject.topcat.domain.DownloadStatus;
35+
import org.icatproject.topcat.domain.DownloadType;
2636
import org.icatproject.topcat.exceptions.ForbiddenException;
27-
28-
import java.net.URLEncoder;
29-
3037
import org.icatproject.topcat.repository.CacheRepository;
3138
import org.icatproject.topcat.repository.ConfVarRepository;
3239
import org.icatproject.topcat.repository.DownloadRepository;
3340
import org.icatproject.topcat.repository.DownloadTypeRepository;
3441
import org.icatproject.topcat.web.rest.AdminResource;
3542

36-
import java.sql.*;
37-
38-
@RunWith(Arquillian.class)
43+
@ArquillianTest
3944
public class AdminResourceTest {
4045

4146
/*
@@ -71,12 +76,12 @@ public static JavaArchive createDeployment() {
7176
private static String adminSessionId;
7277
private static String nonAdminSessionId;
7378

74-
@BeforeClass
79+
@BeforeAll
7580
public static void beforeAll() {
7681
TestHelpers.installTrustManager();
7782
}
7883

79-
@Before
84+
@BeforeEach
8085
public void setup() throws Exception {
8186
HttpClient httpClient = new HttpClient("https://localhost:8181/icat");
8287

@@ -194,7 +199,7 @@ public void testDownloadAPI() throws Exception {
194199
downloads = (List<Download>) response.getEntity();
195200

196201
testDownload = findDownload(downloads, testDownload.getId());
197-
assertTrue(testDownload.getIsDeleted() != currentDeleted);
202+
assertNotEquals(testDownload.getIsDeleted(), currentDeleted);
198203

199204
// Test that getDownloadStatus() etc. produce an error response for a non-admin
200205
// user
@@ -206,7 +211,6 @@ public void testDownloadAPI() throws Exception {
206211
+ (String) response.getEntity());
207212
fail("AdminResource.getDownloads did not raise exception for non-admin user");
208213
} catch (ForbiddenException fe) {
209-
assertTrue(true);
210214
}
211215

212216
try {
@@ -217,7 +221,6 @@ public void testDownloadAPI() throws Exception {
217221
+ (String) response.getEntity());
218222
fail("AdminResource.setDownloadStatus did not raise exception for non-admin user");
219223
} catch (ForbiddenException fe) {
220-
assertTrue(true);
221224
}
222225

223226
try {
@@ -228,7 +231,6 @@ public void testDownloadAPI() throws Exception {
228231
+ (String) response.getEntity());
229232
fail("AdminResource.deleteDownload did not raise exception for non-admin user");
230233
} catch (ForbiddenException fe) {
231-
assertTrue(true);
232234
}
233235
} finally {
234236
// Remove the test download from the repository
@@ -308,7 +310,7 @@ public void testSetDownloadTypeStatus() throws Exception {
308310
if (dt != null) {
309311
System.out.println(
310312
"DEBUG: AdminRT final download type status is {" + dt.getDisabled() + "," + dt.getMessage() + "}");
311-
assertTrue(disabled != dt.getDisabled());
313+
assertNotEquals(disabled, dt.getDisabled());
312314
assertEquals(message, dt.getMessage());
313315
}
314316

@@ -322,7 +324,6 @@ public void testSetDownloadTypeStatus() throws Exception {
322324
+ (String) response.getEntity());
323325
fail("AdminResource.setDownloadTypeStatus did not raise exception for non-admin user");
324326
} catch (ForbiddenException fe) {
325-
assertTrue(true);
326327
}
327328

328329
// Finally, ought to reset the disabled status to the original value!
@@ -406,7 +407,6 @@ public void testClearCachedSize() throws Exception {
406407
+ (String) response.getEntity());
407408
fail("AdminResource.clearCachedSize did not raise exception for non-admin user");
408409
} catch (ForbiddenException fe) {
409-
assertTrue(true);
410410
}
411411
}
412412

@@ -437,7 +437,6 @@ public void testSetConfVar() throws Exception {
437437
+ (String) response.getEntity());
438438
fail("AdminResource.setConfVar did not raise exception for non-admin user");
439439
} catch (ForbiddenException fe) {
440-
assertTrue(true);
441440
}
442441
}
443442

src/test/java/org/icatproject/topcat/CacheRepositoryTest.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
package org.icatproject.topcat;
22

3-
import java.util.*;
4-
import java.lang.reflect.*;
3+
import jakarta.inject.Inject;
54

65
import org.jboss.arquillian.container.test.api.Deployment;
7-
import org.jboss.arquillian.junit.Arquillian;
6+
import org.jboss.arquillian.junit5.container.annotation.ArquillianTest;
87
import org.jboss.shrinkwrap.api.ShrinkWrap;
98
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
109
import org.jboss.shrinkwrap.api.spec.JavaArchive;
11-
import static org.junit.Assert.*;
12-
import org.junit.*;
13-
import org.junit.runner.RunWith;
14-
import jakarta.inject.Inject;
1510

11+
import static org.junit.jupiter.api.Assertions.assertEquals;
12+
import static org.junit.jupiter.api.Assertions.assertNull;
1613

17-
import jakarta.ejb.EJB;
14+
import org.junit.jupiter.api.Test;
1815

1916
import org.icatproject.topcat.domain.Cache;
2017
import org.icatproject.topcat.repository.CacheRepository;
2118

22-
@RunWith(Arquillian.class)
19+
@ArquillianTest
2320
public class CacheRepositoryTest {
2421

2522
@Deployment
@@ -44,6 +41,6 @@ public void testRemove() {
4441
String key = "test:remove";
4542
cacheRepository.put(key, "Hello World");
4643
cacheRepository.remove(key);
47-
assertEquals(null,cacheRepository.get(key));
44+
assertNull(cacheRepository.get(key));
4845
}
49-
}
46+
}

src/test/java/org/icatproject/topcat/FacilityMapTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package org.icatproject.topcat;
22

3-
import static org.junit.Assert.*;
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertThrows;
45

56
import java.util.HashMap;
67
import java.util.Map;
78

89
import org.icatproject.topcat.exceptions.InternalException;
9-
import org.junit.*;
10-
import org.junit.function.ThrowingRunnable;
10+
import org.junit.jupiter.api.Test;
11+
import org.junit.jupiter.api.function.Executable;
1112

1213
public class FacilityMapTest {
1314

@@ -153,7 +154,7 @@ public void testGetIcatUrlFailure() throws InternalException{
153154

154155
FacilityMap facilityMap = new FacilityMap(props);
155156

156-
ThrowingRunnable runnable = () -> {facilityMap.getIcatUrl(null);};
157+
Executable runnable = () -> {facilityMap.getIcatUrl(null);};
157158
assertThrows(InternalException.class, runnable);
158159
}
159160
}

src/test/java/org/icatproject/topcat/IcatClientTest.java

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,38 @@
11
package org.icatproject.topcat;
22

3-
import java.util.*;
4-
import java.lang.reflect.*;
5-
6-
import static org.junit.Assert.*;
7-
import org.junit.*;
3+
import java.net.URLEncoder;
4+
import java.util.ArrayList;
5+
import java.util.HashMap;
6+
import java.util.List;
7+
import java.util.Map;
88

9-
import jakarta.json.*;
10-
import jakarta.json.JsonValue.ValueType;
119
import jakarta.ejb.EJB;
10+
import jakarta.json.Json;
11+
import jakarta.json.JsonArray;
12+
import jakarta.json.JsonArrayBuilder;
13+
import jakarta.json.JsonObject;
14+
import jakarta.json.JsonObjectBuilder;
15+
import jakarta.json.JsonValue;
16+
import jakarta.json.JsonValue.ValueType;
17+
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertFalse;
20+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
21+
import static org.junit.jupiter.api.Assertions.assertNotNull;
22+
import static org.junit.jupiter.api.Assertions.assertTrue;
23+
24+
import org.junit.jupiter.api.BeforeAll;
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Test;
1227

1328
import org.icatproject.topcat.httpclient.HttpClient;
1429
import org.icatproject.topcat.httpclient.Response;
15-
import org.icatproject.topcat.domain.*;
1630
import org.icatproject.topcat.exceptions.TopcatException;
17-
18-
import java.net.URLEncoder;
19-
2031
import org.icatproject.topcat.repository.CacheRepository;
2132

22-
import java.sql.*;
33+
import java.sql.Connection;
34+
import java.sql.DriverManager;
35+
import java.sql.ResultSet;
2336

2437
public class IcatClientTest {
2538

@@ -30,12 +43,12 @@ public class IcatClientTest {
3043

3144
private Connection connection;
3245

33-
@BeforeClass
46+
@BeforeAll
3447
public static void beforeAll() {
3548
TestHelpers.installTrustManager();
3649
}
3750

38-
@Before
51+
@BeforeEach
3952
public void setup() throws Exception {
4053
HttpClient httpClient = new HttpClient("https://localhost:8181/icat");
4154
String data = "json=" + URLEncoder.encode(

src/test/java/org/icatproject/topcat/IdsClientTest.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package org.icatproject.topcat;
22

3-
import java.util.*;
4-
import java.lang.reflect.*;
3+
import java.lang.reflect.Method;
4+
import java.util.ArrayList;
5+
import java.util.List;
56

6-
import static org.junit.Assert.*;
7-
import org.junit.*;
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
import static org.junit.jupiter.api.Assertions.assertFalse;
9+
import static org.junit.jupiter.api.Assertions.assertTrue;
10+
11+
import org.junit.jupiter.api.Test;
812

913
public class IdsClientTest {
1014

@@ -54,16 +58,15 @@ public void testChunkOffsets() throws Exception {
5458
}
5559
allFound = allFound && foundInvestigation && foundDataset && foundDatafile;
5660
}
57-
assertTrue("Not all IDs found in chunks", allFound);
58-
assertTrue("At least one ID was repeated", ! foundRepeats);
61+
assertTrue(allFound, "Not all IDs found in chunks");
62+
assertFalse(foundRepeats, "At least one ID was repeated");
5963
}
6064

6165
String expected = "test?investigationIds=1,2,3&datasetIds=4,5,6&datafileIds=7,8,9";
6266
List<String> offsets = (List<String>) chunkOffsets.invoke(idsClient, "test?", generateIds(1, 3), generateIds(4, 3), generateIds(7, 3));
6367
String actual = offsets.get(0);
6468

65-
assertTrue("expected: " + expected + " actual: " + actual, expected.equals(actual));
66-
69+
assertEquals(expected, actual);
6770
}
6871

6972
@Test
@@ -94,4 +97,4 @@ private boolean chunkContains(String chunk, String entityType, Long id) {
9497
return chunk.matches(".*" + entityType + "Ids=[\\d+,]*" + id.toString() + "[,\\d+]*.*");
9598
}
9699

97-
}
100+
}

0 commit comments

Comments
 (0)