commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject commons-rdf git commit: Tests should manage resources with try-with-resources blocks.
Date Mon, 30 Oct 2017 17:28:43 GMT
Repository: commons-rdf
Updated Branches:
  refs/heads/master 7f8b02840 -> 7a0589214


Tests should manage resources with try-with-resources blocks.

Project: http://git-wip-us.apache.org/repos/asf/commons-rdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rdf/commit/7a058921
Tree: http://git-wip-us.apache.org/repos/asf/commons-rdf/tree/7a058921
Diff: http://git-wip-us.apache.org/repos/asf/commons-rdf/diff/7a058921

Branch: refs/heads/master
Commit: 7a05892144434e3f8b8dc671171493038aed4384
Parents: 7f8b028
Author: Gary Gregory <ggregory@apache.org>
Authored: Mon Oct 30 11:28:40 2017 -0600
Committer: Gary Gregory <ggregory@apache.org>
Committed: Mon Oct 30 11:28:40 2017 -0600

----------------------------------------------------------------------
 .../commons/rdf/api/AbstractDatasetTest.java    | 69 ++++++++--------
 .../commons/rdf/api/AbstractGraphTest.java      | 86 ++++++++++----------
 2 files changed, 78 insertions(+), 77 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/7a058921/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/AbstractDatasetTest.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/AbstractDatasetTest.java
b/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/AbstractDatasetTest.java
index 0bea504..d6363c2 100644
--- a/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/AbstractDatasetTest.java
+++ b/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/AbstractDatasetTest.java
@@ -344,13 +344,12 @@ public abstract class AbstractDatasetTest {
     }
 
     @Test
-    public void addBlankNodesFromMultipleDatasets() {
-            // Create two separate Dataset instances
-            final Dataset g1 = createDataset1();
-            final Dataset g2 = createDataset2();
+    public void addBlankNodesFromMultipleDatasets() throws Exception {
+        // Create two separate Dataset instances
+        try (final Dataset g1 = createDataset1();
+                final Dataset g2 = createDataset2();
+                final Dataset g3 = factory.createDataset()) {
 
-            // and add them to a new Dataset g3
-            final Dataset g3 = factory.createDataset();
             addAllQuads(g1, g3);
             addAllQuads(g2, g3);
 
@@ -408,6 +407,7 @@ public abstract class AbstractDatasetTest {
             // and these don't have any children (as far as we know)
             assertFalse(g3.contains(null, b2Bob, hasChild, null));
             assertFalse(g3.contains(null, b1Charlie, hasChild, null));
+        }
     }
 
     private void notEquals(final BlankNodeOrIRI node1, final BlankNodeOrIRI node2) {
@@ -537,37 +537,40 @@ public abstract class AbstractDatasetTest {
 
     @Test
     public void getGraph() throws Exception {
-        final Graph defaultGraph = dataset.getGraph();
-        // TODO: Can we assume the default graph was empty before our new triples?
-        assertEquals(2, defaultGraph.size());
-        assertTrue(defaultGraph.contains(alice, isPrimaryTopicOf, graph1));
-        // NOTE: graph2 is a BlankNode
-        assertTrue(defaultGraph.contains(bob, isPrimaryTopicOf, null));
+        try (final Graph defaultGraph = dataset.getGraph()) {
+            // TODO: Can we assume the default graph was empty before our new triples?
+            assertEquals(2, defaultGraph.size());
+            assertTrue(defaultGraph.contains(alice, isPrimaryTopicOf, graph1));
+            // NOTE: graph2 is a BlankNode
+            assertTrue(defaultGraph.contains(bob, isPrimaryTopicOf, null));
+        }
     }
 
 
     @Test
     public void getGraphNull() throws Exception {
         // Default graph should be present
-        final Graph defaultGraph = dataset.getGraph(null).get();
-        // TODO: Can we assume the default graph was empty before our new triples?
-        assertEquals(2, defaultGraph.size());
-        assertTrue(defaultGraph.contains(alice, isPrimaryTopicOf, graph1));
-        // NOTE: wildcard as graph2 is a (potentially mapped) BlankNode
-        assertTrue(defaultGraph.contains(bob, isPrimaryTopicOf, null));
+        try (final Graph defaultGraph = dataset.getGraph(null).get()) {
+            // TODO: Can we assume the default graph was empty before our new triples?
+            assertEquals(2, defaultGraph.size());
+            assertTrue(defaultGraph.contains(alice, isPrimaryTopicOf, graph1));
+            // NOTE: wildcard as graph2 is a (potentially mapped) BlankNode
+            assertTrue(defaultGraph.contains(bob, isPrimaryTopicOf, null));
+        }
     }
 
 
     @Test
     public void getGraph1() throws Exception {
         // graph1 should be present
-        final Graph g1 = dataset.getGraph(graph1).get();
-        assertEquals(4, g1.size());
+        try (final Graph g1 = dataset.getGraph(graph1).get()) {
+            assertEquals(4, g1.size());
 
-        assertTrue(g1.contains(alice, name, aliceName));
-        assertTrue(g1.contains(alice, knows, bob));
-        assertTrue(g1.contains(alice, member, null));
-        assertTrue(g1.contains(null, name, secretClubName));
+            assertTrue(g1.contains(alice, name, aliceName));
+            assertTrue(g1.contains(alice, knows, bob));
+            assertTrue(g1.contains(alice, member, null));
+            assertTrue(g1.contains(null, name, secretClubName));
+        }
     }
 
     @Test
@@ -577,17 +580,17 @@ public abstract class AbstractDatasetTest {
         final BlankNodeOrIRI graph2Name = (BlankNodeOrIRI) dataset.stream(Optional.empty(),
bob, isPrimaryTopicOf, null)
                 .map(Quad::getObject).findAny().get();
 
-        final Graph g2 = dataset.getGraph(graph2Name).get();
-        assertEquals(4, g2.size());
-        final Triple bobNameTriple = bobNameQuad.asTriple();
-        assertTrue(g2.contains(bobNameTriple));
-        assertTrue(g2.contains(bob, member, bnode1));
-        assertTrue(g2.contains(bob, member, bnode2));
-        assertFalse(g2.contains(bnode1, name, secretClubName));
-        assertTrue(g2.contains(bnode2, name, companyName));
+        try (final Graph g2 = dataset.getGraph(graph2Name).get()) {
+            assertEquals(4, g2.size());
+            final Triple bobNameTriple = bobNameQuad.asTriple();
+            assertTrue(g2.contains(bobNameTriple));
+            assertTrue(g2.contains(bob, member, bnode1));
+            assertTrue(g2.contains(bob, member, bnode2));
+            assertFalse(g2.contains(bnode1, name, secretClubName));
+            assertTrue(g2.contains(bnode2, name, companyName));
+        }
     }
 
-
     @Test
     public void containsLanguageTagsCaseInsensitive() {
         // COMMONSRDF-51: Ensure we can add/contains/remove with any casing

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/7a058921/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
b/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
index b74a1c5..afdd25f 100644
--- a/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
+++ b/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
@@ -316,15 +316,11 @@ public abstract class AbstractGraphTest {
     }
 
     @Test
-    public void addBlankNodesFromMultipleGraphs() {
+    public void addBlankNodesFromMultipleGraphs() throws Exception {
 
-        try {
-            // Create two separate Graph instances
-            final Graph g1 = createGraph1();
-            final Graph g2 = createGraph2();
-
-            // and add them to a new Graph g3
-            final Graph g3 = factory.createGraph();
+        // Create two separate Graph instances
+        // and add them to a new Graph g3
+        try (final Graph g1 = createGraph1(); final Graph g2 = createGraph2(); final Graph
g3 = factory.createGraph()) {
             addAllTriples(g1, g3);
             addAllTriples(g2, g3);
 
@@ -387,7 +383,7 @@ public abstract class AbstractGraphTest {
     }
 
     @Test
-    public void containsLanguageTagsCaseInsensitive() {
+    public void containsLanguageTagsCaseInsensitive() throws Exception {
         // COMMONSRDF-51: Ensure we can add/contains/remove with any casing
         // of literal language tag
         final Literal lower = factory.createLiteral("Hello", "en-gb");
@@ -397,22 +393,23 @@ public abstract class AbstractGraphTest {
         final IRI example1 = factory.createIRI("http://example.com/s1");
         final IRI greeting = factory.createIRI("http://example.com/greeting");
 
-        final Graph graph = factory.createGraph();
-        graph.add(example1, greeting, upper);
+        try (final Graph graph = factory.createGraph()) {
+            graph.add(example1, greeting, upper);
 
-        // any kind of Triple should match
-        assertTrue(graph.contains(factory.createTriple(example1, greeting, upper)));
-        assertTrue(graph.contains(factory.createTriple(example1, greeting, lower)));
-        assertTrue(graph.contains(factory.createTriple(example1, greeting, mixed)));
+            // any kind of Triple should match
+            assertTrue(graph.contains(factory.createTriple(example1, greeting, upper)));
+            assertTrue(graph.contains(factory.createTriple(example1, greeting, lower)));
+            assertTrue(graph.contains(factory.createTriple(example1, greeting, mixed)));
 
-        // or as patterns
-        assertTrue(graph.contains(null, null, upper));
-        assertTrue(graph.contains(null, null, lower));
-        assertTrue(graph.contains(null, null, mixed));
+            // or as patterns
+            assertTrue(graph.contains(null, null, upper));
+            assertTrue(graph.contains(null, null, lower));
+            assertTrue(graph.contains(null, null, mixed));
+        }
     }
 
     @Test
-    public void containsLanguageTagsCaseInsensitiveTurkish() {
+    public void containsLanguageTagsCaseInsensitiveTurkish() throws Exception {
         // COMMONSRDF-51: Special test for Turkish issue where
         // "i".toLowerCase() != "i"
         // See also:
@@ -420,12 +417,11 @@ public abstract class AbstractGraphTest {
 
         // This is similar to the test in AbstractRDFTest, but on a graph
         final Locale defaultLocale = Locale.getDefault();
-        try {
+        try (final Graph g = factory.createGraph()) {
             Locale.setDefault(Locale.ROOT);
             final Literal lowerROOT = factory.createLiteral("moi", "fi");
             final Literal upperROOT = factory.createLiteral("moi", "FI");
             final Literal mixedROOT = factory.createLiteral("moi", "fI");
-            final Graph g = factory.createGraph();
             final IRI exampleROOT = factory.createIRI("http://example.com/s1");
             final IRI greeting = factory.createIRI("http://example.com/greeting");
             g.add(exampleROOT, greeting, mixedROOT);
@@ -472,7 +468,7 @@ public abstract class AbstractGraphTest {
 
 
     @Test
-    public void removeLanguageTagsCaseInsensitive() {
+    public void removeLanguageTagsCaseInsensitive() throws Exception {
         // COMMONSRDF-51: Ensure we can remove with any casing
         // of literal language tag
         final Literal lower = factory.createLiteral("Hello", "en-gb");
@@ -482,20 +478,21 @@ public abstract class AbstractGraphTest {
         final IRI example1 = factory.createIRI("http://example.com/s1");
         final IRI greeting = factory.createIRI("http://example.com/greeting");
 
-        final Graph graph = factory.createGraph();
-        graph.add(example1, greeting, upper);
+        try (final Graph graph = factory.createGraph()) {
+            graph.add(example1, greeting, upper);
 
-        // Remove should also honour any case
-        graph.remove(example1, null, mixed);
-        assertFalse(graph.contains(null, greeting, null));
+            // Remove should also honour any case
+            graph.remove(example1, null, mixed);
+            assertFalse(graph.contains(null, greeting, null));
 
-        graph.add(example1, greeting, lower);
-        graph.remove(example1, null, upper);
+            graph.add(example1, greeting, lower);
+            graph.remove(example1, null, upper);
 
-        // Check with Triple
-        graph.add(factory.createTriple(example1, greeting, mixed));
-        graph.remove(factory.createTriple(example1, greeting, upper));
-        assertFalse(graph.contains(null, greeting, null));
+            // Check with Triple
+            graph.add(factory.createTriple(example1, greeting, mixed));
+            graph.remove(factory.createTriple(example1, greeting, upper));
+            assertFalse(graph.contains(null, greeting, null));
+        }
     }
 
     private static Optional<? extends Triple> closableFindAny(final Stream<? extends
Triple> stream) {
@@ -505,7 +502,7 @@ public abstract class AbstractGraphTest {
     }
 
     @Test
-    public void streamLanguageTagsCaseInsensitive() {
+    public void streamLanguageTagsCaseInsensitive() throws Exception {
         // COMMONSRDF-51: Ensure we can add/contains/remove with any casing
         // of literal language tag
         final Literal lower = factory.createLiteral("Hello", "en-gb");
@@ -515,17 +512,18 @@ public abstract class AbstractGraphTest {
         final IRI example1 = factory.createIRI("http://example.com/s1");
         final IRI greeting = factory.createIRI("http://example.com/greeting");
 
-        final Graph graph = factory.createGraph();
-        graph.add(example1, greeting, upper);
+        try (final Graph graph = factory.createGraph()) {
+            graph.add(example1, greeting, upper);
 
-        // or as patterns
-        assertTrue(closableFindAny(graph.stream(null, null, upper)).isPresent());
-        assertTrue(closableFindAny(graph.stream(null, null, lower)).isPresent());
-        assertTrue(closableFindAny(graph.stream(null, null, mixed)).isPresent());
+            // or as patterns
+            assertTrue(closableFindAny(graph.stream(null, null, upper)).isPresent());
+            assertTrue(closableFindAny(graph.stream(null, null, lower)).isPresent());
+            assertTrue(closableFindAny(graph.stream(null, null, mixed)).isPresent());
 
-        // Check the triples returned equal a new triple
-        final Triple t = closableFindAny(graph.stream(null, null, lower)).get();
-        assertEquals(t, factory.createTriple(example1, greeting, mixed));
+            // Check the triples returned equal a new triple
+            final Triple t = closableFindAny(graph.stream(null, null, lower)).get();
+            assertEquals(t, factory.createTriple(example1, greeting, mixed));
+        }
     }
 
     private void notEquals(final BlankNodeOrIRI node1, final BlankNodeOrIRI node2) {


Mime
View raw message