AbstractContext implements Context.Impl { protected ResponseStreams finalizeHeaders(Result result, Boolean handleFlashAndSessionCookie) { if (handleFlashAndSessionCookie) { flashScope.save(this); session.save(this); } for (ninja.Cookie cookie : result.getCookies()) { addCookie(cookie); } return null; } @Inject  AbstractContext(
            BodyParserEngineManager bodyParserEngineManager,
            FlashScope flashScope,
            NinjaProperties ninjaProperties,
            Session session,
            Validation validation,
            Injector injector,
            ParamParsers paramParsers); @Override void setRoute(Route route); @Override Route getRoute(); @Override Validation getValidation(); @Deprecated @Override FlashScope getFlashCookie(); @Override FlashScope getFlashScope(); @Deprecated @Override Session getSessionCookie(); @Override Session getSession(); @Override String getContextPath(); @Override String getRequestPath(); @Override String getRemoteAddr(); @Override T getAttribute(String name, Class<T> clazz); @Override String getPathParameter(String key); @Override String getPathParameterEncoded(String key); @Override Integer getPathParameterAsInteger(String key); @Override String getParameter(String key, String defaultValue); @Override Integer getParameterAsInteger(String key); @Override Integer getParameterAsInteger(String key, Integer defaultValue); @Override T getParameterAs(String key, Class<T> clazz); @Override T getParameterAs(String key, Class<T> clazz, T defaultValue); @Override T parseBody(Class<T> classOfT); @Override String getCookieValue(String name); @Override void unsetCookie(Cookie cookie); @Override void asyncRequestComplete(); @Override ResponseStreams finalizeHeadersWithoutFlashAndSessionCookie(Result result); @Override ResponseStreams finalizeHeaders(Result result); @Override String getAcceptContentType(); @Override String getAcceptEncoding(); @Override String getAcceptLanguage(); @Override String getAcceptCharset(); @Override boolean isRequestJson(); @Override boolean isRequestXml();  }
@Test public void addCookieViaResult() { AbstractContextImpl context = spy(abstractContext); Cookie cookie0 = Cookie.builder("cookie0", "yum0").setDomain("domain").build(); Cookie cookie1 = Cookie.builder("cookie1", "yum1").setDomain("domain").build(); Result result = Results.html(); result.addCookie(cookie0); result.addCookie(cookie1); doNothing().when(context).addCookie(cookie0); doNothing().when(context).addCookie(cookie1); context.finalizeHeaders(result); verify(context, times(1)).addCookie(cookie0); verify(context, times(1)).addCookie(cookie1); }
@Test public void finalizeInAbstractContextSavesFlashSessionCookies() { AbstractContextImpl context = spy(abstractContext); Result result = Results.json(); Cookie cookie = Cookie.builder("TEST", "value").build(); result.addCookie(cookie); doNothing().when(context).addCookie(cookie); ResponseStreams streams = context.finalizeHeaders(result); assertThat(streams, is(nullValue())); verify(flashCookie, times(1)).save(context); verify(sessionCookie, times(1)).save(context); verify(context, times(1)).addCookie(cookie); }