AccountService { public Account logout(String userId) { logger.debug("AccountService.logout: Logging out account with userId: " + userId); Account account = accounts.findByUserid(userId); if (account != null) { account.setAuthtoken(null); account.setLogoutcount(account.getLogoutcount() + 1); accounts.save(account); logger.info("AccountService.logout: Account logged out: " + account.getUserid()); } else { logger.warn("AccountService.logout: Could not find account to logout with userId: " + userId); } return account; }  Account findAccount(Integer id); Account findAccount(String id); @Cacheable(value = "authorizationCache") Account findAccountprofileByAuthtoken(String token); Integer saveAccount(Account accountRequest); Map<String, Object> login(String username, String password); Account logout(String userId);  }
@Test public void testLogoutNull() { when(repo.findByUserid(ServiceTestConfiguration.USER_ID)).thenReturn(null); Account result = service.logout(ServiceTestConfiguration.USER_ID); assertNull(result); }
@Test public void testLogout() { Account acc = ServiceTestConfiguration.account(); when(repo.findByUserid(ServiceTestConfiguration.USER_ID)).thenReturn(acc); Account result = service.logout(ServiceTestConfiguration.USER_ID); Integer i = Math.addExact(1, ServiceTestConfiguration.LOGOUT_COUNT ); assertEquals(result.getLogoutcount(), i); assertNull(result.getAuthtoken()); }