@Test void shouldReturnNull() { final Session expiredSession = createSession(Instant.EPOCH); final SessionManager delegate = mock(SessionManager.class); when(delegate.get(any())).thenReturn(CompletableFuture.completedFuture(expiredSession)); final ExpiredSessionDeletingSessionManager manager = new ExpiredSessionDeletingSessionManager(delegate); assertThat(manager.get("id").join()).isNull(); }
@Override public CompletableFuture<Session> get(String sessionId) { return super.get(sessionId).thenApply(session -> { if (session != null) { if (Instant.now().isBefore(session.expirationTime())) { return session; } delete(sessionId); } return null; }); }
ExpiredSessionDeletingSessionManager extends ForwardingSessionManager { @Override public CompletableFuture<Session> get(String sessionId) { return super.get(sessionId).thenApply(session -> { if (session != null) { if (Instant.now().isBefore(session.expirationTime())) { return session; } delete(sessionId); } return null; }); } }
ExpiredSessionDeletingSessionManager extends ForwardingSessionManager { @Override public CompletableFuture<Session> get(String sessionId) { return super.get(sessionId).thenApply(session -> { if (session != null) { if (Instant.now().isBefore(session.expirationTime())) { return session; } delete(sessionId); } return null; }); } ExpiredSessionDeletingSessionManager(SessionManager delegate); }
ExpiredSessionDeletingSessionManager extends ForwardingSessionManager { @Override public CompletableFuture<Session> get(String sessionId) { return super.get(sessionId).thenApply(session -> { if (session != null) { if (Instant.now().isBefore(session.expirationTime())) { return session; } delete(sessionId); } return null; }); } ExpiredSessionDeletingSessionManager(SessionManager delegate); @Override CompletableFuture<Session> get(String sessionId); }
ExpiredSessionDeletingSessionManager extends ForwardingSessionManager { @Override public CompletableFuture<Session> get(String sessionId) { return super.get(sessionId).thenApply(session -> { if (session != null) { if (Instant.now().isBefore(session.expirationTime())) { return session; } delete(sessionId); } return null; }); } ExpiredSessionDeletingSessionManager(SessionManager delegate); @Override CompletableFuture<Session> get(String sessionId);  }