SureshBR
Committed by Gerrit Code Review

UT for Pcep close message updated with assertThat

Change-Id: I6c51af5aefcf49a2bdc304dd9bd6e3f25f18ae21
...@@ -17,44 +17,44 @@ package org.onosproject.pcepio; ...@@ -17,44 +17,44 @@ package org.onosproject.pcepio;
17 17
18 import org.jboss.netty.buffer.ChannelBuffer; 18 import org.jboss.netty.buffer.ChannelBuffer;
19 import org.jboss.netty.buffer.ChannelBuffers; 19 import org.jboss.netty.buffer.ChannelBuffers;
20 -import org.junit.Assert;
21 import org.junit.Test; 20 import org.junit.Test;
22 import org.onosproject.pcepio.exceptions.PcepParseException; 21 import org.onosproject.pcepio.exceptions.PcepParseException;
22 +import org.onosproject.pcepio.protocol.PcepCloseMsg;
23 import org.onosproject.pcepio.protocol.PcepFactories; 23 import org.onosproject.pcepio.protocol.PcepFactories;
24 import org.onosproject.pcepio.protocol.PcepMessage; 24 import org.onosproject.pcepio.protocol.PcepMessage;
25 import org.onosproject.pcepio.protocol.PcepMessageReader; 25 import org.onosproject.pcepio.protocol.PcepMessageReader;
26 -import org.onosproject.pcepio.protocol.PcepCloseMsg; 26 +
27 +import static org.hamcrest.MatcherAssert.assertThat;
28 +import static org.hamcrest.core.Is.is;
29 +import static org.hamcrest.core.IsSame.sameInstance;
27 30
28 public class PcepCloseMsgTest { 31 public class PcepCloseMsgTest {
29 32
30 /** 33 /**
31 * Common header, reason to close. 34 * Common header, reason to close.
32 - *
33 - * @throws PcepParseException while parsing the PCEP message.
34 */ 35 */
35 @Test 36 @Test
36 public void closeMessageTest1() throws PcepParseException { 37 public void closeMessageTest1() throws PcepParseException {
37 38
38 - byte[] closeMsg = new byte[] {0x20, 0x07, 0x00, 0x0C, 39 + byte[] closeMsg = new byte[] {0x20, 0x07, 0x00, 0x0C, 0x0f, 0x10, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02 };
39 - 0x0f, 0x10, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02 };
40 40
41 byte[] testCloseMsg = {0 }; 41 byte[] testCloseMsg = {0 };
42 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); 42 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
43 buffer.writeBytes(closeMsg); 43 buffer.writeBytes(closeMsg);
44 44
45 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); 45 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
46 - PcepMessage message = null; 46 + PcepMessage message;
47 47
48 message = reader.readFrom(buffer); 48 message = reader.readFrom(buffer);
49 - Assert.assertTrue("PcepMessage is not instance of PcepCloseMsg", message instanceof PcepCloseMsg); 49 + assertThat(message, sameInstance((PcepCloseMsg) message));
50 50
51 ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); 51 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
52 message.writeTo(buf); 52 message.writeTo(buf);
53 testCloseMsg = buf.array(); 53 testCloseMsg = buf.array();
54 54
55 - int readLen = buf.writerIndex() - 0; 55 + int readLen = buf.writerIndex();
56 testCloseMsg = new byte[readLen]; 56 testCloseMsg = new byte[readLen];
57 buf.readBytes(testCloseMsg, 0, readLen); 57 buf.readBytes(testCloseMsg, 0, readLen);
58 - Assert.assertArrayEquals("PcTERpt messages are not equal", closeMsg, testCloseMsg); 58 + assertThat(testCloseMsg, is(closeMsg));
59 } 59 }
60 } 60 }
......