only:covering current implementation

This commit is contained in:
rusefillc 2023-07-09 18:37:14 -04:00
parent 48ee5abec7
commit da0fe3ba15
2 changed files with 25 additions and 1 deletions

View File

@ -11,7 +11,7 @@ public class HexUtil {
return hexToBytes(hex);
}
private static byte[] hexToBytes(String s) {
public static byte[] hexToBytes(String s) {
return hexToBytes(s, 0);
}

View File

@ -0,0 +1,24 @@
package com.rusefi.io.can;
import org.junit.Test;
import static org.junit.Assert.assertArrayEquals;
public class HexUtilTest {
@Test
public void decodeSimple() {
byte[] pa = HexUtil.hexToBytes("abcd");
assertArrayEquals(new byte[]{(byte) 0xab, (byte) 0xcd}, pa);
}
@Test
public void decodeUneven() {
byte[] pa = HexUtil.hexToBytes("1abcd");
assertArrayEquals(new byte[]{1, (byte) 0xab, (byte) 0xcd}, pa);
}
@Test(expected = NumberFormatException.class)
public void unexpected() {
HexUtil.hexToBytes("0xff");
}
}