WebUtils { @Nonnull public static Optional<HttpSession> retrieveHttpSessionFromWSSession(@Nonnull Session session) { DockerCloudUtils.requireNonNull(session, "Session cannot be null."); return Optional.ofNullable((HttpSession) session.getUserProperties().get(HttpSession.class.getName())); } private  WebUtils(); @Nonnull static Optional<HttpSession> retrieveHttpSessionFromWSSession(@Nonnull Session session); @Nonnull static Optional<SUser> retrieveUserFromWSSession(@Nonnull Session session); static boolean isAuthorizedToRunContainerTests(@Nonnull Session session); static boolean isAuthorizedToRunContainerTests(@Nullable SUser user);  }
@Test public void retrieveHttpSessionFromWSSession() { TestSession session = new TestSession(); TestHttpSession httpSession = new TestHttpSession(); session.getUserProperties().put(HttpSession.class.getName(), httpSession); assertThat(WebUtils.retrieveHttpSessionFromWSSession(session).get()).isSameAs(httpSession); }
@Test public void noHttpSessionToRetrieve() { TestSession session = new TestSession(); assertThat(WebUtils.retrieveHttpSessionFromWSSession(session).isPresent()).isFalse(); }
@Test public void retrieveHttpSessionFromWSSessionInvalidInput() { assertThatExceptionOfType(NullPointerException.class). isThrownBy(() -> WebUtils.retrieveHttpSessionFromWSSession(null)); }