HONEYCOMB-58 - Routing Api
[honeycomb.git] / vpp-common / vpp-translate-utils / src / test / java / io / fd / honeycomb / translate / vpp / util / ByteDataTranslatorTest.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
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
17 package io.fd.honeycomb.translate.vpp.util;
18
19 import static org.junit.Assert.assertArrayEquals;
20 import static org.junit.Assert.assertEquals;
21
22 import org.junit.Test;
23
24 public class ByteDataTranslatorTest implements ByteDataTranslator {
25
26     @Test
27     public void testBooleanToByte() {
28         assertEquals(0, booleanToByte(null));
29         assertEquals(0, booleanToByte(false));
30         assertEquals(1, booleanToByte(true));
31     }
32
33     @Test
34     public void testByteToBoolean() {
35         assertEquals(Boolean.FALSE, byteToBoolean((byte) 0));
36         assertEquals(Boolean.TRUE, byteToBoolean((byte) 1));
37     }
38
39     @Test(expected = IllegalArgumentException.class)
40     public void testByteToBooleanFailed() {
41         byteToBoolean((byte) 123);
42     }
43
44     @Test
45     public void testToString() {
46         final byte[] expected = "test".getBytes();
47         final byte[] cString = new byte[expected.length + 10];
48         System.arraycopy(expected, 0, cString, 0, expected.length);
49         final String jString = toString(cString);
50         assertArrayEquals(expected, jString.getBytes());
51     }
52 }