@Hex¶
@Hex is an annotation that decodes hexadecimal String instances into byte[] instances:
import io.github.scordio.junit.converters.Hex;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
@ParameterizedTest
@ValueSource(strings = { "0x0A1B2C", "0A1B2C" })
void test(@Hex byte[] bytes) {
assertArrayEquals(new byte[] { 0x0A, 0x1B, 0x2C }, bytes);
}
The input strings are treated as case-insensitive and can be prefixed by 0x.
The following source types and target declarations are supported.
| Source Type | Target Declaration | Example |
|---|---|---|
String |
@Hex byte[] |
"0A1B2C"/"0a1b2c"/"0x0A1B2C"/"0x0a1b2c" → new byte[] { 0x0A, 0x1B, 0x2C } |