Bug 5947: refactored common-api tests 75/42475/7
authorPeter Nosal <peter.nosal@pantheon.tech>
Mon, 25 Jul 2016 12:50:16 +0000 (14:50 +0200)
committerRobert Varga <nite@hq.sk>
Sat, 30 Jul 2016 00:13:42 +0000 (00:13 +0000)
Change-Id: I3b138c524094fcd6c63c46493c8af42c5d0c0d5a
Signed-off-by: Peter Nosal <peter.nosal@pantheon.tech>
12 files changed:
binding/mdsal-binding-api/src/test/java/org/opendaylight/mdsal/binding/api/DataTreeIdentifierTest.java
binding/mdsal-binding-dom-codec/pom.xml
binding/mdsal-binding-dom-codec/src/test/java/org/opendaylight/yangtools/binding/data/codec/impl/NonCachingCodecTest.java [new file with mode: 0644]
common/mdsal-common-api/pom.xml
common/mdsal-common-api/src/test/java/org/opendaylight/mdsal/common/api/BasicExceptionTests.java [deleted file]
common/mdsal-common-api/src/test/java/org/opendaylight/mdsal/common/api/DataStoreUnavailableExceptionTest.java [new file with mode: 0644]
common/mdsal-common-api/src/test/java/org/opendaylight/mdsal/common/api/DataValidationFailedExceptionTest.java [new file with mode: 0644]
common/mdsal-common-api/src/test/java/org/opendaylight/mdsal/common/api/OptimisticLockFailedExceptionTest.java [new file with mode: 0644]
common/mdsal-common-api/src/test/java/org/opendaylight/mdsal/common/api/ReadFailedExceptionTest.java [new file with mode: 0644]
common/mdsal-common-api/src/test/java/org/opendaylight/mdsal/common/api/TransactionChainClosedExceptionTest.java [new file with mode: 0644]
common/mdsal-common-api/src/test/java/org/opendaylight/mdsal/common/api/TransactionCommitDeadlockExceptionTest.java [new file with mode: 0644]
common/mdsal-common-api/src/test/java/org/opendaylight/mdsal/common/api/TransactionCommitFailedExceptionTest.java [new file with mode: 0644]

index c5427c235358afc3c60734a0d972a1a9fcabd59c..7df98fabcb614bb705f17f79864640b505461055 100644 (file)
@@ -19,11 +19,18 @@ import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 public class DataTreeIdentifierTest {
+
     private static final DataTreeIdentifier<TestDataObject1> TEST_IDENTIFIER1 = DataTreeIdentifier.create(
             LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(TestDataObject1.class));
     private static final DataTreeIdentifier<TestDataObject2> TEST_IDENTIFIER2 = DataTreeIdentifier.create(
             LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(TestDataObject2.class));
 
+    @Test
+    public void basicTest() throws Exception {
+        assertEquals(LogicalDatastoreType.OPERATIONAL, TEST_IDENTIFIER1.getDatastoreType());
+        assertEquals(InstanceIdentifier.create(TestDataObject1.class), TEST_IDENTIFIER1.getRootIdentifier());
+    }
+
     @Test
     public void containsTest() {
         assertTrue("Contains", TEST_IDENTIFIER1.contains(DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL,
@@ -40,11 +47,14 @@ public class DataTreeIdentifierTest {
 
     @Test
     public void equalsTest() {
+        assertTrue("Equals", TEST_IDENTIFIER1.equals(TEST_IDENTIFIER1));
         assertTrue("Equals", TEST_IDENTIFIER1.equals(DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL,
                 InstanceIdentifier.create(TestDataObject1.class))));
         assertFalse("Different", TEST_IDENTIFIER1.equals(DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION,
                 InstanceIdentifier.create(TestDataObject1.class))));
         assertFalse("Different", TEST_IDENTIFIER1.equals(TEST_IDENTIFIER2));
+        assertFalse("Equals null", TEST_IDENTIFIER1.equals(null));
+        assertFalse("Different object", TEST_IDENTIFIER1.equals(new Object()));
     }
 
     private static class TestDataObject1 implements DataObject {
index 46855b377041d63235475b68631079d0cf96adfa..42d92accf307b2464849981064d7cc8f2152e86a 100644 (file)
             <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>mockito-configuration</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/binding/mdsal-binding-dom-codec/src/test/java/org/opendaylight/yangtools/binding/data/codec/impl/NonCachingCodecTest.java b/binding/mdsal-binding-dom-codec/src/test/java/org/opendaylight/yangtools/binding/data/codec/impl/NonCachingCodecTest.java
new file mode 100644 (file)
index 0000000..b5672fd
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.binding.data.codec.impl;
+
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import org.junit.Test;
+import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeCodec;
+
+public class NonCachingCodecTest {
+
+    @Test
+    public void basicTest() throws Exception {
+        final BindingNormalizedNodeCodec codec = mock(BindingNormalizedNodeCodec.class);
+        doReturn(null).when(codec).serialize(null);
+        doReturn(null).when(codec).deserialize(null);
+        final NonCachingCodec nonCachingCodec = new NonCachingCodec<>(codec);
+        nonCachingCodec.serialize(null);
+        verify(codec).serialize(null);
+        nonCachingCodec.deserialize(null);
+        verify(codec).deserialize(null);
+    }
+}
\ No newline at end of file
index e5dee0a24aa6033b2a7e6f20bc7e90c6e73865a0..74e3d6c4a362bb07cce836adf752959f9b57c50b 100644 (file)
       <artifactId>mockito-configuration</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.mockito</groupId>
-      <artifactId>mockito-all</artifactId>
-      <scope>test</scope>
-    </dependency>
   </dependencies>
 
   <scm>
diff --git a/common/mdsal-common-api/src/test/java/org/opendaylight/mdsal/common/api/BasicExceptionTests.java b/common/mdsal-common-api/src/test/java/org/opendaylight/mdsal/common/api/BasicExceptionTests.java
deleted file mode 100644 (file)
index 611f2fe..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.mdsal.common.api;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.mock;
-import javax.annotation.Nonnull;
-import org.junit.Test;
-import org.opendaylight.yangtools.concepts.Path;
-import org.opendaylight.yangtools.yang.common.RpcError;
-
-public class BasicExceptionTests {
-
-    private static final RpcError RPC_ERROR = mock(RpcError.class);
-
-    @Test(expected = TransactionCommitFailedException.class)
-    public void transactionCommitFailedExceptionTest() throws Exception {
-        throw new TransactionCommitFailedException("test", RPC_ERROR);
-    }
-
-    @Test(expected = TransactionCommitDeadlockException.class)
-    public void transactionCommitDeadlockExceptionTest() throws Exception {
-        throw new TransactionCommitDeadlockException(TransactionCommitDeadlockException.DEADLOCK_EXCEPTION_SUPPLIER
-                .get().getMessage(), RPC_ERROR);
-    }
-
-    @Test(expected = TransactionChainClosedException.class)
-    public void transactionChainClosedExceptionTest() throws Exception {
-        throw new TransactionChainClosedException("test");
-    }
-
-    @Test(expected = TransactionChainClosedException.class)
-    public void transactionChainClosedExceptionWithNullCauseTest() throws Exception {
-        throw new TransactionChainClosedException("test", null);
-    }
-
-    @Test(expected = ReadFailedException.class)
-    public void readFailedExceptionTest() throws Exception {
-        throw new ReadFailedException("test", RPC_ERROR);
-    }
-
-    @Test(expected = ReadFailedException.class)
-    public void readFailedExceptionWithThrowableTest() throws Exception {
-
-        throw new ReadFailedException("test", ReadFailedException.MAPPER.apply(
-                new NullPointerException()).getCause(), RPC_ERROR);
-    }
-
-    @Test(expected = OptimisticLockFailedException.class)
-    public void optimisticLockFailedExceptionTest() throws Exception {
-        throw new OptimisticLockFailedException("test");
-    }
-
-    @Test(expected = DataStoreUnavailableException.class)
-    public void dataStoreUnavailableExceptionTest() throws Exception {
-        throw new DataStoreUnavailableException("test", null);
-    }
-
-    @Test(expected = DataValidationFailedException.class)
-    public void dataValidationFailedExceptionTest() throws Exception {
-        final TestClass testClass = new TestClass();
-        final DataValidationFailedException dataValidationFailedException =
-                new DataValidationFailedException(TestClass.class, testClass, "test");
-
-        assertEquals(testClass, dataValidationFailedException.getPath());
-        assertEquals(TestClass.class, dataValidationFailedException.getPathType());
-
-        throw dataValidationFailedException;
-    }
-
-    private final class TestClass implements Path {
-        @Override
-        public boolean contains(@Nonnull final Path other) {
-            return false;
-        }
-    }
-}
\ No newline at end of file
diff --git a/common/mdsal-common-api/src/test/java/org/opendaylight/mdsal/common/api/DataStoreUnavailableExceptionTest.java b/common/mdsal-common-api/src/test/java/org/opendaylight/mdsal/common/api/DataStoreUnavailableExceptionTest.java
new file mode 100644 (file)
index 0000000..1911a90
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.common.api;
+
+import org.junit.Test;
+
+public class DataStoreUnavailableExceptionTest {
+
+    @Test(expected = DataStoreUnavailableException.class)
+    public void dataStoreUnavailableExceptionTest() throws Exception {
+        throw new DataStoreUnavailableException("test", null);
+    }
+}
\ No newline at end of file
diff --git a/common/mdsal-common-api/src/test/java/org/opendaylight/mdsal/common/api/DataValidationFailedExceptionTest.java b/common/mdsal-common-api/src/test/java/org/opendaylight/mdsal/common/api/DataValidationFailedExceptionTest.java
new file mode 100644 (file)
index 0000000..cd23802
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.common.api;
+
+import static org.junit.Assert.assertEquals;
+
+import javax.annotation.Nonnull;
+import org.junit.Test;
+import org.opendaylight.yangtools.concepts.Path;
+
+public class DataValidationFailedExceptionTest {
+
+    @Test(expected = DataValidationFailedException.class)
+    public void dataValidationFailedExceptionTest() throws Exception {
+        final TestClass testClass = new TestClass();
+        final DataValidationFailedException dataValidationFailedException =
+                new DataValidationFailedException(TestClass.class, testClass, "test");
+
+        assertEquals(testClass, dataValidationFailedException.getPath());
+        assertEquals(TestClass.class, dataValidationFailedException.getPathType());
+
+        throw dataValidationFailedException;
+    }
+
+    private final class TestClass implements Path {
+        @Override
+        public boolean contains(@Nonnull final Path other) {
+            return false;
+        }
+    }
+}
\ No newline at end of file
diff --git a/common/mdsal-common-api/src/test/java/org/opendaylight/mdsal/common/api/OptimisticLockFailedExceptionTest.java b/common/mdsal-common-api/src/test/java/org/opendaylight/mdsal/common/api/OptimisticLockFailedExceptionTest.java
new file mode 100644 (file)
index 0000000..94ab79e
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.common.api;
+
+import org.junit.Test;
+
+public class OptimisticLockFailedExceptionTest {
+
+    @Test(expected = OptimisticLockFailedException.class)
+    public void optimisticLockFailedExceptionTest() throws Exception {
+        throw new OptimisticLockFailedException("test");
+    }
+}
\ No newline at end of file
diff --git a/common/mdsal-common-api/src/test/java/org/opendaylight/mdsal/common/api/ReadFailedExceptionTest.java b/common/mdsal-common-api/src/test/java/org/opendaylight/mdsal/common/api/ReadFailedExceptionTest.java
new file mode 100644 (file)
index 0000000..95511e6
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.common.api;
+
+import static org.mockito.Mockito.mock;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.RpcError;
+
+public class ReadFailedExceptionTest {
+
+    @Test(expected = ReadFailedException.class)
+    public void readFailedExceptionTest() throws Exception {
+        throw new ReadFailedException("test", mock(RpcError.class));
+    }
+
+    @Test(expected = ReadFailedException.class)
+    public void readFailedExceptionWithThrowableTest() throws Exception {
+        throw new ReadFailedException("test", ReadFailedException.MAPPER.apply(
+                new NullPointerException()).getCause(), mock(RpcError.class));
+    }
+}
\ No newline at end of file
diff --git a/common/mdsal-common-api/src/test/java/org/opendaylight/mdsal/common/api/TransactionChainClosedExceptionTest.java b/common/mdsal-common-api/src/test/java/org/opendaylight/mdsal/common/api/TransactionChainClosedExceptionTest.java
new file mode 100644 (file)
index 0000000..e02060c
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.common.api;
+
+import org.junit.Test;
+
+public class TransactionChainClosedExceptionTest {
+
+    @Test(expected = TransactionChainClosedException.class)
+    public void transactionChainClosedExceptionTest() throws Exception {
+        throw new TransactionChainClosedException("test");
+    }
+
+    @Test(expected = TransactionChainClosedException.class)
+    public void transactionChainClosedExceptionWithNullCauseTest() throws Exception {
+        throw new TransactionChainClosedException("test", null);
+    }
+}
\ No newline at end of file
diff --git a/common/mdsal-common-api/src/test/java/org/opendaylight/mdsal/common/api/TransactionCommitDeadlockExceptionTest.java b/common/mdsal-common-api/src/test/java/org/opendaylight/mdsal/common/api/TransactionCommitDeadlockExceptionTest.java
new file mode 100644 (file)
index 0000000..6d82c76
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.common.api;
+
+import static org.mockito.Mockito.mock;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.RpcError;
+
+public class TransactionCommitDeadlockExceptionTest {
+
+    @Test(expected = TransactionCommitDeadlockException.class)
+    public void transactionCommitDeadlockExceptionTest() throws Exception {
+        throw new TransactionCommitDeadlockException(TransactionCommitDeadlockException.DEADLOCK_EXCEPTION_SUPPLIER
+                .get().getMessage(), mock(RpcError.class));
+    }
+}
\ No newline at end of file
diff --git a/common/mdsal-common-api/src/test/java/org/opendaylight/mdsal/common/api/TransactionCommitFailedExceptionTest.java b/common/mdsal-common-api/src/test/java/org/opendaylight/mdsal/common/api/TransactionCommitFailedExceptionTest.java
new file mode 100644 (file)
index 0000000..e016ed0
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.common.api;
+
+import static org.mockito.Mockito.mock;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.RpcError;
+
+public class TransactionCommitFailedExceptionTest {
+
+    @Test(expected = TransactionCommitFailedException.class)
+    public void transactionCommitFailedExceptionTest() throws Exception {
+        throw new TransactionCommitFailedException("test", mock(RpcError.class));
+    }
+}
\ No newline at end of file