package org.opendaylight.openflowjava.protocol.impl.core;
import static org.junit.Assert.assertEquals;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyShort;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
+
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
-
import java.util.ArrayList;
import java.util.List;
-
-import org.junit.Assert;
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.impl.deserialization.DeserializationFactory;
import org.opendaylight.openflowjava.util.ByteBufUtils;
import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.common.Uint8;
/**
+ * Unit tests for OFDecoder.
*
* @author jameshall
*/
+@RunWith(MockitoJUnitRunner.class)
public class OFDecoderTest {
@Mock ChannelHandlerContext mockChHndlrCtx ;
private List<Object> outList;
/**
- * Sets up test environment
- *
+ * Sets up test environment.
*/
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
- ofDecoder = new OFDecoder() ;
- ofDecoder.setDeserializationFactory( mockDeserializationFactory ) ;
+ ofDecoder = new OFDecoder();
+ ofDecoder.setDeserializationFactory(mockDeserializationFactory);
writeObj = ByteBufUtils.hexStringToByteBuf("16 03 01 00");
- inMsg = new VersionMessageWrapper( (short)8, writeObj );
+ inMsg = new VersionMessageWrapper(Uint8.valueOf(8), writeObj);
outList = new ArrayList<>();
}
- /**
- *
- */
@Test
public void testDecode() {
- when(mockDeserializationFactory.deserialize( any(ByteBuf.class), anyShort() )).thenReturn(mockDataObject);
- try {
- ofDecoder.decode(mockChHndlrCtx, inMsg, outList);
- } catch (Exception e) {
- Assert.fail();
- }
+ when(mockDeserializationFactory.deserialize(any(ByteBuf.class), any(Uint8.class))).thenReturn(mockDataObject);
+
+ ofDecoder.decode(mockChHndlrCtx, inMsg, outList);
// Verify that the message buf was released...
- assertEquals( mockDataObject, outList.get(0) ) ;
- assertEquals( 0, writeObj.refCnt() ) ;
+ assertEquals(mockDataObject, outList.get(0));
+ assertEquals(0, writeObj.refCnt());
}
- /**
- *
- */
@Test
public void testDecodeDeserializeException() {
- when(mockDeserializationFactory.deserialize( any(ByteBuf.class), anyShort() ))
- .thenThrow(new IllegalArgumentException()) ;
+ when(mockDeserializationFactory.deserialize(any(ByteBuf.class), any(Uint8.class)))
+ .thenThrow(new IllegalArgumentException());
- try {
- ofDecoder.decode(mockChHndlrCtx, inMsg, outList);
- } catch (Exception e) {
- Assert.fail();
- }
+ ofDecoder.decode(mockChHndlrCtx, inMsg, outList);
// Verify that the message buf was released...
- assertEquals( 0, outList.size() ) ;
- assertEquals( 0, writeObj.refCnt() ) ;
+ assertEquals(0, outList.size());
+ assertEquals(0, writeObj.refCnt());
}
- /**
- *
- */
@Test
public void testDecodeDeserializeNull() {
- when(mockDeserializationFactory.deserialize( any(ByteBuf.class), anyShort() ))
- .thenReturn(null) ;
+ when(mockDeserializationFactory.deserialize(any(ByteBuf.class), any(Uint8.class))).thenReturn(null);
- try {
- ofDecoder.decode(mockChHndlrCtx, inMsg, outList);
- } catch (Exception e) {
- Assert.fail();
- }
+ ofDecoder.decode(mockChHndlrCtx, inMsg, outList);
// Verify that the message buf was released...
- assertEquals( 0, outList.size() ) ;
- assertEquals( 0, writeObj.refCnt() ) ;
+ assertEquals(0, outList.size());
+ assertEquals(0, writeObj.refCnt());
}
}