ByteTranslator { public abstract byte[] translate(String s) throws IOException; ByteTranslator(); abstract byte[] translate(String s); abstract String translate(byte[] bytes);  }
@Test public void testBase64Translator() throws Exception { ByteTranslator b = new Base64ByteTranslator(); String uniq = new GuidGenerator().getUUID(); String base64String = new String(Conversion.byteArrayToBase64String(uniq .getBytes())); byte[] bytes = b.translate(base64String); String result = b.translate(bytes); assertEquals(base64String, result); }
@Test public void testCharsetByteTranslatorUsingIso8859() throws Exception { CharsetByteTranslator b = new CharsetByteTranslator("ISO-8859-1"); String uniq = new GuidGenerator().getUUID(); byte[] bytes = b.translate(uniq); String result = b.translate(bytes); assertEquals(uniq, result); assertEquals("ISO-8859-1", b.getCharsetEncoding()); }
@Test public void testCharsetByteTranslator() throws Exception { CharsetByteTranslator b = new CharsetByteTranslator(); String uniq = new GuidGenerator().getUUID(); byte[] bytes = b.translate(uniq); String result = b.translate(bytes); assertEquals("UTF-8", b.getCharsetEncoding()); assertEquals(uniq, result); }
@Test public void testSimpleByteTranslator() throws Exception { ByteTranslator b = new SimpleByteTranslator(); String uniq = new GuidGenerator().getUUID(); byte[] bytes = b.translate(uniq); String result = b.translate(bytes); assertEquals(uniq, result); }
@Test public void testHexstringByteTranslator() throws Exception { ByteTranslator b = new HexStringByteTranslator(); byte[] uniq = new GuidGenerator().getUUID().getBytes(StandardCharsets.UTF_8); assertTrue(MessageDigest.isEqual(uniq, b.translate(b.translate(uniq)))); }