### Question:
JwtCookieSession extends MapDecorator<String, Object> implements Session, DirtyListener { @Override public void save(Response response) throws IOException { if (dirty) { Reject.ifNull(response, "Cannot save session state on a null response"); final Cookie jwtCookie; if (isEmpty()) { jwtCookie = buildExpiredJwtCookie(); } else { jwtCookie = buildJwtCookie(); String value = jwtCookie.getValue(); if (value.length() > 4096) { throw new IOException( format("JWT session is too large (%d chars), failing the request because " + "session does not support serialized content that is larger than 4KB " + "(Http Cookie limitation)", value.length())); } if (value.length() > 3072) { logger.warning(format( "Current JWT session's size (%d chars) is quite close to the 4KB limit. Maybe " + "consider using the traditional Http-based session (the default), or place" + "less objects in the session", value.length())); } } response.getHeaders().add(new SetCookieHeader(singletonList(jwtCookie))); } } JwtCookieSession(final Request request,
                            final KeyPair pair,
                            final String cookieName,
                            final Logger logger,
                            final TimeService timeService,
                            final Duration sessionTimeout); @Override void onElementsRemoved(); @Override Object put(final String key, final Object value); @Override void putAll(final Map<? extends String, ?> m); @Override Object remove(final Object key); @Override void clear(); @Override Set<String> keySet(); @Override Collection<Object> values(); @Override Set<Entry<String, Object>> entrySet(); @Override void save(Response response); @Override boolean isEmpty(); static final String OPENIG_JWT_SESSION; }### Answer:
@Test public void shouldNotStoreSessionContentInACookieWhenSessionWasNotModified() throws Exception { JwtCookieSession session = newJwtSession(new Request()); Response response = new Response(); session.save(response); assertThat(response.getHeaders().get("Set-Cookie")).isNull(); }
@Test public void shouldNotStoreSessionContentInACookieWhenSessionWasNotModifiedButOnlyInitialized() throws Exception { Request request = new Request(); setRequestCookie(request, ORIGINAL); JwtCookieSession session = newJwtSession(request); Response response = new Response(); session.save(response); Cookie jwtCookie = SetCookieHeader.valueOf(response).getCookies().get(0); assertThat(jwtCookie).isNotNull(); request = new Request(); setRequestCookie(request, jwtCookie.getValue()); session = newJwtSession(request); response = new Response(); session.save(response); assertThat(response.getHeaders().get("Set-Cookie")).isNull(); }