UserSessionAssist implements ResponseContextCodes { public User expectedUser(String userName) throws GameBootRuntimeException { userNameCheck(userName); User user = userRepo.findByUserName(userName); check(NO_USER_RECORD, user == null, "No user for " + userName); return user; }  @PostConstruct void postConstruct(); UserSession create(User user); User expectedUser(String userName); UserSession expected(String userName); UserSession expected(User user); UserSession expected(Long id); boolean hasSession(String userName); boolean hasSession(Long id); User logout(String userName); User logout(Long id); @Cacheable(cacheNames = SESSIONS_CACHE, key = "target.sessionsKey") List<UserSession> activeSessions(); String getSessionsKey(); static final String SESSIONS_CACHE; static final String SESSIONS_KEY; }
@Test @Transactional public void testExpectedUser() throws Exception { gameBootExpected(() -> assist.expectedUser(null), "Null user name"); gameBootExpected(() -> assist.expectedUser(" "), "Blank user name"); gameBootExpected(() -> assist.expectedUser(NON_EXISTENT), "non existent user name"); User user = assist.expectedUser(USER_NAME); assertEquals(userId, user.getId()); }