TransportUtils { public static ByteString copyFrom(final byte[] rawBytes) { if (null == rawBytes || 0 == rawBytes.length) { return ByteString.EMPTY; } return ByteString.copyFrom(rawBytes); } private  TransportUtils(); static ByteString copyFrom(final byte[] rawBytes); static ByteString copyFrom(final BytesValue bytesValue); static ByteString copyFrom(final Aer aer); static ByteString copyFrom(final long longValue); static BytesValue parseToBytesValue(final ByteString bytesString); static Aer parseToAer(final byte[] rawAer); static Aer parseToAer(final ByteString rawAer); static TxHash parseToTxHash(final ByteString byteString); static BlockHash parseToBlockHash(final ByteString byteString); static String sha256AndEncodeHexa(final String string); static String sha256AndEncodeHexa(final byte[] rawBytes);  }
@Test public void testCopyFromWithRawBytes() { final byte[] filledValue = randomUUID().toString().getBytes(); final byte[] emptyValue = new byte[0]; final byte[] nullValue = null; assertEquals(ByteString.copyFrom(filledValue), copyFrom(filledValue)); assertEquals(ByteString.EMPTY, copyFrom(emptyValue)); assertEquals(ByteString.EMPTY, copyFrom(nullValue)); }
@Test public void testCopyFromWithBytesValue() { final BytesValue filledValue = BytesValue.of(randomUUID().toString().getBytes()); final BytesValue emptyValue = BytesValue.EMPTY; ; final BytesValue nullValue = null; assertEquals(ByteString.copyFrom(filledValue.getValue()), copyFrom(filledValue)); assertEquals(ByteString.EMPTY, copyFrom(emptyValue)); assertEquals(ByteString.EMPTY, copyFrom(nullValue)); }
@Test public void testCopyFromWithAer() { final Aer filledValue = Aer.of("100", Unit.AERGO); final Aer nullValue = null; assertEquals(ByteString.copyFrom(positiveToByteArray(filledValue.getValue())), copyFrom(filledValue)); assertEquals(ByteString.EMPTY, copyFrom(nullValue)); }
@Test public void testCopyFromWithLong() { final ByteString expected = ByteString.copyFrom(new byte[]{0x7f, 0x6f, 0x5f, 0x4f, 0x3f, 0x2f, 0x1f, 0x0f}); ByteString actual = copyFrom(Long.decode("0x0f1f2f3f4f5f6f7f").longValue()); assertEquals(expected, actual); }