SessionExpirationCacheListener extends CacheListenerAdapter<String, HttpSession> implements Declarable { @Override public void afterDestroy(EntryEvent<String, HttpSession> event) { DeltaSessionInterface session = null; if (event.getOperation() == Operation.EXPIRE_DESTROY) { session = (DeltaSessionInterface) event.getOldValue(); } else { Object callback = event.getCallbackArgument(); if (callback instanceof DeltaSessionInterface) { session = (DeltaSessionInterface) callback; ManagerBase m = ContextMapper.getContext(session.getContextName()); if (m != null) { session.setOwner(m); } } } if (session != null) { session.processExpired(); } }  @Override void afterDestroy(EntryEvent<String, HttpSession> event); @Override boolean equals(Object obj); @Override int hashCode();  }
@Test public void testAfterDestroyProcessesSessionExpired() { final SessionExpirationCacheListener listener = new SessionExpirationCacheListener(); final EntryEvent<String, HttpSession> event = mock(EntryEvent.class); final DeltaSession session = mock(DeltaSession.class); when(event.getOperation()).thenReturn(Operation.EXPIRE_DESTROY); when(event.getOldValue()).thenReturn(session); listener.afterDestroy(event); verify(session).processExpired(); }