Skip to content

Commit c3a88b9

Browse files
committed
junit5 upgrade
1 parent 5d5f7e7 commit c3a88b9

14 files changed

Lines changed: 239 additions & 205 deletions

jena-serviceenhancer/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
</dependency>
5050

5151
<dependency>
52-
<groupId>junit</groupId>
53-
<artifactId>junit</artifactId>
52+
<groupId>org.junit.jupiter</groupId>
53+
<artifactId>junit-jupiter</artifactId>
5454
<scope>test</scope>
5555
</dependency>
5656

jena-serviceenhancer/src/test/java/org/apache/jena/sparql/service/enhancer/assembler/TestServiceEnhancerDatasetAssembler.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@
1818

1919
package org.apache.jena.sparql.service.enhancer.assembler;
2020

21+
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertThrows;
23+
2124
import java.io.File;
2225
import java.io.IOException;
2326
import java.io.StringReader;
2427
import java.nio.file.Files;
2528
import java.nio.file.Path;
2629
import java.util.Comparator;
2730

31+
import org.junit.jupiter.api.Test;
32+
2833
import org.apache.jena.query.Dataset;
2934
import org.apache.jena.query.DatasetFactory;
3035
import org.apache.jena.query.QueryExecException;
@@ -42,8 +47,6 @@
4247
import org.apache.jena.system.Txn;
4348
import org.apache.jena.tdb2.assembler.VocabTDB2;
4449
import org.apache.jena.vocabulary.RDF;
45-
import org.junit.Assert;
46-
import org.junit.Test;
4750

4851
public class TestServiceEnhancerDatasetAssembler
4952
{
@@ -84,9 +87,9 @@ private void testAssemblerActual(String specStr) {
8487
Dataset dataset = DatasetFactory.assemble(spec.getResource("urn:example:root"));
8588
Context cxt = dataset.getContext();
8689

87-
Assert.assertEquals(20, cxt.getInt(ServiceEnhancerConstants.serviceBulkMaxBindingCount, -1));
88-
Assert.assertEquals(10, cxt.getInt(ServiceEnhancerConstants.serviceBulkBindingCount, -1));
89-
Assert.assertEquals(5, cxt.getInt(ServiceEnhancerConstants.serviceBulkMaxOutOfBandBindingCount, -1));
90+
assertEquals(20, cxt.getInt(ServiceEnhancerConstants.serviceBulkMaxBindingCount, -1));
91+
assertEquals(10, cxt.getInt(ServiceEnhancerConstants.serviceBulkBindingCount, -1));
92+
assertEquals(5, cxt.getInt(ServiceEnhancerConstants.serviceBulkMaxOutOfBandBindingCount, -1));
9093

9194
try (QueryExecution qe = QueryExecutionFactory.create(
9295
"SELECT * { BIND(<urn:example:x> AS ?x) SERVICE <loop:bulk+10:> { ?x ?y ?z } }", dataset)) {
@@ -95,7 +98,7 @@ private void testAssemblerActual(String specStr) {
9598
}
9699

97100
/** Test that calling cacheRm fails because enableMgmt has not been set to true in the context */
98-
@Test(expected = QueryExecException.class)
101+
@Test
99102
public void testAssemblerMgmtFail() {
100103
String specStr = String.join("\n",
101104
"PREFIX ja: <http://jena.hpl.hp.com/2005/11/Assembler#>",
@@ -107,10 +110,12 @@ public void testAssemblerMgmtFail() {
107110
Model spec = ModelFactory.createDefaultModel();
108111
RDFDataMgr.read(spec, new StringReader(specStr), null, Lang.TURTLE);
109112
Dataset dataset = DatasetFactory.assemble(spec.getResource("urn:example:root"));
110-
try (QueryExecution qe = QueryExecutionFactory.create(
111-
"PREFIX se: <http://jena.apache.org/service-enhancer#> SELECT se:cacheRm(0) { }", dataset)) {
112-
Assert.assertEquals(1, ResultSetFormatter.consume(qe.execSelect()));
113-
}
113+
assertThrows(QueryExecException.class, () -> {
114+
try (QueryExecution qe = QueryExecutionFactory.create(
115+
"PREFIX se: <http://jena.apache.org/service-enhancer#> SELECT se:cacheRm(0) { }", dataset)) {
116+
assertEquals(1, ResultSetFormatter.consume(qe.execSelect()));
117+
}
118+
});
114119
}
115120

116121
/** Test for cacheRm to execute successfully due to enableMgmt having been set to true in the context */
@@ -131,12 +136,12 @@ public void testAssemblerMgmtSuccess() {
131136
dataset.asDatasetGraph().getDefaultGraph().add(RDF.Nodes.type, RDF.Nodes.type, RDF.Nodes.Property);
132137
try (QueryExecution qe = QueryExecutionFactory.create(
133138
"SELECT * { SERVICE <cache:> { ?s ?p ?o } }", dataset)) {
134-
Assert.assertEquals(1, ResultSetFormatter.consume(qe.execSelect()));
139+
assertEquals(1, ResultSetFormatter.consume(qe.execSelect()));
135140
}
136141

137142
try (QueryExecution qe = QueryExecutionFactory.create(
138143
"PREFIX se: <http://jena.apache.org/service-enhancer#> SELECT se:cacheRm(0) { }", dataset)) {
139-
Assert.assertEquals(1, ResultSetFormatter.consume(qe.execSelect()));
144+
assertEquals(1, ResultSetFormatter.consume(qe.execSelect()));
140145
}
141146
}
142147

@@ -184,7 +189,7 @@ public void testAssemblerTdbUnionDefaultGraph() throws IOException {
184189
}
185190
});
186191

187-
Assert.assertEquals(4, actualRowCount);
192+
assertEquals(4, actualRowCount);
188193
} finally {
189194
Files.walk(tdb2TmpFolder)
190195
.sorted(Comparator.reverseOrder())

jena-serviceenhancer/src/test/java/org/apache/jena/sparql/service/enhancer/cache/TestAsyncClaimingCache.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,19 @@
1919

2020
import java.util.concurrent.TimeUnit;
2121

22+
import com.github.benmanes.caffeine.cache.Caffeine;
23+
import com.github.benmanes.caffeine.cache.Scheduler;
24+
25+
import org.junit.jupiter.api.Disabled;
26+
import org.junit.jupiter.api.Test;
27+
2228
import org.apache.jena.atlas.lib.Closeable;
2329
import org.apache.jena.sparql.service.enhancer.claimingcache.AsyncClaimingCacheImplCaffeine;
2430
import org.apache.jena.sparql.service.enhancer.claimingcache.RefFuture;
25-
import org.junit.Ignore;
26-
import org.junit.Test;
27-
28-
import com.github.benmanes.caffeine.cache.Caffeine;
29-
import com.github.benmanes.caffeine.cache.Scheduler;
3031

3132
public class TestAsyncClaimingCache {
3233
@Test
33-
@Ignore
34+
@Disabled
3435
public void test() throws InterruptedException {
3536

3637
int maxCacheSize = 10;

jena-serviceenhancer/src/test/java/org/apache/jena/sparql/service/enhancer/concurrent/TestIdPool.java

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,87 +18,92 @@
1818

1919
package org.apache.jena.sparql.service.enhancer.concurrent;
2020

21+
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertThrows;
23+
2124
import java.util.ArrayList;
2225
import java.util.Collections;
2326
import java.util.List;
2427
import java.util.ListIterator;
2528

29+
import org.junit.jupiter.api.Test;
30+
2631
import org.apache.jena.sparql.service.enhancer.util.IdPool;
27-
import org.junit.Assert;
28-
import org.junit.Test;
2932

3033
public class TestIdPool {
3134
@Test
3235
public void test01() {
3336
IdPool pool = new IdPool();
3437
int id0 = pool.acquire();
35-
Assert.assertEquals(0, id0);
38+
assertEquals(0, id0);
3639

3740
int id1 = pool.acquire();
38-
Assert.assertEquals(1, id1);
41+
assertEquals(1, id1);
3942

4043
int id2 = pool.acquire();
41-
Assert.assertEquals(2, id2);
44+
assertEquals(2, id2);
4245

4346
// We have not given back any ids to the pool so no id can be recycled.
44-
Assert.assertEquals(0, pool.getRecyclePoolSize());
47+
assertEquals(0, pool.getRecyclePoolSize());
4548

4649
// Give back and re-acquire ids starting from the lowest.
4750
// Giving back a single id and immediately re-acquiring a new one should
4851
// return the same id.
4952

5053
pool.giveBack(id0);
5154
id0 = pool.acquire();
52-
Assert.assertEquals(id0, 0);
55+
assertEquals(id0, 0);
5356

5457
pool.giveBack(id1);
5558
id1 = pool.acquire();
56-
Assert.assertEquals(id1, 1);
59+
assertEquals(id1, 1);
5760

5861
pool.giveBack(id2);
5962
id2 = pool.acquire();
60-
Assert.assertEquals(id2, 2);
63+
assertEquals(id2, 2);
6164

6265
// We have re-acquired all ids so there shouldn't be any recycled ones.
63-
Assert.assertEquals(0, pool.getRecyclePoolSize());
66+
assertEquals(0, pool.getRecyclePoolSize());
6467

6568
// Give back and re-acquire ids starting from the highest.
6669

6770
pool.giveBack(id2);
6871
id2 = pool.acquire();
69-
Assert.assertEquals(id2, 2);
72+
assertEquals(id2, 2);
7073

7174
pool.giveBack(id1);
7275
id1 = pool.acquire();
73-
Assert.assertEquals(id1, 1);
76+
assertEquals(id1, 1);
7477

7578
pool.giveBack(id0);
7679
id0 = pool.acquire();
77-
Assert.assertEquals(id0, 0);
80+
assertEquals(id0, 0);
7881

7982
// Giving back all but the highest ids should track those ids in the recycle pool
8083
pool.giveBack(id0);
8184
pool.giveBack(id1);
8285

83-
Assert.assertEquals(2, pool.getRecyclePoolSize());
86+
assertEquals(2, pool.getRecyclePoolSize());
8487

8588
// Giving back the highest id should now clear the recycle pool
8689
pool.giveBack(id2);
87-
Assert.assertEquals(0, pool.getRecyclePoolSize());
90+
assertEquals(0, pool.getRecyclePoolSize());
8891

8992
// Since all ids were given back then next acquired one should be 0 again
9093
id0 = pool.acquire();
91-
Assert.assertEquals(0, id0);
94+
assertEquals(0, id0);
9295
}
9396

94-
@Test(expected = IllegalArgumentException.class)
97+
@Test
9598
public void test_invalid_giveback_01() {
9699
IdPool pool = new IdPool();
97100
int id0 = pool.acquire();
98-
Assert.assertEquals(0, id0);
101+
assertEquals(0, id0);
99102

100103
pool.giveBack(id0);
101-
pool.giveBack(id0);
104+
assertThrows(IllegalArgumentException.class, () -> {
105+
pool.giveBack(id0);
106+
});
102107
}
103108

104109
@Test
@@ -130,10 +135,10 @@ public void test_random_01() {
130135
ids.forEach(pool::giveBack);
131136

132137
// Assert that the recycle pool is empty since all ids were given back
133-
Assert.assertEquals(0, pool.getRecyclePoolSize());
138+
assertEquals(0, pool.getRecyclePoolSize());
134139

135140
// Assert that the next id we get is 0
136141
int id0 = pool.acquire();
137-
Assert.assertEquals(0, id0);
142+
assertEquals(0, id0);
138143
}
139144
}

jena-serviceenhancer/src/test/java/org/apache/jena/sparql/service/enhancer/impl/AbstractTestServiceEnhancerResultSetLimits.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@
1818

1919
package org.apache.jena.sparql.service.enhancer.impl;
2020

21+
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
2123
import java.util.IdentityHashMap;
2224
import java.util.Map;
2325
import java.util.regex.Pattern;
2426

27+
import org.junit.jupiter.api.Test;
28+
2529
import org.apache.jena.query.Dataset;
2630
import org.apache.jena.query.DatasetFactory;
2731
import org.apache.jena.query.Query;
@@ -41,8 +45,6 @@
4145
import org.apache.jena.sparql.util.Context;
4246
import org.apache.jena.vocabulary.RDF;
4347
import org.apache.jena.vocabulary.RDFS;
44-
import org.junit.Assert;
45-
import org.junit.Test;
4648

4749
public abstract class AbstractTestServiceEnhancerResultSetLimits {
4850

@@ -84,7 +86,7 @@ public static Model createModel(int departments) {
8486
public void testLoop01_asc_limit1() {
8587
Model model = createModel(4);
8688
int rows = test(model, "SELECT * { { SELECT ?d { ?d a <urn:Department> } ORDER BY ASC(?d) } SERVICE <${mode}> { ?d <urn:hasEmployee> ?p }}", 1);
87-
Assert.assertEquals(4, rows);
89+
assertEquals(4, rows);
8890
}
8991

9092
@Test
@@ -94,7 +96,7 @@ public void testLoop01_asc_limit2() {
9496

9597
Model model = createModel(4);
9698
int rows = test(model, "SELECT * { { SELECT ?d { ?d a <urn:Department> } ORDER BY ASC(?d) } SERVICE <${mode}> { ?d <urn:hasEmployee> ?p }}", 2);
97-
Assert.assertEquals(7, rows);
99+
assertEquals(7, rows);
98100
}
99101

100102
/** Departments in descending order */
@@ -104,7 +106,7 @@ public void testLoop01_desc_limit1() {
104106
Model model = createModel(4);
105107
int rows = test(model, "SELECT * { { SELECT ?d { ?d a <urn:Department> } ORDER BY DESC(?d) } SERVICE <${mode}> { ?d <urn:hasEmployee> ?p }}", 1);
106108
//int rows = test(model, "SELECT * { SELECT ?d { ?d a <urn:Department> } ORDER BY DESC(?d) }", 1);
107-
Assert.assertEquals(4, rows);
109+
assertEquals(4, rows);
108110
}
109111

110112
@Test
@@ -114,7 +116,7 @@ public void testLoop01_desc_limit2() {
114116

115117
Model model = createModel(4);
116118
int rows = test(model, "SELECT * { { SELECT ?d { ?d a <urn:Department> } ORDER BY DESC(?d) } SERVICE <${mode}> { ?d <urn:hasEmployee> ?p }}", 2);
117-
Assert.assertEquals(7, rows);
119+
assertEquals(7, rows);
118120
}
119121

120122

@@ -127,7 +129,7 @@ public void testLoop01_asc_limit10() {
127129

128130
Model model = createModel(4);
129131
int rows = test(model, "SELECT * { { SELECT ?d { ?d a <urn:Department> } ORDER BY ASC(?d) } SERVICE <${mode}> { ?d <urn:hasEmployee> ?p }}", 10);
130-
Assert.assertEquals(10, rows);
132+
assertEquals(10, rows);
131133
}
132134

133135

@@ -172,7 +174,7 @@ public static void assertRowCount(int expectedRowCount, Dataset dataset, String
172174
rs.reset();
173175
ResultSetFormatter.outputAsJSON(rs);
174176
}
175-
Assert.assertEquals(expectedRowCount, actualSize);
177+
assertEquals(expectedRowCount, actualSize);
176178
}
177179

178180
public static int testCore(Dataset dataset, String queryStr, int hiddenLimit) {

0 commit comments

Comments
 (0)