2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.aai.sparky.util;
23 import org.junit.Test;
24 import static org.junit.Assert.assertEquals;
26 * The Class RawByteHelper.
28 public class RawByteHelperTest {
31 public void testDumpBytes() {
33 assertEquals(RawByteHelper.dumpBytes(str.getBytes()),"61 62 63 64 ");
37 // if you're trying to figure out why or's w/ FF's see:
39 public void testBytesToInt() {
40 byte one = 0, two = 0, three = 1, four = 1;
41 assertEquals(RawByteHelper.bytesToInt(one, two, three,four),257);
45 public void testBytesToShort() {
48 assertEquals(RawByteHelper.bytesToShort(a, b), (short)256);
51 // short helper functions
53 public void testFirstByteShort() {
56 assertEquals(RawByteHelper.firstByte(num1),(short)0);
57 assertEquals(RawByteHelper.firstByte(num2),(short)1);
61 public void testFirstByteInt() {
63 assertEquals(RawByteHelper.firstByte(num1),(byte)0);
67 public void testSecondByteShort() {
70 assertEquals(RawByteHelper.secondByte(num1),(byte)num1);
71 assertEquals(RawByteHelper.secondByte(num2),(byte)65);
75 public void testSecondByteInt() {
78 assertEquals(RawByteHelper.secondByte(num1),(byte)0);
79 assertEquals(RawByteHelper.secondByte(num2),(byte)-1);
83 public void thirdByte() {
86 assertEquals(RawByteHelper.thirdByte(num1),(byte)0);
87 assertEquals(RawByteHelper.thirdByte(num2),(byte)-1);
90 public void fourthByte() {
93 assertEquals(RawByteHelper.fourthByte(num1),(byte)123);
94 assertEquals(RawByteHelper.fourthByte(num2),(byte)65);
97 public void intToByte() {
100 assertEquals(RawByteHelper.intToByte(num1),(byte)123);
101 assertEquals(RawByteHelper.intToByte(num2),(byte)65);
104 public void intToShort() {
107 assertEquals(RawByteHelper.intToByte(num1),(short)123);
108 assertEquals(RawByteHelper.intToByte(num2),(short)65);