8494568ec8e4b86c7d71058d1a4fc692a95b0af0
[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.hc2vpp.common.translate.util;
18
19 import static org.junit.Assert.assertArrayEquals;
20 import static org.junit.Assert.assertEquals;
21
22 import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
23 import org.junit.Test;
24
25 public class ByteDataTranslatorTest implements ByteDataTranslator {
26
27     @Test
28     public void testBooleanToByte() {
29         assertEquals(0, booleanToByte(null));
30         assertEquals(0, booleanToByte(false));
31         assertEquals(1, booleanToByte(true));
32     }
33
34     @Test
35     public void testByteToBoolean() {
36         assertEquals(Boolean.FALSE, byteToBoolean((byte) 0));
37         assertEquals(Boolean.TRUE, byteToBoolean((byte) 1));
38     }
39
40     @Test(expected = IllegalArgumentException.class)
41     public void testByteToBooleanFailed() {
42         byteToBoolean((byte) 123);
43     }
44
45     @Test
46     public void testToString() {
47         final byte[] expected = "test".getBytes();
48         final byte[] cString = new byte[expected.length + 10];
49         System.arraycopy(expected, 0, cString, 0, expected.length);
50         final String jString = toString(cString);
51         assertArrayEquals(expected, jString.getBytes());
52     }
53 }