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.hc2vpp.common.translate.util;
19 import static org.junit.Assert.assertArrayEquals;
20 import static org.junit.Assert.assertEquals;
22 import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
23 import org.junit.Test;
25 public class ByteDataTranslatorTest implements ByteDataTranslator {
28 public void testBooleanToByte() {
29 assertEquals(0, booleanToByte(null));
30 assertEquals(0, booleanToByte(false));
31 assertEquals(1, booleanToByte(true));
35 public void testByteToBoolean() {
36 assertEquals(Boolean.FALSE, byteToBoolean((byte) 0));
37 assertEquals(Boolean.TRUE, byteToBoolean((byte) 1));
40 @Test(expected = IllegalArgumentException.class)
41 public void testByteToBooleanFailed() {
42 byteToBoolean((byte) 123);
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());