### Question:
PcapHelper { public static String reverseKey(String key) { Assert.hasText(key, "key must not be null or empty"); String delimeter = HBaseConfigConstants.PCAP_KEY_DELIMETER; String regex = "\\" + delimeter; StringBuffer sb = new StringBuffer(); try { String[] tokens = key.split(regex); Assert .isTrue( (tokens.length == 5 || tokens.length == 6 || tokens.length == 7), "key is not in the format : 'srcAddr-dstAddr-protocol-srcPort-dstPort-{ipId-fragment identifier}'"); sb.append(tokens[1]).append(delimeter).append(tokens[0]) .append(delimeter).append(tokens[2]).append(delimeter) .append(tokens[4]).append(delimeter).append(tokens[3]); } catch (Exception e) { Log.warn("Failed to reverse the key. Reverse scan won't be performed.", e); } return sb.toString(); }  static long convertToDataCreationTimeUnit(long inputTime); @VisibleForTesting static TimeUnit getDataCreationTimeUnit(); @VisibleForTesting static long convertSecondsToDataCreationTimeUnit(long inputTime); static String reverseKey(String key); static List<String> reverseKey(List<String> keys); static CellTimestampComparator getCellTimestampComparator();  }### Answer:
@Test public void test_reverseKey_valid() { String key = "162.242.152.24-162.242.153.12-TCP-38190-9092"; String reversekey = PcapHelper.reverseKey(key); Assert.isTrue("162.242.153.12-162.242.152.24-TCP-9092-38190" .equals(reversekey)); }
@Test public void test_reverseKey_valid_withFragment() { String key = "162.242.152.24-162.242.153.12-TCP-38190-9092-fragmentId"; String reversekey = PcapHelper.reverseKey(key); Assert.isTrue("162.242.153.12-162.242.152.24-TCP-9092-38190" .equals(reversekey)); }
@Test public void test_reverseKey_inValid() { String key = "162.242.152.24-162.242.153.12-TCP-38190-9092-ipId-fragmentId-extra"; String reversekey = PcapHelper.reverseKey(key); Assert.isTrue("".equals(reversekey)); }
@Test public void test_reverseKey_asList() { String[] keys = { "162.242.152.24-162.242.153.12-TCP-38190-9092-fragmentId", "162.242.152.24-162.242.153.12-UDP-38190-9092" }; List<String> reverseKeys = PcapHelper.reverseKey(Arrays.asList(keys)); Assert.isTrue("162.242.153.12-162.242.152.24-TCP-9092-38190" .equals(reverseKeys.get(0))); Assert.isTrue("162.242.153.12-162.242.152.24-UDP-9092-38190" .equals(reverseKeys.get(1))); }