HttpSessionNotifier implements SessionNotifier { @Override public void attributeAdded(RepositoryBackedSession session, String key, Object value) { if (session instanceof HttpSession && value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener)value).valueBound(new HttpSessionBindingEvent((HttpSession)session, key)); } HttpSessionBindingEvent event = new HttpSessionBindingEvent((HttpSession)session, key, value); for (HttpSessionAttributeListener listener : descriptor.getHttpSessionAttributeListeners()) { listener.attributeAdded(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 testAttributeAdded() { HttpSessionAttributeListener listener = mock(HttpSessionAttributeListener.class); descriptor.addHttpSessionAttributeListener(listener); notifier.attributeAdded(session, "Test", "value"); verify(listener).attributeAdded(any(HttpSessionBindingEvent.class)); HttpSessionBindingListener bindingListener = mock(HttpSessionBindingListener.class); notifier.attributeAdded(session, "Test", bindingListener); verify(listener, times(2)).attributeAdded(any(HttpSessionBindingEvent.class)); verify(bindingListener).valueBound(any(HttpSessionBindingEvent.class)); }