/** * Creates a matcher of {@link java.math.BigDecimal}s that matches when an examined BigDecimal is equal * to the specified <code>operand</code>, within a range of +/- <code>error</code>. The comparison for equality * is done by BigDecimals {@link java.math.BigDecimal#compareTo(java.math.BigDecimal)} method. * <p/> * For example: * <pre>assertThat(new BigDecimal("1.03"), is(closeTo(new BigDecimal("1.0"), new BigDecimal("0.03"))))</pre> * * @param operand * the expected value of matching BigDecimals * @param error * the delta (+/-) within which matches will be allowed */ public static org.hamcrest.Matcher<java.math.BigDecimal> closeTo(java.math.BigDecimal operand, java.math.BigDecimal error) { return org.hamcrest.number.BigDecimalCloseTo.closeTo(operand, error); }
/** * Creates a matcher of {@link java.math.BigDecimal}s that matches when an examined BigDecimal is equal * to the specified <code>operand</code>, within a range of +/- <code>error</code>. The comparison for equality * is done by BigDecimals {@link java.math.BigDecimal#compareTo(java.math.BigDecimal)} method. * For example: * <pre>assertThat(new BigDecimal("1.03"), is(closeTo(new BigDecimal("1.0"), new BigDecimal("0.03"))))</pre> * * @param operand * the expected value of matching BigDecimals * @param error * the delta (+/-) within which matches will be allowed */ public static org.hamcrest.Matcher<java.math.BigDecimal> closeTo(java.math.BigDecimal operand, java.math.BigDecimal error) { return org.hamcrest.number.BigDecimalCloseTo.closeTo(operand, error); }
@Override protected Matcher<?> createMatcher() { BigDecimal irrelevant = new BigDecimal("0.01"); return closeTo(irrelevant, irrelevant); }
/** * Creates a matcher of {@link java.math.BigDecimal}s that matches when an examined BigDecimal is equal * to the specified <code>operand</code>, within a range of +/- <code>error</code>. The comparison for equality * is done by BigDecimals {@link java.math.BigDecimal#compareTo(java.math.BigDecimal)} method. * For example: * <pre>assertThat(new BigDecimal("1.03"), is(closeTo(new BigDecimal("1.0"), new BigDecimal("0.03"))))</pre> * * @param operand * the expected value of matching BigDecimals * @param error * the delta (+/-) within which matches will be allowed */ public static org.hamcrest.Matcher<java.math.BigDecimal> closeTo(java.math.BigDecimal operand, java.math.BigDecimal error) { return org.hamcrest.number.BigDecimalCloseTo.closeTo(operand, error); }
@Test public void testDeposit() throws Exception { BigDecimal start = service.getBalance(1L); BigDecimal amount = new BigDecimal("50.0"); service.deposit(1L, amount); BigDecimal finish = start.add(amount); assertThat(finish, is(closeTo(service.getBalance(1L), new BigDecimal("0.01")))); }
@Test public void testWithdraw() throws Exception { BigDecimal start = service.getBalance(1L); BigDecimal amount = new BigDecimal("50.0"); service.withdraw(1L, amount); BigDecimal finish = start.subtract(amount); assertThat(finish, is(closeTo(service.getBalance(1L), new BigDecimal("0.01")))); }
@Test public void testDeposit() throws Exception { BigDecimal start = service.getBalance(1L); BigDecimal amount = new BigDecimal("50.0"); service.deposit(1L, amount); BigDecimal finish = start.add(amount); assertThat(finish, is(closeTo(service.getBalance(1L), new BigDecimal("0.01")))); }
@Test public void testWithdraw() throws Exception { BigDecimal start = service.getBalance(1L); BigDecimal amount = new BigDecimal("50.0"); service.withdraw(1L, amount); BigDecimal finish = start.subtract(amount); assertThat(finish, is(closeTo(service.getBalance(1L), new BigDecimal("0.01")))); }
@Test public void testWithdraw() throws Exception { BigDecimal start = service.getBalance(1L); BigDecimal amount = new BigDecimal("50.0"); service.withdraw(1L, amount); BigDecimal finish = start.subtract(amount); assertThat(finish, is(closeTo(service.getBalance(1L), new BigDecimal("0.01")))); }
@Test public void testDeposit() throws Exception { BigDecimal start = service.getBalance(1L); BigDecimal amount = new BigDecimal("50.0"); service.deposit(1L, amount); BigDecimal finish = start.add(amount); assertThat(finish, is(closeTo(service.getBalance(1L), new BigDecimal("0.01")))); }
@Test public void testGetAccount() throws Exception { Account account = repository.getAccount(1L); assertThat(account.getId(), is(1L)); assertThat(new BigDecimal("100.0"), is(closeTo(account.getBalance(), new BigDecimal("0.01")))); }
@Test public void testGetAccount() throws Exception { Account account = repository.findOne(1L); assertThat(account.getId(), is(1L)); assertThat(new BigDecimal("100.0"), is(closeTo(account.getBalance(), new BigDecimal("0.01")))); }
@Test public void testCreateAccount() throws Exception { Long id = repository.createAccount(new BigDecimal("250.00")); assertThat(id, is(notNullValue())); Account account = repository.getAccount(id); assertThat(account.getId(), is(id)); assertThat(account.getBalance(), is(closeTo(new BigDecimal("250.0"), new BigDecimal("0.01")))); }
@Test public void testCreateAccount() throws Exception { Long id = repository.createAccount(new BigDecimal("250.00")); assertThat(id, is(notNullValue())); Account account = repository.getAccount(id); assertThat(account.getId(), is(id)); assertThat(account.getBalance(), is(closeTo(new BigDecimal("250.0"), new BigDecimal("0.01")))); }
@Test public void testGetAccount() throws Exception { Account account = repository.getAccount(1L); assertThat(account.getId(), is(1L)); assertThat(new BigDecimal("100.0"), is(closeTo(account.getBalance(), new BigDecimal("0.01")))); }
@Test public void testGetAccount() throws Exception { Account account = repository.findOne(1L); assertThat(account.getId(), is(1L)); assertThat(new BigDecimal("100.0"), is(closeTo(account.getBalance(), new BigDecimal("0.01")))); }
@Test public void testCreateAccount() throws Exception { Account account = new Account(99L, new BigDecimal("250.00")); repository.save(account); Long id = account.getId(); assertThat(id, is(notNullValue())); Account again = repository.findOne(id); assertThat(again.getId(), is(id)); assertThat(again.getBalance(), is(closeTo(new BigDecimal("250.0"), new BigDecimal("0.01")))); }
@Test public void testUpdateAccount() throws Exception { Account account = repository.findOne(1L); BigDecimal current = account.getBalance(); BigDecimal amount = new BigDecimal("50.0"); account.setBalance(current.add(amount)); repository.save(account); Account again = repository.findOne(1L); assertThat(again.getBalance(), is(closeTo(current.add(amount), new BigDecimal("0.01")))); }
@Test public void testUpdateAccount() throws Exception { Account account = repository.getAccount(1L); BigDecimal current = account.getBalance(); BigDecimal amount = new BigDecimal("50.0"); account.setBalance(current.add(amount)); repository.updateAccount(account); Account again = repository.getAccount(1L); assertThat(again.getBalance(), is(closeTo(current.add(amount), new BigDecimal("0.01")))); }
@Test public void testUpdateAccount() throws Exception { Account account = repository.getAccount(1L); BigDecimal current = account.getBalance(); BigDecimal amount = new BigDecimal("50.0"); account.setBalance(current.add(amount)); repository.updateAccount(account); Account again = repository.getAccount(1L); assertThat(again.getBalance(), is(closeTo(current.add(amount), new BigDecimal("0.01")))); }