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 import org.apache.maven.wagon.Wagon;
24 import org.apache.maven.wagon.resource.Resource;
25 import org.easymock.EasyMock;
26
27 import static org.easymock.EasyMock.*;
28
29
30
31
32 public class TransferEventSupportTest
33 extends TestCase
34 {
35 private TransferEventSupport eventSupport;
36
37 private Wagon wagon;
38
39
40
41
42 protected void setUp()
43 throws Exception
44 {
45 super.setUp();
46
47 eventSupport = new TransferEventSupport();
48
49
50 wagon = EasyMock.createNiceMock( Wagon.class );
51 }
52
53 public void testTransferListenerRegistration()
54 {
55 TransferListener mock1 = createMock( TransferListener.class );
56 eventSupport.addTransferListener( mock1 );
57
58 assertTrue( eventSupport.hasTransferListener( mock1 ) );
59 TransferListener mock2 = createMock( TransferListener.class );
60
61 assertFalse( eventSupport.hasTransferListener( mock2 ) );
62
63 eventSupport.addTransferListener( mock2 );
64
65 assertTrue( eventSupport.hasTransferListener( mock1 ) );
66 assertTrue( eventSupport.hasTransferListener( mock2 ) );
67
68 eventSupport.removeTransferListener( mock2 );
69
70 assertTrue( eventSupport.hasTransferListener( mock1 ) );
71 assertFalse( eventSupport.hasTransferListener( mock2 ) );
72
73 eventSupport.removeTransferListener( mock1 );
74 assertFalse( eventSupport.hasTransferListener( mock1 ) );
75 }
76
77 public void testFireTransferStarted()
78 {
79 TransferListener mock1 = createMock( TransferListener.class );
80 eventSupport.addTransferListener( mock1 );
81
82 TransferListener mock2 = createMock( TransferListener.class );
83 eventSupport.addTransferListener( mock2 );
84
85 final TransferEvent event = getEvent( wagon );
86
87 mock1.transferStarted( event );
88 mock2.transferStarted( event );
89
90 replay( mock1, mock2 );
91
92 eventSupport.fireTransferStarted( event );
93
94 verify( mock1, mock2 );
95 }
96
97 public void testFireTransferProgress()
98 {
99 TransferListener mock1 = createMock( TransferListener.class );
100
101 eventSupport.addTransferListener( mock1 );
102
103 TransferListener mock2 = createMock( TransferListener.class );
104
105 eventSupport.addTransferListener( mock2 );
106
107 final TransferEvent event = getEvent( wagon );
108 final byte[] buffer = "content".getBytes();
109
110 mock1.transferProgress( event, buffer, 0 );
111 mock2.transferProgress( event, buffer, 0 );
112
113 replay( mock1, mock2 );
114
115 eventSupport.fireTransferProgress( event, buffer , 0 );
116
117 verify( mock1, mock2 );
118 }
119
120 public void testFireTransferCompleted()
121 {
122 TransferListener mock1 = createMock( TransferListener.class );
123
124 eventSupport.addTransferListener( mock1 );
125
126 TransferListener mock2 = createMock( TransferListener.class );
127
128 eventSupport.addTransferListener( mock2 );
129
130 final TransferEvent event = getEvent( wagon );
131
132 mock1.transferCompleted( event );
133 mock2.transferCompleted( event );
134
135 replay( mock1, mock2 );
136
137 eventSupport.fireTransferCompleted( event );
138
139 verify( mock1, mock2 );
140 }
141
142 public void testFireTransferError()
143 {
144 TransferListener mock1 = createMock( TransferListener.class );
145
146 eventSupport.addTransferListener( mock1 );
147
148 TransferListener mock2 = createMock( TransferListener.class );
149
150 eventSupport.addTransferListener( mock2 );
151
152 final TransferEvent event = getEvent( wagon );
153
154 mock1.transferError( event );
155 mock2.transferError( event );
156
157 replay( mock1, mock2 );
158
159 eventSupport.fireTransferError( event );
160
161 verify( mock1, mock2 );
162 }
163
164 public void testFireDebug()
165 {
166 TransferListener mock1 = createMock( TransferListener.class );
167
168 eventSupport.addTransferListener( mock1 );
169
170 TransferListener mock2 = createMock( TransferListener.class );
171
172 eventSupport.addTransferListener( mock2 );
173
174 mock1.debug( "mm" );
175 mock2.debug( "mm" );
176
177 replay( mock1, mock2 );
178
179 eventSupport.fireDebug( "mm" );
180
181 verify( mock1, mock2 );
182 }
183
184 private TransferEvent getEvent( final Wagon wagon )
185 {
186 return new TransferEvent( wagon, new Resource(), TransferEvent.TRANSFER_COMPLETED,
187 TransferEvent.REQUEST_GET );
188 }
189
190 }