2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ============LICENSE_END=========================================================
23 package org.onap.appc.encryption;
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;
30 import java.util.List;
31 import org.junit.Test;
33 public class HexHelperTest {
35 private final List<Character> hexChars =
36 newArrayList('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B','C', 'D', 'E', 'F');
38 @Test(expected = EncryptionException.class)
39 public void convertHexToBytes_should_throw_given_null() throws EncryptionException {
41 HexHelper.convertHexToBytes(null);
44 @Test(expected = EncryptionException.class)
45 public void convertHexToBytes_should_throw_given_non_hexadecimal_string() throws EncryptionException {
47 HexHelper.convertHexToBytes("125FET4A");
51 public void convertHexToBytes_should_convert_hexadecimal_string_to_byte_array() throws EncryptionException {
53 byte[] result = HexHelper.convertHexToBytes("125FE4A");
55 assertNotEquals(0, result.length);
59 @Test(expected = EncryptionException.class)
60 public void convertBytesToHex_should_throw_given_null() throws EncryptionException {
62 HexHelper.convertBytesToHex(null);
67 public void convertBytesToHex_should_convert_byte_array_to_hexadecimal_string() throws EncryptionException {
69 String resultString = HexHelper.convertBytesToHex(new byte[]{24, -1, 85, 99});
70 for (char ch : resultString.toCharArray()) {
71 assertTrue(hexChars.contains(ch));
74 byte[] resultArray = HexHelper.convertHexToBytes("A56C9ED17");
75 assertEquals("0A56C9ED17", HexHelper.convertBytesToHex(resultArray));