commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [2/5] incubator-commonsrdf git commit: COMMONSRDF-14 Tests for hashCode requirements
Date Mon, 10 Aug 2015 10:31:23 GMT
COMMONSRDF-14 Tests for hashCode requirements


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

Branch: refs/heads/master
Commit: 26da40856a86f6fdb511fdc0290b11c24518b704
Parents: 1a1bc32
Author: Stian Soiland-Reyes <stain@apache.org>
Authored: Tue May 12 10:06:29 2015 +0100
Committer: Stian Soiland-Reyes <stain@apache.org>
Committed: Tue May 12 10:06:29 2015 +0100

----------------------------------------------------------------------
 .../rdf/api/AbstractRDFTermFactoryTest.java     | 67 ++++++++++++++++++++
 1 file changed, 67 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/26da4085/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java
b/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java
index e4561c4..1c62161 100644
--- a/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java
+++ b/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java
@@ -22,6 +22,8 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotSame;
 
+import java.util.Objects;
+
 import org.junit.Assume;
 import org.junit.Before;
 import org.junit.Test;
@@ -406,4 +408,69 @@ public abstract class AbstractRDFTermFactoryTest {
         factory.createTriple(subject, (IRI) predicate, object);
     }
 
+    @Test
+    public void hashCodeBlankNode() throws Exception {
+        BlankNode bnode1;
+        try {
+            bnode1 = factory.createBlankNode();
+        } catch (UnsupportedOperationException ex) {
+            Assume.assumeNoException(
+                    "createBlankNode() not supported", ex);
+            return;
+        }
+        assertEquals(bnode1.uniqueReference().hashCode(), bnode1.hashCode());
+    }
+
+    @Test
+    public void hashCodeIRI() throws Exception {
+        IRI iri;
+        try {
+            iri = factory.createIRI("http://example.com/");
+        } catch (UnsupportedOperationException ex) {
+            Assume.assumeNoException(
+                    "createIRI(String) not supported", ex);
+            return;
+        }
+        assertEquals(iri.getIRIString().hashCode(), iri.hashCode());
+    }
+
+    @Test
+    public void hashCodeLiteral() throws Exception {
+        Literal literal;
+        try {
+            literal = factory.createLiteral("Hello");
+        } catch (UnsupportedOperationException ex) {
+            Assume.assumeNoException(
+                    "createLiteral(String) not supported", ex);
+            return;
+        }
+        assertEquals(Objects.hash(
+                    literal.getLexicalForm(),
+                    literal.getDatatype(),
+                    literal.getLanguageTag()
+                ),
+                literal.hashCode());
+    }
+
+    @Test
+    public void hashCodeTriple() throws Exception {
+        IRI iri;
+        try {
+            iri = factory.createIRI("http://example.com/");
+        } catch (UnsupportedOperationException ex) {
+            Assume.assumeNoException(
+                    "createIRI() not supported", ex);
+            return;
+        }
+        Triple triple;
+        try {
+            triple = factory.createTriple(iri, iri, iri);
+        } catch (UnsupportedOperationException ex) {
+            Assume.assumeNoException(
+                    "createTriple() not supported", ex);
+            return;
+        }
+        assertEquals(Objects.hash(iri, iri, iri),
+                     triple.hashCode());
+    }
 }


Mime
View raw message