### Question:
AccountServiceImpl implements AccountService { @Override public AccountResultModel createAccount(final AccountDto accountDto) { final String url = String.format(CREATE_URL, serviceProperties.getAccountServiceUrl(), LocaleContextHolder.getLocale().getLanguage()); try { return restTemplate.postForEntity(url, accountDto, AccountResultModel.class).getBody(); } catch (final Exception ex) { final String errorMessage = String.format("An error occured while creating account %s: %s", accountDto.getUsername(), ex.getMessage()); log.error(errorMessage, ex); throw new AccountPersistenceException(errorMessage, ex); } }  @Override UserDetails authenticate(final String username, final String password); @Override UserDetails loadUserByUsername(final String username); @Override AccountResultModel createAccount(final AccountDto accountDto); @Override AccountResultModel changePassword(final String username, final ChangePasswordModel changePasswordModel);  }### Answer:
@Test public void test_createAccount_success() throws Exception { final AccountResultModel expectedResult = new AccountResultModel(); final AccountDto accountDto = new AccountDto(); final String url = ACCOUNT_SERVICE_URL + ACCOUNT_CREATE_PATH; when(response.getBody()).thenReturn(expectedResult); when(response.getStatusCode()).thenReturn(HttpStatus.OK); when(restTemplate.postForEntity(url, accountDto, AccountResultModel.class)) .thenReturn(response); final AccountResultModel result = accountService.createAccount(accountDto); assertEquals(expectedResult, result); }
@Test(expected = AccountPersistenceException.class) public void test_createAccount_exception() throws Exception { final AccountDto accountDto = new AccountDto(); final String url = ACCOUNT_SERVICE_URL + ACCOUNT_CREATE_PATH; when(restTemplate.postForEntity(url, accountDto, AccountResultModel.class)) .thenThrow(new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR)); accountService.createAccount(accountDto); }