PRASHANTH SHIVANANJAPPA | 491b8af | 2016-04-27 19:23:24 +0530 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.isis.io.isispacket.tlv; |
| 17 | |
| 18 | import org.easymock.EasyMock; |
| 19 | import org.jboss.netty.buffer.ChannelBuffer; |
| 20 | import org.junit.After; |
| 21 | import org.junit.Before; |
| 22 | import org.junit.Test; |
| 23 | |
| 24 | import static org.hamcrest.CoreMatchers.*; |
| 25 | import static org.hamcrest.MatcherAssert.assertThat; |
| 26 | |
| 27 | /** |
| 28 | * Unit test class for TlvHeader. |
| 29 | */ |
| 30 | public class TlvHeaderTest { |
| 31 | |
| 32 | private TlvHeader tlvHeader; |
| 33 | private int result; |
| 34 | private ChannelBuffer channelBuffer; |
| 35 | |
| 36 | @Before |
| 37 | public void setUp() throws Exception { |
| 38 | tlvHeader = new TlvHeader(); |
| 39 | channelBuffer = EasyMock.createMock(ChannelBuffer.class); |
| 40 | } |
| 41 | |
| 42 | @After |
| 43 | public void tearDown() throws Exception { |
| 44 | tlvHeader = null; |
| 45 | channelBuffer = null; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Tests tlvLength() getter method. |
| 50 | */ |
| 51 | @Test |
| 52 | public void testTlvLength() throws Exception { |
| 53 | tlvHeader.setTlvLength(1); |
| 54 | result = tlvHeader.tlvLength(); |
| 55 | assertThat(result, is(1)); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Tests tlvLength() setter method. |
| 60 | */ |
| 61 | @Test |
| 62 | public void testSetTlvLength() throws Exception { |
| 63 | tlvHeader.setTlvLength(1); |
| 64 | result = tlvHeader.tlvLength(); |
| 65 | assertThat(result, is(1)); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Tests tlvType() getter method. |
| 70 | */ |
| 71 | @Test |
| 72 | public void testTlvType() throws Exception { |
| 73 | tlvHeader.setTlvType(1); |
| 74 | result = tlvHeader.tlvType(); |
| 75 | assertThat(result, is(1)); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Tests tlvType() setter method. |
| 80 | */ |
| 81 | @Test |
| 82 | public void testSetTlvType() throws Exception { |
| 83 | tlvHeader.setTlvType(1); |
| 84 | result = tlvHeader.tlvType(); |
| 85 | assertThat(result, is(1)); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Tests readFrom() method. |
| 90 | */ |
| 91 | @Test |
| 92 | public void testReadFrom() throws Exception { |
| 93 | tlvHeader.readFrom(channelBuffer); |
| 94 | assertThat(tlvHeader, is(notNullValue())); |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Tests asBytes() getter method. |
| 99 | */ |
| 100 | @Test |
| 101 | public void testAsBytes() throws Exception { |
| 102 | assertThat(tlvHeader.asBytes(), is(nullValue())); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Tests tlvHeaderAsByteArray() method. |
| 107 | */ |
| 108 | @Test |
| 109 | public void testTlvHeaderAsByteArray() throws Exception { |
| 110 | tlvHeader.setTlvLength(1); |
| 111 | tlvHeader.setTlvType(1); |
| 112 | assertThat(tlvHeader.tlvHeaderAsByteArray(), is(notNullValue())); |
| 113 | assertThat(tlvHeader.tlvType(), is(1)); |
| 114 | assertThat(tlvHeader.tlvLength(), is(1)); |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Tests toString() getter method. |
| 119 | */ |
| 120 | @Test |
| 121 | public void testToString() throws Exception { |
| 122 | assertThat(tlvHeader.toString(), is(notNullValue())); |
| 123 | } |
| 124 | } |