1 package org.apache.maven.wagon.events;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import junit.framework.TestCase;
23
24 import org.apache.maven.wagon.Wagon;
25
26 import static org.easymock.EasyMock.*;
27
28
29
30
31
32 public class SessionEventSupportTest
33 extends TestCase
34 {
35
36 private SessionEventSupport eventSupport;
37
38 private Wagon wagon;
39
40
41
42
43 protected void setUp()
44 throws Exception
45 {
46 super.setUp();
47
48 eventSupport = new SessionEventSupport();
49
50
51 wagon = createNiceMock( Wagon.class );
52 }
53
54 public void testSessionListenerRegistration()
55 {
56 SessionListener mock1 = createMock( SessionListener.class );
57
58 eventSupport.addSessionListener( mock1 );
59
60 assertTrue( eventSupport.hasSessionListener( mock1 ) );
61
62 SessionListener mock2 = createMock( SessionListener.class );
63
64 assertFalse( eventSupport.hasSessionListener( mock2 ) );
65
66 eventSupport.addSessionListener( mock2 );
67
68 assertTrue( eventSupport.hasSessionListener( mock1 ) );
69
70 assertTrue( eventSupport.hasSessionListener( mock2 ) );
71
72 eventSupport.removeSessionListener( mock2 );
73
74 assertTrue( eventSupport.hasSessionListener( mock1 ) );
75
76 assertFalse( eventSupport.hasSessionListener( mock2 ) );
77
78 eventSupport.removeSessionListener( mock1 );
79
80 assertFalse( eventSupport.hasSessionListener( mock1 ) );
81 }
82
83 public void testFireSessionDisconnected()
84 {
85 SessionListener mock1 = createMock( SessionListener.class );
86
87 eventSupport.addSessionListener( mock1 );
88
89 SessionListener mock2 = createMock( SessionListener.class );
90
91 eventSupport.addSessionListener( mock2 );
92
93 final SessionEvent event = new SessionEvent( wagon, 1 );
94
95 mock1.sessionDisconnected( event );
96 mock2.sessionDisconnected( event );
97
98 replay( mock1, mock2 );
99
100 eventSupport.fireSessionDisconnected( event );
101
102 verify( mock1, mock2 );
103 }
104
105 public void testFireSessionDisconneting()
106 {
107 SessionListener mock1 = createMock( SessionListener.class );
108
109 eventSupport.addSessionListener( mock1 );
110
111 SessionListener mock2 = createMock( SessionListener.class );
112
113 eventSupport.addSessionListener( mock2 );
114
115 final SessionEvent event = new SessionEvent( wagon, 1 );
116
117 mock1.sessionDisconnecting( event );
118 mock2.sessionDisconnecting( event );
119
120 replay( mock1, mock2 );
121
122 eventSupport.fireSessionDisconnecting( event );
123
124 verify( mock1, mock2 );
125 }
126
127 public void testFireSessionLoggedIn()
128 {
129 SessionListener mock1 = createMock( SessionListener.class );
130
131 eventSupport.addSessionListener( mock1 );
132
133 SessionListener mock2 = createMock( SessionListener.class );
134
135 eventSupport.addSessionListener( mock2 );
136
137 final SessionEvent event = new SessionEvent( wagon, 1 );
138
139 mock1.sessionLoggedIn( event );
140 mock2.sessionLoggedIn( event );
141
142 replay( mock1, mock2 );
143
144 eventSupport.fireSessionLoggedIn( event );
145
146 verify( mock1, mock2 );
147 }
148
149 public void testFireSessionLoggedOff()
150 {
151 SessionListener mock1 = createMock( SessionListener.class );
152
153 eventSupport.addSessionListener( mock1 );
154
155 SessionListener mock2 = createMock( SessionListener.class );
156
157 eventSupport.addSessionListener( mock2 );
158
159 final SessionEvent event = new SessionEvent( wagon, 1 );
160
161 mock1.sessionLoggedOff( event );
162 mock2.sessionLoggedOff( event );
163
164 replay( mock1, mock2 );
165
166 eventSupport.fireSessionLoggedOff( event );
167
168 verify( mock1, mock2 );
169 }
170
171 public void testFireSessionOpened()
172 {
173 SessionListener mock1 = createMock( SessionListener.class );
174
175 eventSupport.addSessionListener( mock1 );
176
177 SessionListener mock2 = createMock( SessionListener.class );
178
179 eventSupport.addSessionListener( mock2 );
180
181 final SessionEvent event = new SessionEvent( wagon, 1 );
182
183 mock1.sessionOpened( event );
184 mock2.sessionOpened( event );
185
186 replay( mock1, mock2 );
187
188 eventSupport.fireSessionOpened( event );
189
190 verify( mock1, mock2 );
191 }
192
193 public void testFireSessionOpenning()
194 {
195 SessionListener mock1 = createMock( SessionListener.class );
196
197 eventSupport.addSessionListener( mock1 );
198
199 SessionListener mock2 = createMock( SessionListener.class );
200
201 eventSupport.addSessionListener( mock2 );
202
203 final SessionEvent event = new SessionEvent( wagon, 1 );
204
205 mock1.sessionOpening( event );
206 mock2.sessionOpening( event );
207
208 replay( mock1, mock2 );
209
210 eventSupport.fireSessionOpening( event );
211
212 verify( mock1, mock2 );
213 }
214
215 public void testFireSessionRefused()
216 {
217 SessionListener mock1 = createMock( SessionListener.class );
218
219 eventSupport.addSessionListener( mock1 );
220
221 SessionListener mock2 = createMock( SessionListener.class );
222
223 eventSupport.addSessionListener( mock2 );
224
225 final SessionEvent event = new SessionEvent( wagon, 1 );
226
227 mock1.sessionConnectionRefused( event );
228 mock2.sessionConnectionRefused( event );
229
230 replay( mock1, mock2 );
231
232 eventSupport.fireSessionConnectionRefused( event );
233
234 verify( mock1, mock2 );
235 }
236
237 public void testFireDebug()
238 {
239 SessionListener mock1 = createMock( SessionListener.class );
240
241 eventSupport.addSessionListener( mock1 );
242
243 SessionListener mock2 = createMock( SessionListener.class );
244
245 eventSupport.addSessionListener( mock2 );
246
247 mock1.debug( "mm" );
248 mock2.debug( "mm" );
249
250 replay( mock1, mock2 );
251
252 eventSupport.fireDebug( "mm" );
253
254 verify( mock1, mock2 );
255 }
256
257 }