01: package com.ecyrd.jspwiki.auth;
02:
03: import java.util.ArrayList;
04: import java.util.List;
05:
06: import com.ecyrd.jspwiki.event.WikiEvent;
07: import com.ecyrd.jspwiki.event.WikiEventListener;
08: import com.ecyrd.jspwiki.event.WikiSecurityEvent;
09:
10: /**
11: * Traps the most recent WikiEvent so that it can be used in assertions.
12: * @author Andrew Jaquith
13: * @since 2.3.79
14: */
15: public class SecurityEventTrap implements WikiEventListener {
16: private WikiSecurityEvent m_lastEvent = null;
17: private List m_events = new ArrayList();
18:
19: public void actionPerformed(WikiEvent event) {
20: if (event instanceof WikiSecurityEvent) {
21: m_lastEvent = (WikiSecurityEvent) event;
22: m_events.add(event);
23: } else {
24: throw new IllegalArgumentException(
25: "Event wasn't a WikiSecurityEvent. Check the unit test code!");
26: }
27: }
28:
29: public WikiSecurityEvent lastEvent() {
30: return m_lastEvent;
31: }
32:
33: public void clearEvents() {
34: m_events.clear();
35: }
36:
37: public WikiSecurityEvent[] events() {
38: return (WikiSecurityEvent[]) m_events
39: .toArray(new WikiSecurityEvent[m_events.size()]);
40: }
41:
42: }
|