LocalSessionStore implements SessionStore { @Override public Map<String, String> getAndRefresh(String sessionId, String domain, Duration sessionTimeout) { SessionValue sessionValue = values.get(sessionId); if (sessionValue == null) return null; if (Instant.now().isAfter(sessionValue.expirationTime)) { values.remove(sessionId); return null; } Map<String, String> sessionValues = sessionValue.values; values.put(sessionId, new SessionValue(expirationTime(sessionTimeout), sessionValues)); return sessionValues; }  @Override Map<String, String> getAndRefresh(String sessionId, String domain, Duration sessionTimeout); @Override void save(String sessionId, String domain, Map<String, String> values, Set<String> changedFields, Duration sessionTimeout); @Override void invalidate(String sessionId, String domain); @Override void invalidateByKey(String key, String value); void cleanup();  }
@Test void getAndRefresh() { localSessionStore.values.put("sessionId", sessionValue(Instant.now().plus(Duration.ofHours(1)), Map.of())); Map<String, String> values = localSessionStore.getAndRefresh("sessionId", null, Duration.ofSeconds(30)); assertThat(values).isNotNull(); }
@Test void getAndRefreshWithExpiredSession() { localSessionStore.values.put("sessionId", sessionValue(Instant.now().minus(Duration.ofSeconds(30)), Map.of())); Map<String, String> values = localSessionStore.getAndRefresh("sessionId", null, Duration.ofSeconds(30)); assertThat(values).isNull(); }
@Test void getAndRefreshWithNotExistedSessionId() { Map<String, String> values = localSessionStore.getAndRefresh("sessionId", null, Duration.ofSeconds(30)); assertThat(values).isNull(); }