Improve RoutedDOMRpcRoutingTableEntryTest 50/97950/4
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 17 Oct 2021 08:39:06 +0000 (10:39 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 17 Oct 2021 08:47:40 +0000 (10:47 +0200)
Add a few assertions around what we expect to happen.

Change-Id: I4fc56fb0f763a5b9cf6669444a8d1e3e442780c2
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/RoutedDOMRpcRoutingTableEntryTest.java

index f90c0b52e883a63284b69118d3754a5634db41f7..be9198cd522214ec4408876d0d595f24bea3c3f9 100644 (file)
@@ -9,34 +9,55 @@ package org.opendaylight.mdsal.dom.broker;
 
 import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertThrows;
 import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
 import static org.opendaylight.mdsal.dom.broker.TestUtils.TEST_CHILD;
 
+import com.google.common.collect.ImmutableMap;
+import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
-import java.util.HashMap;
+import java.util.Map;
 import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
+import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException;
 import org.opendaylight.mdsal.dom.broker.DOMRpcRouter.OperationInvocation;
 import org.opendaylight.mdsal.dom.broker.util.TestModel;
 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
 
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class RoutedDOMRpcRoutingTableEntryTest {
-    @Test
-    public void basicTest()  {
-        final RpcDefinition rpcDefinition = mock(RpcDefinition.class);
+    @Mock
+    public RpcDefinition rpcDefinition;
+
+    private RoutedDOMRpcRoutingTableEntry entry;
+
+    @Before
+    public void before() {
         doReturn(TestModel.TEST2_QNAME).when(rpcDefinition).getQName();
+        // Note: ImmutableMap.of() allows get(null), Map.of() does not
+        entry = new RoutedDOMRpcRoutingTableEntry(rpcDefinition, TestModel.TEST_PATH, ImmutableMap.of());
+    }
 
-        final RoutedDOMRpcRoutingTableEntry routedDOMRpcRoutingTableEntry =
-                new RoutedDOMRpcRoutingTableEntry(rpcDefinition, TestModel.TEST_PATH, new HashMap<>());
-        assertNotNull(routedDOMRpcRoutingTableEntry.newInstance(new HashMap<>()));
+    @Test
+    public void testNewInstance() {
+        final RoutedDOMRpcRoutingTableEntry instance = entry.newInstance(Map.of());
+        assertEquals(TestModel.TEST2_QNAME, entry.getType());
+        assertEquals(Map.of(), instance.getImplementations());
+    }
 
-        final ListenableFuture<?> future = OperationInvocation.invoke(routedDOMRpcRoutingTableEntry, TEST_CHILD);
-        final ExecutionException ex = assertThrows(ExecutionException.class, () -> future.get(5, TimeUnit.SECONDS));
-        assertThat(ex.getCause(), instanceOf(DOMRpcImplementationNotAvailableException.class));
+    @Test
+    public void testUnregistered()  {
+        final ListenableFuture<?> future = OperationInvocation.invoke(entry, TEST_CHILD);
+        final Throwable cause = assertThrows(ExecutionException.class, () -> Futures.getDone(future)).getCause();
+        assertThat(cause, instanceOf(DOMRpcImplementationNotAvailableException.class));
+        assertEquals("No implementation of RPC "
+            + "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test2 "
+            + "available",
+            cause.getMessage());
     }
 }