@Override public void updateAccount(Account account) { String sqlTxt = "update account set balance = ? where id = ?"; template.update(sqlTxt, account.getBalance(), account.getId()); }
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS) public BigDecimal getBalance(Long id) { return repository.getAccount(id).getBalance(); }
public BigDecimal deposit(Long id, BigDecimal amount) { Account account = repository.getAccount(id); BigDecimal newBalance = account.getBalance().add(amount); account.setBalance(newBalance); repository.updateAccount(account); return newBalance; }
public BigDecimal deposit(Long id, BigDecimal amount) { Account account = repository.findOne(id); BigDecimal newBalance = account.getBalance().add(amount); account.setBalance(newBalance); repository.save(account); return newBalance; }
public BigDecimal deposit(Long id, BigDecimal amount) { Account account = repository.getAccount(id); BigDecimal newBalance = account.getBalance().add(amount); account.setBalance(newBalance); repository.updateAccount(account); return newBalance; }
@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")))); }
@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 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 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 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 { // Make a new account and add it to DB Long id = repository.createAccount(new BigDecimal("250.00")); assertThat(id, is(notNullValue())); // Retrieve the new account and check its properties Account account = repository.getAccount(id); assertThat(account.getId(), is(id)); assertThat(account.getBalance(), is(closeTo(new BigDecimal("250.0"), new BigDecimal("0.01")))); // Delete the account repository.deleteAccount(id); }
@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")))); }