2 * Copyright (c) 2016 Cisco and/or its affiliates.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package io.fd.honeycomb.translate.vpp.util;
19 import static org.junit.Assert.assertArrayEquals;
20 import static org.junit.Assert.assertEquals;
22 import org.junit.Test;
24 public class ByteDataTranslatorTest implements ByteDataTranslator {
27 public void testBooleanToByte() {
28 assertEquals(0, booleanToByte(null));
29 assertEquals(0, booleanToByte(false));
30 assertEquals(1, booleanToByte(true));
34 public void testByteToBoolean() {
35 assertEquals(Boolean.FALSE, byteToBoolean((byte) 0));
36 assertEquals(Boolean.TRUE, byteToBoolean((byte) 1));
39 @Test(expected = IllegalArgumentException.class)
40 public void testByteToBooleanFailed() {
41 byteToBoolean((byte) 123);
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());