Skip to content

Commit

Permalink
account service fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sqshq committed Feb 15, 2016
1 parent b892e94 commit 3b71038
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ public void saveChanges(String name, Account update) {

repository.save(account);

statisticsClient.updateStatistics(name, account);
try {
statisticsClient.updateStatistics(name, account);
} catch (Exception e) {
log.error("error during statistics update", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,26 @@ public void shouldFailWhenNameIsEmpty() {
accountService.findByName("");
}

@Test
public void shouldCreateAccountWithGivenUser() {

User user = new User();
user.setUsername("test");

Account account = accountService.create(user);

assertEquals(user.getUsername(), account.getName());
assertEquals(0, account.getSaving().getAmount().intValue());
assertEquals(Currency.getDefault(), account.getSaving().getCurrency());
assertEquals(0, account.getSaving().getInterest().intValue());
assertEquals(false, account.getSaving().getDeposit());
assertEquals(false, account.getSaving().getCapitalization());
assertNotNull(account.getLastSeen());

verify(authClient, times(1)).createUser(user);
verify(repository, times(1)).save(account);
}

@Test
public void shouldSaveChangesWhenUpdatedAccountGiven() {

Expand Down Expand Up @@ -146,22 +166,14 @@ public void shouldFailWhenNoAccountsExistedWithGivenName() {
}

@Test
public void shouldCreateAccountWithGivenUser() {

User user = new User();
user.setUsername("test");

Account account = accountService.create(user);
public void shouldNotFailOnStatisticsClientException() {
final Account update = new Account();
update.setIncomes(Arrays.asList(new Item()));
update.setExpenses(Arrays.asList(new Item()));

assertEquals(user.getUsername(), account.getName());
assertEquals(0, account.getSaving().getAmount().intValue());
assertEquals(Currency.getDefault(), account.getSaving().getCurrency());
assertEquals(0, account.getSaving().getInterest().intValue());
assertEquals(false, account.getSaving().getDeposit());
assertEquals(false, account.getSaving().getCapitalization());
assertNotNull(account.getLastSeen());
when(accountService.findByName("test")).thenReturn(new Account());
doThrow(RuntimeException.class).when(statisticsClient).updateStatistics(any(), any());

verify(authClient, times(1)).createUser(user);
verify(repository, times(1)).save(account);
accountService.saveChanges("test", update);
}
}

0 comments on commit 3b71038

Please sign in to comment.