SessionStore { public HttpSession getSession( String userId, Function<? super String, ? extends HttpSession> createSessionFunction) { return userIdToSession.computeIfAbsent(userId, createSessionFunction); } SessionStore(); HttpSession getSession(
      String userId, Function<? super String, ? extends HttpSession> createSessionFunction); HttpSession getSession(String userId); void remove(String userId);  }
@Test public void shouldCreateSessionOnlyIfAbsent() { HttpSession sessionMock = mock(HttpSession.class); HttpSession result1 = sessionStore.getSession(userId, s -> sessionMock); assertEquals(result1, sessionMock); HttpSession result2 = sessionStore.getSession(userId, s -> null); assertEquals(result2, sessionMock); }
@Test public void shouldGetSessionById() { HttpSession sessionMock = mock(HttpSession.class); sessionStore.getSession(userId, s -> sessionMock); HttpSession result = sessionStore.getSession(userId); assertEquals(result, sessionMock); }