commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [1/3] incubator-commonsrdf git commit: Test default methods
Date Thu, 03 Nov 2016 13:11:34 GMT
Repository: incubator-commonsrdf
Updated Branches:
  refs/heads/master 0ae95c3b6 -> 7e700cb37


Test default methods

also adds a couple of Dummy implementations for that purpose


Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/ce0e9abb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/ce0e9abb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/ce0e9abb

Branch: refs/heads/master
Commit: ce0e9abba7f75c69c43c885e980ed382dfd0bea5
Parents: 0ae95c3
Author: Stian Soiland-Reyes <stain@apache.org>
Authored: Thu Nov 3 09:55:30 2016 +0000
Committer: Stian Soiland-Reyes <stain@apache.org>
Committed: Thu Nov 3 12:59:29 2016 +0000

----------------------------------------------------------------------
 .../org/apache/commons/rdf/api/Dataset.java     |   7 ++
 .../java/org/apache/commons/rdf/api/Graph.java  |   7 ++
 .../apache/commons/rdf/api/AbstractRDFTest.java |   1 -
 .../commons/rdf/api/DefaultDatasetTest.java     |  58 ++++++++++
 .../commons/rdf/api/DefaultGraphTest.java       |  78 +++++++++++++
 .../apache/commons/rdf/api/DefaultQuadTest.java |  36 ++++++
 .../rdf/api/DefaultRDFTermFactoryTest.java      |  63 +++++++++++
 .../apache/commons/rdf/api/DummyDataset.java    | 110 +++++++++++++++++++
 .../commons/rdf/api/DummyDatasetTest.java       | 101 +++++++++++++++++
 .../org/apache/commons/rdf/api/DummyGraph.java  |  85 ++++++++++++++
 .../apache/commons/rdf/api/DummyGraphTest.java  |  84 ++++++++++++++
 .../org/apache/commons/rdf/api/DummyIRI.java    |  47 ++++++++
 .../apache/commons/rdf/api/DummyIRITest.java    |  56 ++++++++++
 .../org/apache/commons/rdf/api/DummyQuad.java   |  63 +++++++++++
 .../apache/commons/rdf/api/DummyQuadTest.java   |  58 ++++++++++
 .../org/apache/commons/rdf/api/DummyTriple.java |  57 ++++++++++
 .../apache/commons/rdf/api/DummyTripleTest.java |  53 +++++++++
 17 files changed, 963 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ce0e9abb/api/src/main/java/org/apache/commons/rdf/api/Dataset.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Dataset.java b/api/src/main/java/org/apache/commons/rdf/api/Dataset.java
index 54721fd..fec4239 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Dataset.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Dataset.java
@@ -272,6 +272,9 @@ public interface Dataset extends AutoCloseable, GraphLike<Quad>
{
      * The {@link Iterable#iterator()} must only be called once, that is the
      * Iterable must only be iterated over once. A {@link IllegalStateException}
      * may be thrown on attempt to reuse the Iterable.
+     * <p>
+     * The default implementation of this method will call {@link #stream()} to
+     * return its {@link Stream#iterator()}.
      *
      * @return A {@link Iterable} that returns {@link Iterator} over all of the
      *         quads in the dataset
@@ -313,6 +316,10 @@ public interface Dataset extends AutoCloseable, GraphLike<Quad>
{
      * The {@link Iterable#iterator()} must only be called once, that is the
      * Iterable must only be iterated over once. A {@link IllegalStateException}
      * may be thrown on attempt to reuse the Iterable.
+     * <p>
+     * The default implementation of this method will call
+     * {@link #stream(Optional, BlankNodeOrIRI, IRI, RDFTerm)} to return its
+     * {@link Stream#iterator()}.
      *
      * @param graphName
      *            The graph the quad belongs to, wrapped as an {@link Optional}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ce0e9abb/api/src/main/java/org/apache/commons/rdf/api/Graph.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Graph.java b/api/src/main/java/org/apache/commons/rdf/api/Graph.java
index bd6d175..8524403 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Graph.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Graph.java
@@ -221,6 +221,9 @@ public interface Graph extends AutoCloseable, GraphLike<Triple>
{
      * The {@link Iterable#iterator()} must only be called once, that is the
      * Iterable must only be iterated over once. A {@link IllegalStateException}
      * may be thrown on attempt to reuse the Iterable.
+     * <p>
+     * The default implementation of this method will call {@link #stream()} to return
+     * its {@link Stream#iterator()}.
      *
      * @return A {@link Iterable} that returns {@link Iterator} over all of the
      *         triples in the graph
@@ -261,6 +264,10 @@ public interface Graph extends AutoCloseable, GraphLike<Triple>
{
      * The {@link Iterable#iterator()} must only be called once, that is the
      * Iterable must only be iterated over once. A {@link IllegalStateException}
      * may be thrown on attempt to reuse the Iterable.
+     * <p>
+     * The default implementation of this method will call
+     * {@link #stream(BlankNodeOrIRI, IRI, RDFTerm)} to return its
+     * {@link Stream#iterator()}.
      *
      * @param subject
      *            The triple subject (null is a wildcard)

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ce0e9abb/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTest.java b/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTest.java
index e58ede6..bd3865a 100644
--- a/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTest.java
+++ b/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTest.java
@@ -24,7 +24,6 @@ import static org.junit.Assert.assertNotSame;
 
 import java.util.Objects;
 
-import org.junit.Assume;
 import org.junit.Before;
 import org.junit.Test;
 

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ce0e9abb/api/src/test/java/org/apache/commons/rdf/api/DefaultDatasetTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/DefaultDatasetTest.java b/api/src/test/java/org/apache/commons/rdf/api/DefaultDatasetTest.java
new file mode 100644
index 0000000..22262da
--- /dev/null
+++ b/api/src/test/java/org/apache/commons/rdf/api/DefaultDatasetTest.java
@@ -0,0 +1,58 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rdf.api;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class DefaultDatasetTest {
+    
+    DummyDataset dataset = new DummyDataset();
+    
+    @Test
+    public void close() throws Exception {
+        dataset.close(); // no-op
+    }
+    
+    @Test
+    public void defaultIterate() throws Exception {
+        assertFalse(dataset.streamCalled);
+        assertFalse(dataset.filteredStreamCalled);
+        for (Quad t : dataset.iterate()) {
+            assertEquals(t, new DummyQuad());
+        }
+        assertTrue(dataset.streamCalled);
+        assertFalse(dataset.filteredStreamCalled);
+    }
+    
+    @Test
+    public void defaultFilteredIterate() throws Exception {
+        assertFalse(dataset.streamCalled);
+        assertFalse(dataset.filteredStreamCalled);
+        for (Quad t : dataset.iterate(null, null, new DummyIRI(2), null)) {
+            assertEquals(t, new DummyQuad());
+        }
+        assertTrue(dataset.filteredStreamCalled);
+        assertFalse(dataset.streamCalled);
+    }
+    
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ce0e9abb/api/src/test/java/org/apache/commons/rdf/api/DefaultGraphTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/DefaultGraphTest.java b/api/src/test/java/org/apache/commons/rdf/api/DefaultGraphTest.java
new file mode 100644
index 0000000..14a32f0
--- /dev/null
+++ b/api/src/test/java/org/apache/commons/rdf/api/DefaultGraphTest.java
@@ -0,0 +1,78 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rdf.api;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class DefaultGraphTest {
+    
+    DummyGraph graph = new DummyGraph();
+    
+    @Test
+    public void close() throws Exception {
+        graph.close(); // no-op
+    }
+    
+    @SuppressWarnings("deprecation")
+    @Test
+    public void defaultGetTriples() throws Exception {
+        assertFalse(graph.streamCalled);
+        assertFalse(graph.filteredStreamCalled);
+        assertEquals(1L, graph.getTriples().count());        
+        assertTrue(graph.streamCalled);
+        assertFalse(graph.filteredStreamCalled);        
+    }
+
+    @SuppressWarnings("deprecation")
+    @Test
+    public void defaultGetTriplesFiltered() throws Exception {
+        assertFalse(graph.streamCalled);
+        assertFalse(graph.filteredStreamCalled);
+        assertEquals(1L, graph.getTriples(null,null,null).count());
+        assertFalse(graph.streamCalled);
+        assertTrue(graph.filteredStreamCalled);
+        // Ensure arguments are passed on to graph.stream(s,p,o);
+        assertEquals(0L, graph.getTriples(new DummyIRI(0),null,null).count());
+    }
+    
+    @Test
+    public void defaultIterate() throws Exception {
+        assertFalse(graph.streamCalled);
+        assertFalse(graph.filteredStreamCalled);
+        for (Triple t : graph.iterate()) {
+            assertEquals(t, new DummyTriple());
+        }
+        assertTrue(graph.streamCalled);
+        assertFalse(graph.filteredStreamCalled);
+    }
+    
+    @Test
+    public void defaultFilteredIterate() throws Exception {
+        assertFalse(graph.streamCalled);
+        assertFalse(graph.filteredStreamCalled);
+        for (Triple t : graph.iterate(null, new DummyIRI(2), null)) {
+            assertEquals(t, new DummyTriple());
+        }
+        assertTrue(graph.filteredStreamCalled);
+        assertFalse(graph.streamCalled);
+    }
+    
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ce0e9abb/api/src/test/java/org/apache/commons/rdf/api/DefaultQuadTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/DefaultQuadTest.java b/api/src/test/java/org/apache/commons/rdf/api/DefaultQuadTest.java
new file mode 100644
index 0000000..9d563cd
--- /dev/null
+++ b/api/src/test/java/org/apache/commons/rdf/api/DefaultQuadTest.java
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rdf.api;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class DefaultQuadTest {
+    @Test
+    public void asQuad() throws Exception {
+        Quad q = new DummyQuad();
+        Triple t = q.asTriple();
+        // FIXME: This would not catch if asTriple() accidentally mixed up s/p/o
+        // as they are here all the same
+        assertEquals(new DummyIRI(1), t.getSubject());
+        assertEquals(new DummyIRI(2), t.getPredicate());
+        assertEquals(new DummyIRI(3), t.getObject());
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ce0e9abb/api/src/test/java/org/apache/commons/rdf/api/DefaultRDFTermFactoryTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/DefaultRDFTermFactoryTest.java b/api/src/test/java/org/apache/commons/rdf/api/DefaultRDFTermFactoryTest.java
new file mode 100644
index 0000000..7a48464
--- /dev/null
+++ b/api/src/test/java/org/apache/commons/rdf/api/DefaultRDFTermFactoryTest.java
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rdf.api;
+
+import org.junit.Test;
+
+/**
+ * Test that all {@link RDFTermFactory} default methods throw
+ * {@link UnsupportedOperationException}.
+ */
+@SuppressWarnings("deprecation")
+public class DefaultRDFTermFactoryTest {
+    // All methods in RDFTermFactory has a default implementation
+    RDFTermFactory factory = new RDFTermFactory() {};
+    
+    @Test(expected=UnsupportedOperationException.class)
+    public void createBlankNode() throws Exception {
+        factory.createBlankNode();
+    }
+    @Test(expected=UnsupportedOperationException.class)
+    public void createBlankNodeName() throws Exception {
+        factory.createBlankNode("fred");
+    }
+    @Test(expected=UnsupportedOperationException.class)
+    public void createGraph() throws Exception {
+        factory.createGraph();
+    }
+    @Test(expected=UnsupportedOperationException.class)
+    public void createIRI() throws Exception {
+        factory.createIRI("http://example.com/");
+    }
+    @Test(expected=UnsupportedOperationException.class)
+    public void createLiteral() throws Exception {
+        factory.createLiteral("Alice");
+    }
+    @Test(expected=UnsupportedOperationException.class)
+    public void createLiteralLang() throws Exception {
+        factory.createLiteral("Alice", "en");
+    }
+    @Test(expected=UnsupportedOperationException.class)
+    public void createLiteralTyped() throws Exception {
+        factory.createLiteral("Alice", new DummyIRI(0));
+    }
+    @Test(expected=UnsupportedOperationException.class)
+    public void createTriple() throws Exception {
+        factory.createTriple(new DummyIRI(1), new DummyIRI(2), new DummyIRI(3));
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ce0e9abb/api/src/test/java/org/apache/commons/rdf/api/DummyDataset.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/DummyDataset.java b/api/src/test/java/org/apache/commons/rdf/api/DummyDataset.java
new file mode 100644
index 0000000..0cfbc69
--- /dev/null
+++ b/api/src/test/java/org/apache/commons/rdf/api/DummyDataset.java
@@ -0,0 +1,110 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rdf.api;
+
+import java.util.Arrays;
+import java.util.Optional;
+import java.util.stream.Stream;
+
+class DummyDataset implements Dataset {
+    
+    boolean streamCalled = false;
+    boolean filteredStreamCalled;
+    
+    @Override
+    public void add(Quad Quad) {
+        if (! contains(Quad)) {
+            throw new IllegalStateException("DummyDataset can't be modified");
+        }
+    }
+    
+    @Override
+    public void add(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm
object) {
+        if (! contains(Optional.ofNullable(graphName), subject, predicate, object)) { 
+            throw new IllegalStateException("DummyDataset can't be modified");
+        }
+    }
+    
+    @Override
+    public boolean contains(Quad Quad) {
+        return Quad.equals(new DummyQuad());
+    }
+    
+    @Override
+    public boolean contains(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject,
IRI predicate, RDFTerm object) {        
+        return (graphName == null || ! graphName.isPresent()) &&
+                (subject == null || subject.equals(new DummyIRI(1))) && 
+                (predicate == null || predicate.equals(new DummyIRI(2))) && 
+                (object == null || object.equals(new DummyIRI(3)));
+    }
+    @Override
+    public void remove(Quad Quad) {
+        if (contains(Quad)) {
+            throw new IllegalStateException("DummyDataset can't be modified");
+        }
+    }
+    @Override
+    public void remove(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject,
IRI predicate, RDFTerm object) {
+        if (contains(graphName, subject, predicate, object)) {
+            throw new IllegalStateException("DummyDataset can't be modified");
+        }
+    }
+    @Override
+    public void clear() {
+        throw new IllegalStateException("DummyDataset can't be modified");
+    }
+    @Override
+    public long size() {
+        return 1;
+    }
+    @Override
+    public Stream<? extends Quad> stream() {
+        streamCalled = true;
+        return Arrays.asList(new DummyQuad()).stream();
+    }
+
+    @Override
+    public Stream<? extends Quad> stream(Optional<BlankNodeOrIRI> graphName,
BlankNodeOrIRI subject, IRI predicate,
+            RDFTerm object) {
+        filteredStreamCalled = true;
+        if (contains(graphName, subject, predicate, object)) { 
+            return Stream.of(new DummyQuad());
+        } else {
+            return Stream.empty();
+        }
+    }
+
+    @Override
+    public Graph getGraph() {
+        return new DummyGraph();
+    }
+
+    @Override
+    public Optional<Graph> getGraph(BlankNodeOrIRI graphName) {
+        if (graphName == null) { 
+            return Optional.of(getGraph());
+        } else {
+            return Optional.empty();
+        }
+    }
+
+    @Override
+    public Stream<BlankNodeOrIRI> getGraphNames() {
+        return Stream.empty();
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ce0e9abb/api/src/test/java/org/apache/commons/rdf/api/DummyDatasetTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/DummyDatasetTest.java b/api/src/test/java/org/apache/commons/rdf/api/DummyDatasetTest.java
new file mode 100644
index 0000000..cf0c6e2
--- /dev/null
+++ b/api/src/test/java/org/apache/commons/rdf/api/DummyDatasetTest.java
@@ -0,0 +1,101 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rdf.api;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class DummyDatasetTest {
+    Dataset dataset = new DummyDataset();
+
+    @Test
+    public void add() throws Exception {
+        dataset.add(new DummyQuad());
+    }
+
+    @Test
+    public void addSPO() throws Exception {
+        dataset.add(null, new DummyIRI(1), new DummyIRI(2), new DummyIRI(3));
+    }
+
+    @Test
+    public void contains() throws Exception {
+        assertTrue(dataset.contains(new DummyQuad()));
+    }
+
+    @Test
+    public void containsSPO() throws Exception {
+        assertTrue(dataset.contains(null, null, null, null));
+        assertTrue(dataset.contains(null, new DummyIRI(1), new DummyIRI(2), new DummyIRI(3)));
+        assertFalse(dataset.contains(null, new DummyIRI(0), new DummyIRI(0), new DummyIRI(0)));
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void clearNotSupported() throws Exception {
+        dataset.clear();
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void remove() throws Exception {
+        dataset.remove(new DummyQuad());
+    }
+
+    @Test
+    public void removeSPO() throws Exception {
+        dataset.remove(null, new DummyIRI(0), new DummyIRI(0), new DummyIRI(0));
+    }
+
+    @Test
+    public void size() throws Exception {
+        assertEquals(1, dataset.size());
+    }
+
+    @Test
+    public void stream() throws Exception {
+        assertEquals(new DummyQuad(), dataset.stream().findAny().get());
+    }
+
+    @Test
+    public void streamFiltered() throws Exception {
+        assertEquals(new DummyQuad(), dataset.stream(null, null, null, null).findAny().get());
+        assertEquals(new DummyQuad(),
+                dataset.stream(null, new DummyIRI(1), new DummyIRI(2), new DummyIRI(3)).findAny().get());
+        assertFalse(dataset.stream(null, new DummyIRI(0), new DummyIRI(0), new DummyIRI(0)).findAny().isPresent());
+    }
+
+    @Test
+    public void getGraph() throws Exception {
+        assertTrue(dataset.getGraph() instanceof DummyGraph);
+    }
+    
+    @Test
+    public void getGraphNull() throws Exception {
+        assertTrue(dataset.getGraph(null).get() instanceof DummyGraph);
+    }
+
+    @Test
+    public void getGraphNamed() throws Exception {
+        assertFalse(dataset.getGraph(new DummyIRI(0)).isPresent());
+    }
+    
+    @Test
+    public void getGraphNames() throws Exception {
+        assertFalse(dataset.getGraphNames().findAny().isPresent());
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ce0e9abb/api/src/test/java/org/apache/commons/rdf/api/DummyGraph.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/DummyGraph.java b/api/src/test/java/org/apache/commons/rdf/api/DummyGraph.java
new file mode 100644
index 0000000..d33ffa9
--- /dev/null
+++ b/api/src/test/java/org/apache/commons/rdf/api/DummyGraph.java
@@ -0,0 +1,85 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rdf.api;
+
+import java.util.Arrays;
+import java.util.stream.Stream;
+
+class DummyGraph implements Graph {
+    
+    boolean streamCalled = false;
+    boolean filteredStreamCalled;
+    
+    @Override
+    public void add(Triple triple) {
+        if (! contains(triple)) {
+            throw new IllegalStateException("DummyGraph can't be modified");
+        }
+    }
+    @Override
+    public void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+        if (! contains(subject, predicate, object)) { 
+            throw new IllegalStateException("DummyGraph can't be modified");
+        }
+    }
+    @Override
+    public boolean contains(Triple triple) {
+        return triple.equals(new DummyTriple());
+    }
+    @Override
+    public boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+        return (subject == null || subject.equals(new DummyIRI(1))) && 
+                (predicate == null || predicate.equals(new DummyIRI(2))) && 
+                (object == null || object.equals(new DummyIRI(3)));
+    }
+    @Override
+    public void remove(Triple triple) {
+        if (contains(triple)) {
+            throw new IllegalStateException("DummyGraph can't be modified");
+        }
+    }
+    @Override
+    public void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+        if (contains(subject, predicate, object)) {
+            throw new IllegalStateException("DummyGraph can't be modified");
+        }
+    }
+    @Override
+    public void clear() {
+        throw new IllegalStateException("DummyGraph can't be modified");
+    }
+    @Override
+    public long size() {
+        return 1;
+    }
+    @Override
+    public Stream<? extends Triple> stream() {
+        streamCalled = true;
+        return Arrays.asList(new DummyTriple()).stream();
+    }
+
+    @Override
+    public Stream<? extends Triple> stream(BlankNodeOrIRI subject, IRI predicate, RDFTerm
object) {
+        filteredStreamCalled = true;
+        if (contains(subject, predicate, object)) { 
+            return Stream.of(new DummyTriple());
+        } else {
+            return Stream.empty();
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ce0e9abb/api/src/test/java/org/apache/commons/rdf/api/DummyGraphTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/DummyGraphTest.java b/api/src/test/java/org/apache/commons/rdf/api/DummyGraphTest.java
new file mode 100644
index 0000000..a5dffed
--- /dev/null
+++ b/api/src/test/java/org/apache/commons/rdf/api/DummyGraphTest.java
@@ -0,0 +1,84 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rdf.api;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class DummyGraphTest {
+    Graph graph = new DummyGraph();
+
+    @Test
+    public void add() throws Exception {
+        graph.add(new DummyTriple());
+    }
+
+    @Test
+    public void addSPO() throws Exception {
+        graph.add(new DummyIRI(1), new DummyIRI(2), new DummyIRI(3));
+    }
+
+    @Test
+    public void contains() throws Exception {
+        assertTrue(graph.contains(new DummyTriple()));
+    }
+
+    @Test
+    public void containsSPO() throws Exception {
+        assertTrue(graph.contains(null, null, null));
+        assertTrue(graph.contains(new DummyIRI(1), new DummyIRI(2), new DummyIRI(3)));
+        assertFalse(graph.contains(new DummyIRI(0), new DummyIRI(0), new DummyIRI(0)));
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void clearNotSupported() throws Exception {
+        graph.clear();
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void remove() throws Exception {
+        graph.remove(new DummyTriple());
+    }
+
+    @Test
+    public void removeSPO() throws Exception {
+        graph.remove(new DummyIRI(0), new DummyIRI(0), new DummyIRI(0));
+    }
+
+    @Test
+    public void size() throws Exception {
+        assertEquals(1, graph.size());
+    }
+
+    @Test
+    public void stream() throws Exception {
+        assertEquals(new DummyTriple(), graph.stream().findAny().get());
+    }
+
+    @Test
+    public void streamFiltered() throws Exception {
+        assertEquals(new DummyTriple(), graph.stream(null, null, null).findAny().get());
+        assertEquals(new DummyTriple(),
+                graph.stream(new DummyIRI(1), new DummyIRI(2), new DummyIRI(3)).findAny().get());
+        assertFalse(graph.stream(new DummyIRI(0), new DummyIRI(0), new DummyIRI(0)).findAny().isPresent());
+    }
+    
+    
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ce0e9abb/api/src/test/java/org/apache/commons/rdf/api/DummyIRI.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/DummyIRI.java b/api/src/test/java/org/apache/commons/rdf/api/DummyIRI.java
new file mode 100644
index 0000000..c9fe083
--- /dev/null
+++ b/api/src/test/java/org/apache/commons/rdf/api/DummyIRI.java
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rdf.api;
+
+class DummyIRI implements IRI {
+    static final String EXAMPLE_COM = "http://example.com/";
+    final int i;
+
+    public DummyIRI(int i) {
+        this.i = i;
+    }
+
+    @Override
+    public String ntriplesString() {
+        return "<" + EXAMPLE_COM + i + ">";
+    }
+
+    @Override
+    public String getIRIString() {
+        return EXAMPLE_COM + i;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        return (obj instanceof IRI) && ((IRI) obj).getIRIString().equals(EXAMPLE_COM
+ i);
+    }
+
+    @Override
+    public int hashCode() {
+        return getIRIString().hashCode();
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ce0e9abb/api/src/test/java/org/apache/commons/rdf/api/DummyIRITest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/DummyIRITest.java b/api/src/test/java/org/apache/commons/rdf/api/DummyIRITest.java
new file mode 100644
index 0000000..c40e0d7
--- /dev/null
+++ b/api/src/test/java/org/apache/commons/rdf/api/DummyIRITest.java
@@ -0,0 +1,56 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rdf.api;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class DummyIRITest {
+    DummyIRI iri = new DummyIRI(1337);
+
+    @Test
+    public void i() throws Exception {
+        assertEquals(1337, iri.i);
+    }
+
+    @Test
+    public void equals() throws Exception {
+        assertEquals(iri, new DummyIRI(1337));
+    }
+
+    @Test
+    public void notEquals() throws Exception {
+        assertNotEquals(iri, new DummyIRI(1));
+    }
+
+    @Test
+    public void ntriplesString() throws Exception {
+        assertEquals("<http://example.com/1337>", iri.ntriplesString());
+    }
+
+    @Test
+    public void getIRIString() throws Exception {
+        assertEquals("http://example.com/1337", iri.getIRIString());
+    }
+
+    @Test
+    public void testHashCode() throws Exception {
+        assertEquals("http://example.com/1337".hashCode(), iri.hashCode());
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ce0e9abb/api/src/test/java/org/apache/commons/rdf/api/DummyQuad.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/DummyQuad.java b/api/src/test/java/org/apache/commons/rdf/api/DummyQuad.java
new file mode 100644
index 0000000..f964d2a
--- /dev/null
+++ b/api/src/test/java/org/apache/commons/rdf/api/DummyQuad.java
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rdf.api;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+
+class DummyQuad implements Quad {
+    @Override
+    public Optional<BlankNodeOrIRI> getGraphName() {
+        return Optional.empty();
+    }
+    @Override
+    public BlankNodeOrIRI getSubject() {
+        return new DummyIRI(1);
+    }
+    @Override
+    public IRI getPredicate() {
+        return new DummyIRI(2);
+    }
+    @Override
+    public RDFTerm getObject() {
+        return new DummyIRI(3);
+    }
+
+    private static List<RDFTerm> quadList(Quad q) {
+         return Arrays.asList(
+             q.getGraphName().orElse(null),
+             q.getSubject(),
+             q.getPredicate(),
+             q.getObject());
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (!(obj instanceof Quad)) {
+            return false;
+        }
+        return quadList(this).equals(quadList((Quad) obj));
+    }
+    
+    @Override
+    public int hashCode() {           
+        return Objects.hash(getSubject(), getPredicate(), getObject(), getGraphName());
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ce0e9abb/api/src/test/java/org/apache/commons/rdf/api/DummyQuadTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/DummyQuadTest.java b/api/src/test/java/org/apache/commons/rdf/api/DummyQuadTest.java
new file mode 100644
index 0000000..17f33bb
--- /dev/null
+++ b/api/src/test/java/org/apache/commons/rdf/api/DummyQuadTest.java
@@ -0,0 +1,58 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rdf.api;
+
+import static org.junit.Assert.*;
+
+import java.util.Objects;
+
+import org.junit.Test;
+
+public class DummyQuadTest {
+    Quad quad = new DummyQuad();
+
+    @Test
+    public void getGraphName() throws Exception {
+        assertFalse(quad.getGraphName().isPresent());
+    }
+
+    @Test
+    public void getSubject() throws Exception {
+        assertEquals(1, ((DummyIRI) quad.getSubject()).i);
+    }
+    @Test
+    public void getPredicate() throws Exception {
+        assertEquals(2, ((DummyIRI) quad.getPredicate()).i);
+    }
+    @Test
+    public void getObject() throws Exception {
+        assertEquals(3, ((DummyIRI) quad.getObject()).i);
+    }
+    
+    @Test
+    public void equals() throws Exception {
+        assertEquals(quad, new DummyQuad());
+    }
+    
+    @Test
+    public void testHashCode() {
+        int expected = Objects.hash(quad.getSubject(), quad.getPredicate(), quad.getObject(),
quad.getGraphName()); 
+        assertEquals(expected, quad.hashCode());
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ce0e9abb/api/src/test/java/org/apache/commons/rdf/api/DummyTriple.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/DummyTriple.java b/api/src/test/java/org/apache/commons/rdf/api/DummyTriple.java
new file mode 100644
index 0000000..9994bcb
--- /dev/null
+++ b/api/src/test/java/org/apache/commons/rdf/api/DummyTriple.java
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rdf.api;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+
+class DummyTriple implements Triple {
+    @Override
+    public BlankNodeOrIRI getSubject() {
+        return new DummyIRI(1);
+    }
+    @Override
+    public IRI getPredicate() {
+        return new DummyIRI(2);
+    }
+    @Override
+    public RDFTerm getObject() {
+        return new DummyIRI(3);
+    }
+
+    private static List<RDFTerm> tripleList(Triple q) {
+         return Arrays.asList(             
+             q.getSubject(),
+             q.getPredicate(),
+             q.getObject());
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (!(obj instanceof Triple)) {
+            return false;
+        }
+        return tripleList(this).equals(tripleList((Triple) obj));
+    }
+    
+    @Override
+    public int hashCode() {           
+        return Objects.hash(getSubject(), getPredicate(), getObject());
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ce0e9abb/api/src/test/java/org/apache/commons/rdf/api/DummyTripleTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/DummyTripleTest.java b/api/src/test/java/org/apache/commons/rdf/api/DummyTripleTest.java
new file mode 100644
index 0000000..0fae349
--- /dev/null
+++ b/api/src/test/java/org/apache/commons/rdf/api/DummyTripleTest.java
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rdf.api;
+
+import static org.junit.Assert.*;
+
+import java.util.Objects;
+
+import org.junit.Test;
+
+public class DummyTripleTest {
+    Triple triple = new DummyTriple();
+
+    @Test
+    public void getSubject() throws Exception {
+        assertEquals(1, ((DummyIRI) triple.getSubject()).i);
+    }
+    @Test
+    public void getPredicate() throws Exception {
+        assertEquals(2, ((DummyIRI) triple.getPredicate()).i);
+    }
+    @Test
+    public void getObject() throws Exception {
+        assertEquals(3, ((DummyIRI) triple.getObject()).i);
+    }
+    
+    @Test
+    public void equals() throws Exception {
+        assertEquals(triple, new DummyTriple());
+    }
+    
+    @Test
+    public void testHashCode() {
+        int expected = Objects.hash(triple.getSubject(), triple.getPredicate(), triple.getObject());

+        assertEquals(expected, triple.hashCode());
+    }
+}
+



Mime
View raw message