BinToHex { public static String toHexFromBytes(final byte[] bytes) { if(bytes == null || bytes.length == 0) { return (""); } StringBuilder hexBuffer = new StringBuilder(bytes.length * 2); for(int i = 0; i < bytes.length; i++) { hexBuffer.append(toHexFromByte(bytes[i])); } return (hexBuffer.toString()); }  static String toHexFromByte(final byte b); static String toHexFromBytes(final byte[] bytes); static byte[] readFile(File file); static void main(final String[] args); final static int BITS_PER_HEX_DIGIT; }
@Test public void testToHexFromBytes(){ byte[] data = {45,67,89}; String hexData=BinToHex.toHexFromBytes(data); Assert.assertEquals("2d4359", hexData); }
@Test public void testToHexFromBytes_bytesEqualNull(){ byte[] data=null; String hexData=BinToHex.toHexFromBytes(data); Assert.assertEquals("", hexData); }
@Test public void testToHexFromBytes_byteslength(){ byte[] data = {}; String hexData=BinToHex.toHexFromBytes(data); Assert.assertEquals("", hexData); }