Skip to content

Commit

Permalink
Merge pull request #289 from strangelookingnerd/migrate_to_junit5
Browse files Browse the repository at this point in the history
Migrate tests to JUnit5
  • Loading branch information
garydgregory authored Jan 24, 2025
2 parents c2765e5 + 49ef20d commit 48a8b1e
Show file tree
Hide file tree
Showing 44 changed files with 375 additions and 334 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
*/
package org.apache.commons.rdf.api;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* Abstract test class for the BlankNode interface.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
*/
package org.apache.commons.rdf.api;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

import java.util.ArrayList;
import java.util.HashSet;
Expand All @@ -36,9 +39,8 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

/**
* Test Dataset implementation
Expand Down Expand Up @@ -98,7 +100,7 @@ private void addAllQuads(final Dataset source, final Dataset target) {
// thread-safe

try (Stream<? extends Quad> stream = source.stream()) {
stream.unordered().sequential().forEach(t -> target.add(t));
stream.unordered().sequential().forEach(target::add);
}
}

Expand Down Expand Up @@ -150,7 +152,7 @@ private Dataset createDataset2() {
return g2;
}

@Before
@BeforeEach
public void createDatasetAndAdd() {
factory = createFactory();
dataset = factory.createDataset();
Expand Down Expand Up @@ -239,10 +241,10 @@ public String uniqueReference() {
}

private void notEquals(final BlankNodeOrIRI node1, final BlankNodeOrIRI node2) {
assertFalse(node1.equals(node2));
assertNotEquals(node1, node2);
// in which case we should be able to assume
// (as they are in the same dataset)
assertFalse(node1.ntriplesString().equals(node2.ntriplesString()));
assertNotEquals(node1.ntriplesString(), node2.ntriplesString());
}

@Test
Expand Down Expand Up @@ -330,7 +332,7 @@ public void testContains() throws Exception {

try (Stream<? extends Quad> stream = dataset.stream()) {
final Optional<? extends Quad> first = stream.skip(4).findFirst();
Assume.assumeTrue(first.isPresent());
assumeTrue(first.isPresent());
final Quad existingQuad = first.get();
assertTrue(dataset.contains(existingQuad));
}
Expand Down Expand Up @@ -391,7 +393,7 @@ public void testContainsLanguageTagsCaseInsensitiveTurkish() {
// If the below assertion fails, then the Turkish
// locale no longer have this peculiarity that
// we want to test.
Assume.assumeFalse("FI".toLowerCase().equals("fi"));
assumeFalse("FI".toLowerCase().equals("fi"));

// Below is pretty much the same as in
// containsLanguageTagsCaseInsensitive()
Expand Down Expand Up @@ -477,12 +479,12 @@ public void testGetGraph2() throws Exception {
@Test
public void testGetGraphNames() throws Exception {
final Set<BlankNodeOrIRI> names = dataset.getGraphNames().collect(Collectors.toSet());
assertTrue("Can't find graph name " + graph1, names.contains(graph1));
assertTrue("Found no quads in graph1", dataset.contains(Optional.of(graph1), null, null, null));
assertTrue(names.contains(graph1), "Can't find graph name " + graph1);
assertTrue(dataset.contains(Optional.of(graph1), null, null, null), "Found no quads in graph1");

final Optional<BlankNodeOrIRI> graphName2 = dataset.getGraphNames().filter(BlankNode.class::isInstance).findAny();
assertTrue("Could not find graph2-like BlankNode", graphName2.isPresent());
assertTrue("Found no quads in graph2", dataset.contains(graphName2, null, null, null));
assertTrue(graphName2.isPresent(), "Could not find graph2-like BlankNode");
assertTrue(dataset.contains(graphName2, null, null, null), "Found no quads in graph2");

// Some implementations like Virtuoso might have additional internal graphs,
// so we can't assume this:
Expand Down Expand Up @@ -514,7 +516,7 @@ public void testGetQuads() throws Exception {
}

// Check exact count
Assume.assumeNotNull(bnode1, bnode2, aliceName, bobName, secretClubName, companyName, bobNameQuad);
assumeTrue(bnode1 != null && bnode2 != null && aliceName != null && bobName != null && secretClubName != null && companyName != null && bobNameQuad != null);
assertEquals(10, quadCount);
}

Expand All @@ -524,23 +526,23 @@ public void testGetQuadsQuery() throws Exception {
try (Stream<? extends Quad> stream = dataset.stream(Optional.of(graph1), alice, null, null)) {
final long aliceCount = stream.count();
assertTrue(aliceCount > 0);
Assume.assumeNotNull(aliceName);
assumeTrue(aliceName != null);
assertEquals(3, aliceCount);
}

Assume.assumeNotNull(bnode1, bnode2, bobName, companyName, secretClubName);
assumeTrue(bnode1 != null && bnode2 != null && bobName != null && companyName != null && secretClubName != null);
try (Stream<? extends Quad> stream = dataset.stream(null, null, name, null)) {
assertEquals(4, stream.count());
}
Assume.assumeNotNull(bnode1);
assumeTrue(bnode1 != null);
try (Stream<? extends Quad> stream = dataset.stream(null, null, member, null)) {
assertEquals(3, stream.count());
}
}

@Test
public void testIterate() throws Exception {
Assume.assumeFalse(dataset.isEmpty());
assumeFalse(dataset.isEmpty());
final List<Quad> quads = new ArrayList<>();
for (final Quad t : dataset.iterate()) {
quads.add(t);
Expand Down Expand Up @@ -638,7 +640,7 @@ public void testRemove() throws Exception {
Quad otherQuad;
try (Stream<? extends Quad> stream = dataset.stream()) {
final Optional<? extends Quad> anyQuad = stream.findAny();
Assume.assumeTrue(anyQuad.isPresent());
assumeTrue(anyQuad.isPresent());
otherQuad = anyQuad.get();
}

Expand Down Expand Up @@ -747,7 +749,7 @@ public void testStreamLanguageTagsCaseInsensitive() {
*/
@Test
public void testWhyJavaStreamsMightNotTakeOverFromSparql() throws Exception {
Assume.assumeNotNull(bnode1, bnode2, secretClubName);
assumeTrue(bnode1 != null && bnode2 != null && secretClubName != null);
// Find a secret organizations
try (Stream<? extends Quad> stream = dataset.stream(null, null, knows, null)) {
assertEquals("\"The Secret Club\"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
*/
package org.apache.commons.rdf.api;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

import java.util.ArrayList;
import java.util.HashSet;
Expand All @@ -33,9 +36,8 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Stream;

import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

/**
* Test Graph implementation
Expand Down Expand Up @@ -92,7 +94,7 @@ private void addAllTriples(final Graph source, final Graph target) {
// thread-safe

try (Stream<? extends Triple> stream = source.stream()) {
stream.unordered().sequential().forEach(t -> target.add(t));
stream.unordered().sequential().forEach(target::add);
}
}

Expand Down Expand Up @@ -153,7 +155,7 @@ private Graph createGraph2() {
return g2;
}

@Before
@BeforeEach
public void createGraphAndAdd() {
factory = createFactory();
graph = factory.createGraph();
Expand Down Expand Up @@ -246,10 +248,10 @@ public String uniqueReference() {
}

private void notEquals(final BlankNodeOrIRI node1, final BlankNodeOrIRI node2) {
assertFalse(node1.equals(node2));
assertNotEquals(node1, node2);
// in which case we should be able to assume
// (as they are in the same graph)
assertFalse(node1.ntriplesString().equals(node2.ntriplesString()));
assertNotEquals(node1.ntriplesString(), node2.ntriplesString());
}

@Test
Expand Down Expand Up @@ -315,7 +317,7 @@ public void testAddBlankNodesFromMultipleGraphs() throws Exception {
assertFalse(g3.contains(b2Bob, hasChild, null));
assertFalse(g3.contains(b1Charlie, hasChild, null));
} catch (final UnsupportedOperationException ex) {
Assume.assumeNoException(ex);
assumeFalse(true);
}
}

Expand All @@ -336,7 +338,7 @@ public void testContains() throws Exception {

try (Stream<? extends Triple> stream = graph.stream()) {
final Optional<? extends Triple> first = stream.skip(4).findFirst();
Assume.assumeTrue(first.isPresent());
assumeTrue(first.isPresent());
final Triple existingTriple = first.get();
assertTrue(graph.contains(existingTriple));
}
Expand Down Expand Up @@ -404,7 +406,7 @@ public void testContainsLanguageTagsCaseInsensitiveTurkish() throws Exception {
// If the below assertion fails, then the Turkish
// locale no longer have this peculiarity that
// we want to test.
Assume.assumeFalse("FI".toLowerCase().equals("fi"));
assumeFalse("FI".toLowerCase().equals("fi"));

// Below is pretty much the same as in
// containsLanguageTagsCaseInsensitive()
Expand Down Expand Up @@ -452,7 +454,7 @@ public void testGetTriples() throws Exception {
}

// Check exact count
Assume.assumeNotNull(bnode1, bnode2, aliceName, bobName, secretClubName, companyName, bobNameTriple);
assumeTrue(bnode1 != null && bnode2 != null && aliceName != null && bobName != null && secretClubName != null && companyName != null && bobNameTriple != null);
assertEquals(8, tripleCount);
}

Expand All @@ -462,15 +464,15 @@ public void testGetTriplesQuery() throws Exception {
try (Stream<? extends Triple> stream = graph.stream(alice, null, null)) {
final long aliceCount = stream.count();
assertTrue(aliceCount > 0);
Assume.assumeNotNull(aliceName);
assumeTrue(aliceName != null);
assertEquals(3, aliceCount);
}

Assume.assumeNotNull(bnode1, bnode2, bobName, companyName, secretClubName);
assumeTrue(bnode1 != null && bnode2 != null && bobName != null && companyName != null && secretClubName != null);
try (Stream<? extends Triple> stream = graph.stream(null, name, null)) {
assertEquals(4, stream.count());
}
Assume.assumeNotNull(bnode1);
assumeTrue(bnode1 != null);
try (Stream<? extends Triple> stream = graph.stream(null, member, null)) {
assertEquals(3, stream.count());
}
Expand All @@ -479,7 +481,7 @@ public void testGetTriplesQuery() throws Exception {
@Test
public void testIterate() throws Exception {

Assume.assumeFalse(graph.isEmpty());
assumeFalse(graph.isEmpty());

final List<Triple> triples = new ArrayList<>();
for (final Triple t : graph.iterate()) {
Expand Down Expand Up @@ -552,7 +554,7 @@ public void testRemove() throws Exception {
Triple otherTriple;
try (Stream<? extends Triple> stream = graph.stream()) {
final Optional<? extends Triple> anyTriple = stream.findAny();
Assume.assumeTrue(anyTriple.isPresent());
assumeTrue(anyTriple.isPresent());
otherTriple = anyTriple.get();
}

Expand Down Expand Up @@ -599,7 +601,7 @@ public void testRemoveLanguageTagsCaseInsensitive() throws Exception {
@Test
public void testSize() throws Exception {
assertFalse(graph.isEmpty());
Assume.assumeNotNull(bnode1, bnode2, aliceName, bobName, secretClubName, companyName, bobNameTriple);
assumeTrue(bnode1 != null && bnode2 != null && aliceName != null && bobName != null && secretClubName != null && companyName != null && bobNameTriple != null);
// Can only reliably predict size if we could create all triples
assertEquals(8, graph.size());
}
Expand Down Expand Up @@ -648,7 +650,7 @@ public void testStreamLanguageTagsCaseInsensitive() throws Exception {
*/
@Test
public void testWhyJavaStreamsMightNotTakeOverFromSparql() throws Exception {
Assume.assumeNotNull(bnode1, bnode2, secretClubName);
assumeTrue(bnode1 != null && bnode2 != null && secretClubName != null);
// Find a secret organizations
try (Stream<? extends Triple> stream = graph.stream(null, knows, null)) {
assertEquals("\"The Secret Club\"",
Expand Down
Loading

0 comments on commit 48a8b1e

Please sign in to comment.