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.ArgumentMatchers.anyShort;
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.mockito.Mock;
import org.opendaylight.yangtools.yang.binding.DataObject;
/**
+ * Unit tests for OFDecoder.
*
* @author jameshall
*/
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((short) 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();
- }
+ public void testDecode() throws Exception {
+ when(mockDeserializationFactory.deserialize(any(ByteBuf.class), anyShort())).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()) ;
+ public void testDecodeDeserializeException() throws Exception {
+ when(mockDeserializationFactory.deserialize(any(ByteBuf.class), anyShort()))
+ .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) ;
+ public void testDecodeDeserializeNull() throws Exception {
+ when(mockDeserializationFactory.deserialize(any(ByteBuf.class), anyShort())).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());
}
}