UserService { public Integer saveUser(User userRequest) { logger.debug("UserService.saveAccount:" + userRequest.toString()); if (userRequest.getLogincount() == null) { userRequest.setLogincount(0); } if (userRequest.getLogoutcount() == null) { userRequest.setLogoutcount(0); } User account = user.save(userRequest); logger.info("UserService.saveAccount: account saved: " + account); return account.getId(); }  User findUser(Integer id); User findUser(String username); @Cacheable(value = "authorizationCache") User findAccountprofileByAuthtoken(String token); Integer saveUser(User userRequest); Map<String, Object> login(String username, String password); User logout(String userId);  }
@Test public void saveAccount() { User acc = ServiceTestConfiguration.user(); when(repo.save(acc)).thenReturn(acc); assertEquals(service.saveUser(acc),acc.getId()); }
@Test public void saveAccountWithNullCounts() { User acc = ServiceTestConfiguration.user(); User accNull = ServiceTestConfiguration.user(); accNull.setLogincount(null); accNull.setLogoutcount(null); acc.setLogincount(0); acc.setLogoutcount(0); when(repo.save(accNull)).thenReturn(acc); assertEquals(service.saveUser(accNull),acc.getId()); }