### Question:
SpringSessionBackedSessionRegistry implements SessionRegistry { @Override public List<SessionInformation> getAllSessions(Object principal, boolean includeExpiredSessions) { Collection<S> sessions = this.sessionRepository.findByPrincipalName(name(principal)).values(); List<SessionInformation> infos = new ArrayList<>(); for (S session : sessions) { if (includeExpiredSessions || !Boolean.TRUE.equals(session.getAttribute(SpringSessionBackedSessionInformation.EXPIRED_ATTR))) { infos.add(new SpringSessionBackedSessionInformation<>(session, this.sessionRepository)); } } return infos; } SpringSessionBackedSessionRegistry(FindByIndexNameSessionRepository<S> sessionRepository); @Override List<Object> getAllPrincipals(); @Override List<SessionInformation> getAllSessions(Object principal, boolean includeExpiredSessions); @Override SessionInformation getSessionInformation(String sessionId); @Override void refreshLastRequest(String sessionId); @Override void registerNewSession(String sessionId, Object principal); @Override void removeSessionInformation(String sessionId);  }### Answer:
@Test void getAllSessionsForUserDetails() { setUpSessions(); List<SessionInformation> allSessionInfos = this.sessionRegistry.getAllSessions(PRINCIPAL, true); assertThat(allSessionInfos).extracting("sessionId").containsExactly(SESSION_ID, SESSION_ID2); }
@Test void getAllSessionsForAuthenticatedPrincipal() { setUpSessions(); List<SessionInformation> allSessionInfos = this.sessionRegistry .getAllSessions((AuthenticatedPrincipal) () -> USER_NAME, true); assertThat(allSessionInfos).extracting("sessionId").containsExactly(SESSION_ID, SESSION_ID2); }
@Test void getAllSessionsForPrincipal() { setUpSessions(); List<SessionInformation> allSessionInfos = this.sessionRegistry.getAllSessions(new TestPrincipal(USER_NAME), true); assertThat(allSessionInfos).extracting("sessionId").containsExactly(SESSION_ID, SESSION_ID2); }
@Test void getNonExpiredSessions() { setUpSessions(); List<SessionInformation> nonExpiredSessionInfos = this.sessionRegistry.getAllSessions(PRINCIPAL, false); assertThat(nonExpiredSessionInfos).extracting("sessionId").containsExactly(SESSION_ID2); }