More license header updates to appc-common files
[appc.git] / appc-common / src / test / java / org / onap / appc / encryption / HexHelperTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2018 Nokia Solutions and Networks
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * 
21  * ============LICENSE_END=========================================================
22  */
23 package org.onap.appc.encryption;
24
25 import static com.google.common.collect.Lists.newArrayList;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertNotEquals;
28 import static org.junit.Assert.assertTrue;
29
30 import java.util.List;
31 import org.junit.Test;
32
33 public class HexHelperTest {
34
35     private final List<Character> hexChars =
36         newArrayList('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B','C', 'D', 'E', 'F');
37
38     @Test(expected = EncryptionException.class)
39     public void convertHexToBytes_should_throw_given_null() throws EncryptionException {
40
41         HexHelper.convertHexToBytes(null);
42     }
43
44     @Test(expected = EncryptionException.class)
45     public void convertHexToBytes_should_throw_given_non_hexadecimal_string() throws EncryptionException {
46
47         HexHelper.convertHexToBytes("125FET4A");
48     }
49
50     @Test
51     public void convertHexToBytes_should_convert_hexadecimal_string_to_byte_array() throws EncryptionException {
52
53         byte[] result = HexHelper.convertHexToBytes("125FE4A");
54
55         assertNotEquals(0, result.length);
56     }
57
58
59     @Test(expected = EncryptionException.class)
60     public void convertBytesToHex_should_throw_given_null() throws EncryptionException {
61
62         HexHelper.convertBytesToHex(null);
63     }
64
65
66     @Test
67     public void convertBytesToHex_should_convert_byte_array_to_hexadecimal_string() throws EncryptionException {
68
69         String resultString = HexHelper.convertBytesToHex(new byte[]{24, -1, 85, 99});
70         for (char ch : resultString.toCharArray()) {
71             assertTrue(hexChars.contains(ch));
72         }
73
74         byte[] resultArray = HexHelper.convertHexToBytes("A56C9ED17");
75         assertEquals("0A56C9ED17", HexHelper.convertBytesToHex(resultArray));
76     }
77
78 }