fabf9e87aaa4198e944f6eb9865b7b4687bebfa9
[hc2vpp.git] /
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 /**
25  * Created by jsrnicek on 23.9.2016.
26  */
27 public class ByteDataTranslatorTest implements ByteDataTranslator {
28
29     @Test
30     public void testBooleanToByte() {
31         assertEquals(0, booleanToByte(null));
32         assertEquals(0, booleanToByte(false));
33         assertEquals(1, booleanToByte(true));
34     }
35
36     @Test
37     public void testByteToBoolean() {
38         assertEquals(Boolean.FALSE, byteToBoolean((byte) 0));
39         assertEquals(Boolean.TRUE, byteToBoolean((byte) 1));
40     }
41
42     @Test(expected = IllegalArgumentException.class)
43     public void testByteToBooleanFailed() {
44         byteToBoolean((byte) 123);
45     }
46
47     @Test
48     public void testToString() {
49         final byte[] expected = "test".getBytes();
50         final byte[] cString = new byte[expected.length + 10];
51         System.arraycopy(expected, 0, cString, 0, expected.length);
52         final String jString = toString(cString);
53         assertArrayEquals(expected, jString.getBytes());
54     }
55 }