Utils { public static String bitcoinValueToPlainString(BigInteger value) { if (value == null) { throw new IllegalArgumentException("Value cannot be null"); } BigDecimal valueInBTC = new BigDecimal(value).divide(new BigDecimal(Utils.COIN)); return valueInBTC.toPlainString(); }  static BigInteger toNanoCoins(int coins, int cents); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static BigInteger toNanoCoins(String coins); static void uint32ToByteArrayBE(long val, byte[] out, int offset); static void uint32ToByteArrayLE(long val, byte[] out, int offset); static void uint64ToByteArrayLE(long val, byte[] out, int offset); static void uint32ToByteStreamLE(long val, OutputStream stream); static void int64ToByteStreamLE(long val, OutputStream stream); static void uint64ToByteStreamLE(BigInteger val, OutputStream stream); static byte[] doubleDigest(byte[] input); static byte[] scryptDigest(byte[] input); static byte[] doubleDigest(byte[] input, int offset, int length); static byte[] singleDigest(byte[] input, int offset, int length); static byte[] doubleDigestTwoBuffers(byte[] input1, int offset1, int length1,
                                                byte[] input2, int offset2, int length2); static boolean isLessThanUnsigned(long n1, long n2); static String bytesToHexString(byte[] bytes); static byte[] reverseBytes(byte[] bytes); static byte[] reverseDwordBytes(byte[] bytes, int trimLength); static long readUint32(byte[] bytes, int offset); static long readInt64(byte[] bytes, int offset); static long readUint32BE(byte[] bytes, int offset); static int readUint16BE(byte[] bytes, int offset); static byte[] sha256hash160(byte[] input); static String bitcoinValueToFriendlyString(BigInteger value); static String bitcoinValueToPlainString(BigInteger value); static BigInteger decodeMPI(byte[] mpi, boolean hasLength); static byte[] encodeMPI(BigInteger value, boolean includeLength); static BigInteger decodeCompactBits(long compact); static Date rollMockClock(int seconds); static Date rollMockClockMillis(long millis); static void setMockClock(long mockClock); static Date now(); static long currentTimeMillis(); static byte[] copyOf(byte[] in, int length); static byte[] appendByte(byte[] bytes, byte b); static byte[] parseAsHexOrBase58(String data); static boolean isWindows(); static byte[] formatMessageForSigning(String message); static boolean checkBitLE(byte[] data, int index); static void setBitLE(byte[] data, int index); static void sleep(long millis); static void setMockSleep(boolean isEnable); static void passMockSleep(); static void finishMockSleep(); static final BigInteger NEGATIVE_ONE; static final String BITCOIN_SIGNED_MESSAGE_HEADER; static final byte[] BITCOIN_SIGNED_MESSAGE_HEADER_BYTES; static final BigInteger COIN; static final BigInteger CENT; static volatile Date mockTime; }
@Test public void testBitcoinValueToPlainString() { try { bitcoinValueToPlainString(null); org.junit.Assert.fail("Expecting IllegalArgumentException"); } catch (IllegalArgumentException e) { assertTrue(e.getMessage().contains("Value cannot be null")); } assertEquals("0.0015", bitcoinValueToPlainString(BigInteger.valueOf(150000))); assertEquals("1.23", bitcoinValueToPlainString(toNanoCoins("1.23"))); assertEquals("0.1", bitcoinValueToPlainString(toNanoCoins("0.1"))); assertEquals("1.1", bitcoinValueToPlainString(toNanoCoins("1.1"))); assertEquals("21.12", bitcoinValueToPlainString(toNanoCoins("21.12"))); assertEquals("321.123", bitcoinValueToPlainString(toNanoCoins("321.123"))); assertEquals("4321.1234", bitcoinValueToPlainString(toNanoCoins("4321.1234"))); assertEquals("54321.12345", bitcoinValueToPlainString(toNanoCoins("54321.12345"))); assertEquals("654321.123456", bitcoinValueToPlainString(toNanoCoins("654321.123456"))); assertEquals("7654321.1234567", bitcoinValueToPlainString(toNanoCoins("7654321.1234567"))); try { assertEquals("87654321.12345678", bitcoinValueToPlainString(toNanoCoins("87654321.12345678"))); Assert.fail(); } catch (AssertionError e ) {} catch (Exception e) {} assertEquals("1", bitcoinValueToPlainString(toNanoCoins("1.0"))); assertEquals("2", bitcoinValueToPlainString(toNanoCoins("2.00"))); assertEquals("3", bitcoinValueToPlainString(toNanoCoins("3.000"))); assertEquals("4", bitcoinValueToPlainString(toNanoCoins("4.0000"))); assertEquals("5", bitcoinValueToPlainString(toNanoCoins("5.00000"))); assertEquals("6", bitcoinValueToPlainString(toNanoCoins("6.000000"))); assertEquals("7", bitcoinValueToPlainString(toNanoCoins("7.0000000"))); assertEquals("8", bitcoinValueToPlainString(toNanoCoins("8.00000000"))); }