Aer implements Comparable<Aer> { public static Aer of(final String amount) { return new Aer(amount); } Aer(final String amount);  Aer(final String amount, final Unit unit);  Aer(final BigInteger amount); protected  Aer(); static Aer of(final String amount); static Aer of(final String amount, final Unit unit); static Aer of(final BigInteger amount); Aer add(final Aer other); Aer subtract(final Aer other); @Override int compareTo(final Aer other); @Override String toString(); String toString(final Unit unit); static final String EMPTY_STRING; static final Aer EMPTY; static final Aer ZERO; static final Aer ONE; static final Aer GIGA_ONE; static final Aer AERGO_ONE; }
@Test public void testCreateWithUnit() { final Object[][] testParameters = new Object[][] { {"0", Unit.AER, valueOf(0L)}, {"1", Unit.AER, valueOf(1L)}, {"10", Unit.AER, valueOf(10L)}, {"0.000000001", Unit.GAER, valueOf(1L)}, {"0.01", Unit.GAER, valueOf(10000000L)}, {"0", Unit.GAER, valueOf(0L)}, {"1", Unit.GAER, valueOf(1000000000L)}, {"10", Unit.GAER, valueOf(10000000000L)}, {"10.1", Unit.GAER, valueOf(10100000000L)}, {"0.000000000000000001", Unit.AERGO, valueOf(1L)}, {"0.01", Unit.AERGO, new BigInteger("10000000000000000")}, {"0", Unit.AERGO, new BigInteger("0")}, {"1", Unit.AERGO, new BigInteger("1000000000000000000")}, {"10", Unit.AERGO, new BigInteger("10000000000000000000")}, {"10.1", Unit.AERGO, new BigInteger("10100000000000000000")} }; for (final Object[] testParameter : testParameters) { final String amount = (String) testParameter[0]; final Aer.Unit unit = (Aer.Unit) testParameter[1]; final BigInteger expected = (BigInteger) testParameter[2]; logger.debug("Amount: {}, Unit: {}, expected: {}", amount, unit, expected); final BigInteger aer = Aer.of(amount, unit).getValue(); assertEquals(expected, aer); } }
@Test public void testInvalidFormatAmount() { final Object[][] testParameters = new Object[][] { {"0.1", Unit.AER}, {"-1", Unit.AER}, {"-0.000000001", Unit.GAER}, {"0.0000000001", Unit.GAER}, {"0.0000000009", Unit.GAER}, {"-0.000000000000000001", Unit.AERGO}, {"0.0000000000000000001", Unit.AERGO}, {"0.0000000000000000009", Unit.AERGO}, {"1+0", Unit.AER}, {"1+0", Unit.GAER}, {"1+0", Unit.AERGO} }; for (final Object[] testParameter : testParameters) { final String amount = (String) testParameter[0]; final Unit unit = (Unit) testParameter[1]; try { Aer.of(amount, unit); fail(String.format("Should throw exception on Amount: %s, Unit: %s", amount, unit)); } catch (Exception e) { } } }