### Question:
SessionFlushValve extends AbstractLifecycle implements Contained, SessionFlushValveManagement,
        Valve { @Override public void invoke(final Request request, final Response response) { this.lockTemplate.withReadLock(new LockTemplate.LockedOperation<Void>() { @Override public Void invoke() throws IOException, ServletException { try { SessionFlushValve.this.next.invoke(request, response); } finally { Session session = request.getSessionInternal(false); if (session != null && session.isValid()) { SessionFlushValve.this.store.save(session); } } return null; } }); } SessionFlushValve();   SessionFlushValve(JmxSupport jmxSupport); @Override void backgroundProcess(); @Override Container getContainer(); @Override void setContainer(final Container container); @Override Valve getNext(); @Override void setNext(final Valve valve); Store getStore(); void setStore(final Store store); @Override void invoke(final Request request, final Response response); @Override boolean isAsyncSupported();  }### Answer:
@Test public void invokeInvalidSession() throws IOException, ServletException { when(this.request.getSessionInternal(false)).thenReturn(this.session); when(this.session.isValid()).thenReturn(false); this.valve.invoke(this.request, this.response); verify(this.next).invoke(this.request, this.response); verifyZeroInteractions(this.store); }
@Test public void invokeNoSession() throws IOException, ServletException { when(this.request.getSessionInternal(false)).thenReturn(null); this.valve.invoke(this.request, this.response); verify(this.next).invoke(this.request, this.response); verifyZeroInteractions(this.store); }
@Test public void invokeSession() throws IOException, ServletException { when(this.request.getSessionInternal(false)).thenReturn(this.session); when(this.session.isValid()).thenReturn(true); this.valve.invoke(this.request, this.response); verify(this.next).invoke(this.request, this.response); verify(this.store).save(this.session); }