You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by fr...@apache.org on 2015/10/23 15:46:45 UTC

svn commit: r1710214 - in /jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/api: TypeComparisonTest.java TypePreconditionTest.java

Author: frm
Date: Fri Oct 23 13:46:45 2015
New Revision: 1710214

URL: http://svn.apache.org/viewvc?rev=1710214&view=rev
Log:
OAK-3544 - Add tests for comparisons and preconditions of o.a.j.o.api.Type

Added:
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/api/TypeComparisonTest.java   (with props)
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/api/TypePreconditionTest.java   (with props)

Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/api/TypeComparisonTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/api/TypeComparisonTest.java?rev=1710214&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/api/TypeComparisonTest.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/api/TypeComparisonTest.java Fri Oct 23 13:46:45 2015
@@ -0,0 +1,99 @@
+/*
+ * 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.jackrabbit.oak.api;
+
+import org.junit.Test;
+
+import java.util.Arrays;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+public class TypeComparisonTest {
+
+    @Test
+    public void compareTypes() {
+        Type[] types = new Type[]{
+                Type.BINARIES,
+                Type.BINARY,
+                Type.BOOLEANS,
+                Type.BOOLEAN,
+                Type.DATES,
+                Type.DATE,
+                Type.DECIMALS,
+                Type.DECIMAL,
+                Type.DOUBLES,
+                Type.DOUBLE,
+                Type.LONGS,
+                Type.LONG,
+                Type.NAMES,
+                Type.NAME,
+                Type.PATHS,
+                Type.PATH,
+                Type.REFERENCES,
+                Type.REFERENCE,
+                Type.STRINGS,
+                Type.STRING,
+                Type.UNDEFINEDS,
+                Type.UNDEFINED,
+                Type.URIS,
+                Type.URI,
+                Type.WEAKREFERENCES,
+                Type.WEAKREFERENCE,
+
+        };
+
+        Arrays.sort(types);
+
+        for (int i = 0; i < types.length; i++) {
+            for (int j = 0; j < types.length; j++) {
+                if (i < j) {
+                    assertTypeLessThan(types[i], types[j]);
+                }
+
+                if (j < i) {
+                    assertTypeLessThan(types[j], types[i]);
+                }
+
+                if (i == j) {
+                    assertTypeEqual(types[i], types[j]);
+                }
+            }
+        }
+    }
+
+    private void assertTypeLessThan(Type<?> a, Type<?> b) {
+        assertTrue(a.compareTo(b) < 0);
+        assertTrue(b.compareTo(a) > 0);
+
+        if (a.tag() > b.tag()) {
+            fail("Types should be ordered by increasing tag value");
+        }
+
+        if (b.tag() == a.tag() && a.isArray() && !b.isArray()) {
+            fail("If their tag is the same, types should be ordered by multiplicity");
+        }
+    }
+
+    private void assertTypeEqual(Type<?> a, Type<?> b) {
+        assertTrue(a.compareTo(b) == 0);
+        assertTrue(a.tag() == b.tag());
+        assertTrue(a.isArray() == b.isArray());
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/api/TypeComparisonTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/api/TypePreconditionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/api/TypePreconditionTest.java?rev=1710214&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/api/TypePreconditionTest.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/api/TypePreconditionTest.java Fri Oct 23 13:46:45 2015
@@ -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.jackrabbit.oak.api;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import static org.junit.Assert.assertEquals;
+
+@RunWith(Parameterized.class)
+public class TypePreconditionTest {
+
+    @Parameters(name = "{0}/{1}")
+    public static Object[][] getTypes() {
+        return new Object[][]{
+                {Type.BINARIES, Type.BINARY},
+                {Type.BOOLEANS, Type.BOOLEAN},
+                {Type.DATES, Type.DATE},
+                {Type.DECIMALS, Type.DECIMAL},
+                {Type.DOUBLES, Type.DOUBLE},
+                {Type.LONGS, Type.LONG},
+                {Type.NAMES, Type.NAME},
+                {Type.PATHS, Type.PATH},
+                {Type.REFERENCES, Type.REFERENCE},
+                {Type.STRINGS, Type.STRING},
+                {Type.UNDEFINEDS, Type.UNDEFINED},
+                {Type.URIS, Type.URI},
+                {Type.WEAKREFERENCES, Type.WEAKREFERENCE}
+        };
+    }
+
+    private final Type multi;
+
+    private final Type single;
+
+    public TypePreconditionTest(Type multi, Type single) {
+        this.multi = multi;
+        this.single = single;
+    }
+
+    @Test
+    public void testBaseTypeOnMultiValueType() {
+        assertEquals(single, multi.getBaseType());
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void testBaseTypeOnSingleValueType() {
+        single.getBaseType();
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void testArrayTypeOnMultiValueType() {
+        multi.getArrayType();
+    }
+
+    @Test
+    public void testArrayTypeOnSingleValueType() {
+        assertEquals(multi, single.getArrayType());
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/api/TypePreconditionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native