SEC-2574: JavaConfig default SessionRegistry processes SessionDestroyedEvents

This commit is contained in:
Rob Winch
2014-11-19 16:48:19 -06:00
parent 4dcc89fab0
commit 5810681b06
5 changed files with 172 additions and 5 deletions

View File

@@ -0,0 +1,72 @@
package org.springframework.security.context;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.SmartApplicationListener;
import org.springframework.security.core.session.SessionDestroyedEvent;
import static org.junit.Assert.*;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class DelegatingApplicationListenerTests {
@Mock
SmartApplicationListener delegate;
ApplicationEvent event;
DelegatingApplicationListener listener;
@Before
public void setup() {
event = new ApplicationEvent(this) {};
listener = new DelegatingApplicationListener();
listener.addListener(delegate);
}
@Test
public void processEventNull() {
listener.onApplicationEvent(null);
verify(delegate,never()).onApplicationEvent(any(ApplicationEvent.class));
}
@Test
public void processEventSuccess() {
when(delegate.supportsEventType(event.getClass())).thenReturn(true);
when(delegate.supportsSourceType(event.getSource().getClass())).thenReturn(true);
listener.onApplicationEvent(event);
verify(delegate).onApplicationEvent(event);
}
@Test
public void processEventEventTypeNotSupported() {
when(delegate.supportsSourceType(event.getSource().getClass())).thenReturn(true);
listener.onApplicationEvent(event);
verify(delegate,never()).onApplicationEvent(any(ApplicationEvent.class));
}
@Test
public void processEventSourceTypeNotSupported() {
when(delegate.supportsEventType(event.getClass())).thenReturn(true);
listener.onApplicationEvent(event);
verify(delegate,never()).onApplicationEvent(any(ApplicationEvent.class));
}
@Test(expected = IllegalArgumentException.class)
public void addNull() {
listener.addListener(null);
}
}