Migrate netconf-server tests to JUnit5
[netconf.git] / protocol / netconf-server / src / test / java / org / opendaylight / netconf / server / SendErrorExceptionUtilTest.java
index cd69dda218622e361519d6d6cd1a129d3542ae22..a729b0f60dc2caa7e460ea911ba0dd4018b5fac3 100644 (file)
@@ -7,7 +7,7 @@
  */
 package org.opendaylight.netconf.server;
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.times;
@@ -15,19 +15,19 @@ import static org.mockito.Mockito.verify;
 
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelFuture;
-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.ArgumentCaptor;
 import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
 import org.opendaylight.netconf.api.DocumentedException;
 import org.opendaylight.netconf.api.NetconfSession;
 import org.opendaylight.netconf.api.messages.NetconfMessage;
 import org.opendaylight.netconf.api.xml.XmlUtil;
 
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class SendErrorExceptionUtilTest {
+@ExtendWith(MockitoExtension.class)
+class SendErrorExceptionUtilTest {
     private final DocumentedException exception = new DocumentedException("err");
 
     @Mock
@@ -37,40 +37,42 @@ public class SendErrorExceptionUtilTest {
     @Mock
     Channel channel;
 
-    @Before
-    public void setUp() throws Exception {
-        doReturn(channelFuture).when(netconfSession).sendMessage(any());
+    @BeforeEach
+    void setUp() {
         doReturn(channelFuture).when(channelFuture).addListener(any());
-        doReturn(channelFuture).when(channel).writeAndFlush(any());
     }
 
     @Test
-    public void testSendErrorMessage1() throws Exception {
+    void testSendErrorMessage1() {
+        doReturn(channelFuture).when(netconfSession).sendMessage(any());
         SendErrorExceptionUtil.sendErrorMessage(netconfSession, exception);
         verify(channelFuture).addListener(any());
         verify(netconfSession).sendMessage(any());
     }
 
     @Test
-    public void testSendErrorMessage2() throws Exception {
+    void testSendErrorMessage2() {
+        doReturn(channelFuture).when(channel).writeAndFlush(any());
         SendErrorExceptionUtil.sendErrorMessage(channel, exception);
         verify(channelFuture).addListener(any());
     }
 
     @Test
-    public void testSendErrorMessage3() throws Exception {
+    void testSendErrorMessage3() throws Exception {
+        doReturn(channelFuture).when(netconfSession).sendMessage(any());
         SendErrorExceptionUtil.sendErrorMessage(netconfSession, exception, readMessage("rpc.xml"));
         verify(channelFuture).addListener(any());
     }
 
     @Test
-    public void testSendErrorMessage4() throws Exception {
+    void testSendErrorMessage4() throws Exception {
+        doReturn(channelFuture).when(netconfSession).sendMessage(any());
         SendErrorExceptionUtil.sendErrorMessage(netconfSession, exception, readMessage("rpc_ns.xml"));
         final var messageCaptor = ArgumentCaptor.forClass(NetconfMessage.class);
         verify(netconfSession, times(1)).sendMessage(messageCaptor.capture());
         final var rpcReply = messageCaptor.getValue().getDocument().getDocumentElement();
-        assertEquals("Invalid value of message-id attribute in the reply message", "a",
-            rpcReply.getAttribute("message-id"));
+        assertEquals("a", rpcReply.getAttribute("message-id"),
+            "Invalid value of message-id attribute in the reply message");
     }
 
     private static NetconfMessage readMessage(final String name) throws Exception {