UserService { public User logout(String userId) { logger.debug("UserService.logout: Logging out account with userId: " + userId); User account = user.findByUserid(userId); if (account != null) { account.setAuthtoken(null); account.setLogoutcount(account.getLogoutcount() + 1); user.save(account); logger.info("UserService.logout: Account logged out: " + account.getUserid()); } else { logger.warn("UserService.logout: Could not find account to logout with userId: " + userId); } return account; }  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 testLogoutNull() { when(repo.findByUserid(ServiceTestConfiguration.USER_ID)).thenReturn(null); User result = service.logout(ServiceTestConfiguration.USER_ID); assertNull(result); }
@Test public void testLogout() { User acc = ServiceTestConfiguration.user(); when(repo.findByUserid(ServiceTestConfiguration.USER_ID)).thenReturn(acc); User result = service.logout(ServiceTestConfiguration.USER_ID); Integer i = Math.addExact(1, ServiceTestConfiguration.LOGOUT_COUNT ); assertEquals(result.getLogoutcount(), i); assertNull(result.getAuthtoken()); }