HttpSessionNotifier implements SessionNotifier { @Override public void attributeReplaced(RepositoryBackedSession session, String key, Object replacedValue) { if (session instanceof HttpSession && replacedValue instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener)replacedValue).valueUnbound(new HttpSessionBindingEvent((HttpSession)session, key)); } HttpSessionBindingEvent event = new HttpSessionBindingEvent((HttpSession)session, key, replacedValue); for (HttpSessionAttributeListener listener : descriptor.getHttpSessionAttributeListeners()) { listener.attributeReplaced(event); } } HttpSessionNotifier(ServletContextDescriptor descriptor); @Override void sessionCreated(RepositoryBackedSession session); @Override void attributeAdded(RepositoryBackedSession session, String key, Object value); @Override void attributeReplaced(RepositoryBackedSession session, String key, Object replacedValue); @Override void attributeRemoved(RepositoryBackedSession session, String key, Object removedValue); @Override void attributeBeingStored(RepositoryBackedSession session, String key, Object value); @Override void attributeHasBeenRestored(RepositoryBackedSession session, String key, Object value); @Override void sessionDestroyed(RepositoryBackedSession session, boolean shutdown); @Override void sessionIdChanged(RepositoryBackedSession session, String oldId);  }
@Test public void testAttributeReplaced() { HttpSessionAttributeListener listener = mock(HttpSessionAttributeListener.class); notifier.attributeReplaced(session, "Test", "very-old-value"); verify(listener, never()).attributeReplaced(any(HttpSessionBindingEvent.class)); descriptor.addHttpSessionAttributeListener(listener); notifier.attributeReplaced(session, "Test", "old-value"); verify(listener).attributeReplaced(any(HttpSessionBindingEvent.class)); HttpSessionBindingListener bindingListener = mock(HttpSessionBindingListener.class); notifier.attributeReplaced(session, "Test", bindingListener); verify(listener, times(2)).attributeReplaced(any(HttpSessionBindingEvent.class)); verify(bindingListener).valueUnbound(any(HttpSessionBindingEvent.class)); }