Migrate mdsal-binding-api to JUnit5 00/107600/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 30 Aug 2023 17:35:26 +0000 (19:35 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 30 Aug 2023 20:12:57 +0000 (22:12 +0200)
Remove DataObjectModificationTest and migrate other tests to use JUnit5.

Change-Id: Ie341ae97344066a0627225e7ee56162bc27927ac
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-api/src/test/java/org/opendaylight/mdsal/binding/api/DataObjectModificationTest.java [deleted file]
binding/mdsal-binding-api/src/test/java/org/opendaylight/mdsal/binding/api/DataTreeChangeServiceWildcardedTest.java
binding/mdsal-binding-api/src/test/java/org/opendaylight/mdsal/binding/api/DataTreeIdentifierTest.java
binding/mdsal-binding-api/src/test/java/org/opendaylight/mdsal/binding/api/NotificationRejectedExceptionTest.java
binding/mdsal-binding-api/src/test/java/org/opendaylight/mdsal/binding/api/TransactionChainClosedExceptionTest.java

diff --git a/binding/mdsal-binding-api/src/test/java/org/opendaylight/mdsal/binding/api/DataObjectModificationTest.java b/binding/mdsal-binding-api/src/test/java/org/opendaylight/mdsal/binding/api/DataObjectModificationTest.java
deleted file mode 100644 (file)
index 3c6773e..0000000
+++ /dev/null
@@ -1,20 +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.binding.api;
-
-import static org.junit.Assert.assertNotNull;
-
-import org.junit.Test;
-
-public class DataObjectModificationTest {
-
-    @Test
-    public void notificationMethodEnumTest() throws Exception {
-        assertNotNull(DataObjectModification.ModificationType.values());
-    }
-}
\ No newline at end of file
index 55ad0a4d39454267ceaabecd68eb3c52c6cbd4d0..68a4a1355d6e75704cec519bb1be529d3621fd2f 100644 (file)
@@ -7,50 +7,43 @@
  */
 package org.opendaylight.mdsal.binding.api;
 
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
+import static org.hamcrest.CoreMatchers.startsWith;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doCallRealMethod;
-import static org.mockito.Mockito.mock;
 
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.yang.gen.v1.mdsal813.norev.RegisterListenerTest;
 import org.opendaylight.yang.gen.v1.mdsal813.norev.register.listener.test.Item;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
-public class DataTreeChangeServiceWildcardedTest {
-
-    DataBroker dataBroker;
-
-    DataListener<Item> listener;
-
-    DataChangeListener<Item> changeListener;
-
-    @Before
-    public void setUp() {
-        dataBroker = mock(DataBroker.class);
-        listener = mock(DataListener.class);
-        changeListener = mock(DataChangeListener.class);
-    }
+@ExtendWith(MockitoExtension.class)
+class DataTreeChangeServiceWildcardedTest {
+    @Mock
+    private DataBroker dataBroker;
+    @Mock
+    private DataListener<Item> listener;
+    @Mock
+    private DataChangeListener<Item> changeListener;
 
     @Test
-    public void testThrowExceptionOnRegister() {
-        final InstanceIdentifier<Item> instanceIdentifier = InstanceIdentifier.builder(RegisterListenerTest.class)
-            .child(Item.class).build();
-        final DataTreeIdentifier<Item> itemsDataTreeIdentifier = DataTreeIdentifier.create(
-            LogicalDatastoreType.OPERATIONAL, instanceIdentifier);
+    void testThrowExceptionOnRegister() {
+        final var itemIID = InstanceIdentifier.builder(RegisterListenerTest.class).child(Item.class).build();
+        final var itemDTI = DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, itemIID);
 
         doCallRealMethod().when(dataBroker).registerDataListener(any(), any());
         final var dataListenerException = assertThrows(IllegalArgumentException.class,
-            () -> dataBroker.registerDataListener(itemsDataTreeIdentifier, listener));
-        assertTrue(dataListenerException.getMessage().contains("Cannot register listener for wildcard"));
+            () -> dataBroker.registerDataListener(itemDTI, listener));
+        assertThat(dataListenerException.getMessage(), startsWith("Cannot register listener for wildcard"));
 
         doCallRealMethod().when(dataBroker).registerDataChangeListener(any(), any());
         final var dataListenerChangeException = assertThrows(IllegalArgumentException.class,
-            () -> dataBroker.registerDataChangeListener(itemsDataTreeIdentifier, changeListener));
-        assertTrue(dataListenerChangeException.getMessage().contains("Cannot register listener for wildcard"));
+            () -> dataBroker.registerDataChangeListener(itemDTI, changeListener));
+        assertThat(dataListenerChangeException.getMessage(), startsWith("Cannot register listener for wildcard"));
     }
-
 }
index 1f6879b9e007aebda82ced5e5d4a907c76fa7f6d..0b733c8f78d16e4da2cf3a147df98b8d97731c69 100644 (file)
@@ -7,55 +7,55 @@
  */
 package org.opendaylight.mdsal.binding.api;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.yangtools.yang.binding.ChildOf;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.DataRoot;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
-public class DataTreeIdentifierTest {
-
+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 {
+    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,
-                InstanceIdentifier.create(TestDataObject1.class))));
-        assertFalse("Not Contains", TEST_IDENTIFIER1.contains(TEST_IDENTIFIER2));
+    void containsTest() {
+        assertTrue(TEST_IDENTIFIER1.contains(DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL,
+                InstanceIdentifier.create(TestDataObject1.class))), "Contains");
+        assertFalse(TEST_IDENTIFIER1.contains(TEST_IDENTIFIER2), "Not Contains");
     }
 
     @Test
-    public void hashCodeTest() {
-        assertEquals("hashCode", TEST_IDENTIFIER1.hashCode(), DataTreeIdentifier.create(
+    void hashCodeTest() {
+        assertEquals(TEST_IDENTIFIER1.hashCode(),
+            DataTreeIdentifier.create(
                 LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(TestDataObject1.class)).hashCode());
-        assertNotEquals("hashCode", TEST_IDENTIFIER1.hashCode(), TEST_IDENTIFIER2.hashCode());
+        assertNotEquals(TEST_IDENTIFIER1.hashCode(), TEST_IDENTIFIER2.hashCode());
     }
 
     @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()));
+    void equalsTest() {
+        assertEquals(TEST_IDENTIFIER1, TEST_IDENTIFIER1, "Equals");
+        assertEquals(TEST_IDENTIFIER1, DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL,
+                InstanceIdentifier.create(TestDataObject1.class)), "Equals");
+        assertNotEquals(TEST_IDENTIFIER1, DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION,
+                InstanceIdentifier.create(TestDataObject1.class)), "Different");
+        assertNotEquals(TEST_IDENTIFIER1, TEST_IDENTIFIER2, "Different");
+        assertNotEquals(TEST_IDENTIFIER1, null, "Equals null");
+        assertNotEquals(TEST_IDENTIFIER1, new Object(), "Different object");
     }
 
     private interface TestDataObject1 extends ChildOf<DataRoot> {
index 022510a931449bba98156b550fa1088cb31524d9..401d41a64769136bc37d70e77ec14bcd83a86107 100644 (file)
@@ -7,17 +7,25 @@
  */
 package org.opendaylight.mdsal.binding.api;
 
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
 
-public class NotificationRejectedExceptionTest {
+import org.junit.jupiter.api.Test;
 
-    @Test(expected = NotificationRejectedException.class)
-    public void constructWithCauseTest() throws Exception {
-        throw new NotificationRejectedException("test", new Throwable());
+class NotificationRejectedExceptionTest {
+    @Test
+    void constructWithCauseTest() {
+        final var cause = new Throwable();
+        final var ex = new NotificationRejectedException("test", cause);
+        assertEquals("test", ex.getMessage());
+        assertSame(cause, ex.getCause());
     }
 
-    @Test(expected = NotificationRejectedException.class)
-    public void constructTest() throws Exception {
-        throw new NotificationRejectedException("test");
+    @Test
+    void constructTest() throws Exception {
+        final var ex = new NotificationRejectedException("test");
+        assertEquals("test", ex.getMessage());
+        assertNull(ex.getCause());
     }
 }
\ No newline at end of file
index bd8dd15e7be1745db0294af509e24d94ded6cf11..f05e45e478aafbaf91c3033018d958acdebddbbb 100644 (file)
@@ -7,17 +7,25 @@
  */
 package org.opendaylight.mdsal.binding.api;
 
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
 
-public class TransactionChainClosedExceptionTest {
+import org.junit.jupiter.api.Test;
 
-    @Test(expected = TransactionChainClosedException.class)
-    public void transactionChainClosedExceptionTest() throws Exception {
-        throw new TransactionChainClosedException("test");
+class TransactionChainClosedExceptionTest {
+    @Test
+    void transactionChainClosedExceptionTest() throws Exception {
+        final var ex = new TransactionChainClosedException("test");
+        assertEquals("test", ex.getMessage());
+        assertNull(ex.getCause());
     }
 
-    @Test(expected = TransactionChainClosedException.class)
-    public void transactionChainClosedExceptionWithNullCauseTest() throws Exception {
-        throw new TransactionChainClosedException("test", null);
+    @Test
+    void transactionChainClosedExceptionWithNullCauseTest() throws Exception {
+        final var cause = new Throwable();
+        final var ex = new TransactionChainClosedException("test", cause);
+        assertEquals("test", ex.getMessage());
+        assertSame(cause, ex.getCause());
     }
 }
\ No newline at end of file