@Test public void ifCookieNameDoesNotMatchShouldReturnEmptySet() { final Cookie cookie = new Cookie("notMatching", "anyValue"); final HttpServletRequest request = mock(HttpServletRequest.class); when(request.getCookies()).thenReturn(new Cookie[] {cookie}); final Set<CredentialFlowState> got = CredentialFlowStateHelper.restoreFrom((cookies, cls) -> { assertThat(cookies).isEmpty(); return Collections.emptySet(); }, request); assertThat(got).isEmpty(); }
static Set<CredentialFlowState> restoreFrom(final Restorer restore, final HttpServletRequest request) { final Cookie[] servletCookies = request.getCookies(); if (ArrayUtils.isEmpty(servletCookies)) { return Collections.emptySet(); } final List<javax.ws.rs.core.Cookie> credentialCookies = Arrays.stream(servletCookies) .filter(c -> c.getName().startsWith(CredentialFlowState.CREDENTIAL_PREFIX)) .map(CredentialFlowStateHelper::toJaxRsCookie).collect(Collectors.toList()); try { return restore.apply(credentialCookies, CredentialFlowState.class); } catch (final IllegalArgumentException e) { return Collections.emptySet(); } }
CredentialFlowStateHelper { static Set<CredentialFlowState> restoreFrom(final Restorer restore, final HttpServletRequest request) { final Cookie[] servletCookies = request.getCookies(); if (ArrayUtils.isEmpty(servletCookies)) { return Collections.emptySet(); } final List<javax.ws.rs.core.Cookie> credentialCookies = Arrays.stream(servletCookies) .filter(c -> c.getName().startsWith(CredentialFlowState.CREDENTIAL_PREFIX)) .map(CredentialFlowStateHelper::toJaxRsCookie).collect(Collectors.toList()); try { return restore.apply(credentialCookies, CredentialFlowState.class); } catch (final IllegalArgumentException e) { return Collections.emptySet(); } } }
CredentialFlowStateHelper { static Set<CredentialFlowState> restoreFrom(final Restorer restore, final HttpServletRequest request) { final Cookie[] servletCookies = request.getCookies(); if (ArrayUtils.isEmpty(servletCookies)) { return Collections.emptySet(); } final List<javax.ws.rs.core.Cookie> credentialCookies = Arrays.stream(servletCookies) .filter(c -> c.getName().startsWith(CredentialFlowState.CREDENTIAL_PREFIX)) .map(CredentialFlowStateHelper::toJaxRsCookie).collect(Collectors.toList()); try { return restore.apply(credentialCookies, CredentialFlowState.class); } catch (final IllegalArgumentException e) { return Collections.emptySet(); } } private  CredentialFlowStateHelper(); }
CredentialFlowStateHelper { static Set<CredentialFlowState> restoreFrom(final Restorer restore, final HttpServletRequest request) { final Cookie[] servletCookies = request.getCookies(); if (ArrayUtils.isEmpty(servletCookies)) { return Collections.emptySet(); } final List<javax.ws.rs.core.Cookie> credentialCookies = Arrays.stream(servletCookies) .filter(c -> c.getName().startsWith(CredentialFlowState.CREDENTIAL_PREFIX)) .map(CredentialFlowStateHelper::toJaxRsCookie).collect(Collectors.toList()); try { return restore.apply(credentialCookies, CredentialFlowState.class); } catch (final IllegalArgumentException e) { return Collections.emptySet(); } } private  CredentialFlowStateHelper();  }
CredentialFlowStateHelper { static Set<CredentialFlowState> restoreFrom(final Restorer restore, final HttpServletRequest request) { final Cookie[] servletCookies = request.getCookies(); if (ArrayUtils.isEmpty(servletCookies)) { return Collections.emptySet(); } final List<javax.ws.rs.core.Cookie> credentialCookies = Arrays.stream(servletCookies) .filter(c -> c.getName().startsWith(CredentialFlowState.CREDENTIAL_PREFIX)) .map(CredentialFlowStateHelper::toJaxRsCookie).collect(Collectors.toList()); try { return restore.apply(credentialCookies, CredentialFlowState.class); } catch (final IllegalArgumentException e) { return Collections.emptySet(); } } private  CredentialFlowStateHelper();   }