Implement registerNotificationListeners()
[netconf.git] / plugins / netconf-client-mdsal / src / test / java / org / opendaylight / netconf / client / mdsal / spi / NetconfDeviceNotificationServiceTest.java
index 9c965736f718305511f51d9ce3e3e9e3101deb1e..2d3fc9b6a583ec4fa78dac96181b523a875a5a19 100644 (file)
@@ -7,25 +7,28 @@
  */
 package org.opendaylight.netconf.client.mdsal.spi;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
 import org.opendaylight.mdsal.dom.api.DOMNotification;
 import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
 
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class NetconfDeviceNotificationServiceTest {
+@ExtendWith(MockitoExtension.class)
+class NetconfDeviceNotificationServiceTest {
+    private static final Absolute PATH1 = Absolute.of(QName.create("namespace1", "path1"));
+    private static final Absolute PATH2 = Absolute.of(QName.create("namespace2", "path2"));
+
     @Mock
     private DOMNotificationListener listener1;
     @Mock
@@ -35,24 +38,20 @@ public class NetconfDeviceNotificationServiceTest {
     @Mock
     private DOMNotification notification2;
 
-    private NetconfDeviceNotificationService service;
+    private final NetconfDeviceNotificationService service = new NetconfDeviceNotificationService();
     private ListenerRegistration<DOMNotificationListener> registration;
 
+    @BeforeEach
+    void beforeEach() throws Exception {
+        service.registerNotificationListener(listener1, PATH1);
+        registration = service.registerNotificationListener(listener2, PATH2);
 
-    @Before
-    public void setUp() throws Exception {
-        final Absolute path1 = Absolute.of(QName.create("namespace1", "path1"));
-        final Absolute path2 = Absolute.of(QName.create("namespace2", "path2"));
-        service = new NetconfDeviceNotificationService();
-        service.registerNotificationListener(listener1, path1);
-        registration = service.registerNotificationListener(listener2, path2);
-
-        doReturn(path1).when(notification1).getType();
-        doReturn(path2).when(notification2).getType();
+        doReturn(PATH2).when(notification2).getType();
     }
 
     @Test
-    public void testPublishNotification() throws Exception {
+    void testPublishNotification() throws Exception {
+        doReturn(PATH1).when(notification1).getType();
 
         service.publishNotification(notification1);
         verify(listener1).onNotification(notification1);
@@ -64,9 +63,9 @@ public class NetconfDeviceNotificationServiceTest {
     }
 
     @Test
-    public void testCloseRegistration() throws Exception {
+    void testCloseRegistration() throws Exception {
         service.publishNotification(notification2);
-        Assert.assertEquals(listener2, registration.getInstance());
+        assertEquals(listener2, registration.getInstance());
         registration.close();
         service.publishNotification(notification2);
         verify(listener2, times(1)).onNotification(notification2);