[AAI-2531] | Update springboot to 2.1.12.RELEASE
[aai/sparky-be.git] / sparkybe-onap-service / src / test / java / org / onap / aai / sparky / util / RawByteHelperTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21 package org.onap.aai.sparky.util;
22
23 import org.junit.Test;
24 import static org.junit.Assert.assertEquals;
25 /**
26  * The Class RawByteHelper.
27  */
28 public class RawByteHelperTest {
29
30   @Test
31   public void testDumpBytes() {
32     String str = "abcd";
33     assertEquals(RawByteHelper.dumpBytes(str.getBytes()),"61 62 63 64 ");
34
35   }
36
37   // if you're trying to figure out why or's w/ FF's see:
38   @Test
39   public void testBytesToInt() {
40     byte one = 0, two = 0, three = 1, four = 1;
41     assertEquals(RawByteHelper.bytesToInt(one, two, three,four),257);
42   }
43
44   @Test
45   public void testBytesToShort() {
46     byte a = 1;
47     byte b = 0;
48     assertEquals(RawByteHelper.bytesToShort(a, b), (short)256);
49   }
50
51   // short helper functions
52   @Test
53   public void testFirstByteShort() {
54     short num1 = 123;
55     short num2 = 321;
56     assertEquals(RawByteHelper.firstByte(num1),(short)0);
57     assertEquals(RawByteHelper.firstByte(num2),(short)1);
58   }
59
60   @Test
61   public void testFirstByteInt() {
62     int num1 = 123;
63     assertEquals(RawByteHelper.firstByte(num1),(byte)0);
64   }
65
66   @Test
67   public void testSecondByteShort() {
68     short num1 = 123;
69     short num2 = 321;
70     assertEquals(RawByteHelper.secondByte(num1),(byte)num1);
71     assertEquals(RawByteHelper.secondByte(num2),(byte)65);
72   }
73
74   @Test
75   public void testSecondByteInt() {
76     int num1 = 123;
77     int num2 = -123;
78     assertEquals(RawByteHelper.secondByte(num1),(byte)0);
79     assertEquals(RawByteHelper.secondByte(num2),(byte)-1);
80   }
81
82    @Test
83    public void thirdByte() {
84     int num1 = 123;
85     int num2 = -123;
86     assertEquals(RawByteHelper.thirdByte(num1),(byte)0);
87     assertEquals(RawByteHelper.thirdByte(num2),(byte)-1);
88   }
89   @Test
90   public void fourthByte() {
91     int num1 = 123;
92     int num2 = 321;
93     assertEquals(RawByteHelper.fourthByte(num1),(byte)123);
94     assertEquals(RawByteHelper.fourthByte(num2),(byte)65);
95   }
96   @Test
97   public void intToByte() {
98     int num1 = 123;
99     int num2 = 321;
100     assertEquals(RawByteHelper.intToByte(num1),(byte)123);
101     assertEquals(RawByteHelper.intToByte(num2),(byte)65);
102   }
103   @Test
104   public void intToShort() {
105     int num1 = 123;
106     int num2 = 321;
107     assertEquals(RawByteHelper.intToByte(num1),(short)123);
108     assertEquals(RawByteHelper.intToByte(num2),(short)65);
109   }
110
111 }
112