Use ByteBuf.readRetainedSlice()
[openflowplugin.git] / openflowjava / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / core / OFEncoderTest.java
index fbbc7464dd170fbff9bcb71057639402db2f3379..cd4b2f88af0820be5c8f13edbfc69d7e941c7696 100644 (file)
@@ -9,7 +9,6 @@
 package org.opendaylight.openflowjava.protocol.impl.core;
 
 import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyShort;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
@@ -21,8 +20,9 @@ import io.netty.util.concurrent.Future;
 import io.netty.util.concurrent.GenericFutureListener;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.impl.core.connection.MessageListenerWrapper;
 import org.opendaylight.openflowjava.protocol.impl.serialization.SerializationFactory;
@@ -35,6 +35,7 @@ import org.opendaylight.yangtools.yang.common.Uint8;
  *
  * @author jameshall
  */
+@RunWith(MockitoJUnitRunner.class)
 public class OFEncoderTest {
 
     @Mock ChannelHandlerContext mockChHndlrCtx ;
@@ -52,7 +53,6 @@ public class OFEncoderTest {
      */
     @Before
     public void setUp() {
-        MockitoAnnotations.initMocks(this);
         ofEncoder = new OFEncoder() ;
         ofEncoder.setSerializationFactory(mockSerializationFactory);
     }
@@ -62,7 +62,6 @@ public class OFEncoderTest {
      */
     @Test
     public void testEncodeSuccess() throws Exception {
-        when(mockOut.readableBytes()).thenReturn(1);
         when(wrapper.getMsg()).thenReturn(mockMsg);
         when(wrapper.getMsg().getVersion()).thenReturn(Uint8.valueOf(EncodeConstants.OF13_VERSION_ID));
 
@@ -80,7 +79,7 @@ public class OFEncoderTest {
         when(wrapper.getMsg()).thenReturn(mockMsg);
         when(wrapper.getListener()).thenReturn(listener);
         when(wrapper.getMsg().getVersion()).thenReturn(Uint8.valueOf(EncodeConstants.OF13_VERSION_ID));
-        doThrow(new IllegalArgumentException()).when(mockSerializationFactory).messageToBuffer(anyShort(),
+        doThrow(new IllegalArgumentException()).when(mockSerializationFactory).messageToBuffer(any(Uint8.class),
                 any(ByteBuf.class), any(DataObject.class));
 
         ofEncoder.encode(mockChHndlrCtx, wrapper, mockOut);
@@ -94,7 +93,6 @@ public class OFEncoderTest {
      */
     @Test
     public void testEncodeSerializesNoBytes() throws Exception {
-        when(mockOut.readableBytes()).thenReturn(0);
         when(wrapper.getMsg()).thenReturn(mockMsg);
         when(wrapper.getMsg().getVersion()).thenReturn(Uint8.valueOf(EncodeConstants.OF13_VERSION_ID));