d8d4cf422144b1e043b12080f0a34e306072724d
[lispflowmapping.git] / mappingservice / lisp-proto / src / test / java / org / opendaylight / lispflowmapping / TestUtils.java
1 /*
2  * Copyright (c) 2023 PANTHEON.tech s.r.o. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.lispflowmapping;
9
10 import static org.junit.Assert.assertEquals;
11
12 import java.nio.ByteBuffer;
13
14 public final class TestUtils {
15
16     private TestUtils() {
17         // utility class
18     }
19
20     public static ByteBuffer hexToByteBuffer(String hex) {
21         String[] hexBytes = hex.split(" ");
22         ByteBuffer bb = ByteBuffer.allocate(hexBytes.length);
23         for (String hexByte : hexBytes) {
24             bb.put((byte) Integer.parseInt(hexByte, 16));
25         }
26         bb.clear();
27         return bb;
28     }
29
30     public static void assertHexEquals(short expected, short actual) {
31         assertEquals(String.format("0x%04X", expected), String.format("0x%04X", actual));
32     }
33
34     public static void assertHexEquals(byte expected, byte actual) {
35         assertEquals(String.format("0x%02X", expected), String.format("0x%02X", actual));
36     }
37 }