### Question:
DynamicHexRegexDataHandler extends HexRegexDataHandler { @Override public Optional<byte[]> handle(final byte[] data) { final String encoded = base16().encode(data); final Matcher regexMatcher = hexRegex.matcher(encoded); final boolean matches = regexMatcher.matches(); if (matches) { final int groupCount = regexMatcher.groupCount(); if (groupCount == 0) { return Optional.of(base16().decode(MessageFormat.format(responseDataTemplate, regexMatcher.group()))); } final Object[] groups = new Object[groupCount]; for (int i = 0; i < groupCount; i++) { groups[i] = regexMatcher.group(i + 1); } return Optional.of(base16().decode(MessageFormat.format(responseDataTemplate, groups))); } else { return Optional.empty(); } } DynamicHexRegexDataHandler(final String hexRegex,
                                      final String responseDataTemplate); @Override Optional<byte[]> handle(final byte[] data);  }### Answer:
@Test public void testHandle() { final Optional<byte[]> handleResult = dataHandler.handle(DEFAULT_TEST_DATA); assertThat(handleResult, is(optionalWithValue(equalTo(base16().decode("EEFF1010CCDD"))))); }
@Test public void testHandle_emptyResult() { final Optional<byte[]> handleResult = dataHandler.handle(EMPTY_RESULT_TEST_DATA); assertThat(handleResult, emptyOptional()); }