@@ -134,7 +134,7 @@ public void onError(TransferContext context, IOException reason) {
134
134
}
135
135
136
136
@ Test
137
- public void transferProgressListener_addListener_errorOccured_errorlistenerInvoked ()
137
+ public void transferProgressListener_addListener_errorOccurred_errorListenerInvoked ()
138
138
throws IOException {
139
139
DownloadEvent event = Mockito .mock (DownloadEvent .class );
140
140
Mockito .when (event .getSession ()).thenReturn (session );
@@ -173,7 +173,7 @@ public void transferProgressListener_addListener_errorOccured_errorlistenerInvok
173
173
}
174
174
175
175
@ Test
176
- public void transferProgressListener_addListener_callbackErrorOccured_errorlistenerInvoked () {
176
+ public void transferProgressListener_addListener_callbackIOExceptionOccurred_errorListenerInvoked () {
177
177
DownloadEvent event = Mockito .mock (DownloadEvent .class );
178
178
Mockito .when (event .getSession ()).thenReturn (session );
179
179
Mockito .when (event .getResponse ()).thenReturn (response );
@@ -203,6 +203,65 @@ public void transferProgressListener_addListener_callbackErrorOccured_errorliste
203
203
whenCompleteResult .get ());
204
204
}
205
205
206
+ @ Test
207
+ public void transferProgressListener_addListener_callbackUncheckedExceptionOccurred_errorListenerInvoked () {
208
+ DownloadEvent event = Mockito .mock (DownloadEvent .class );
209
+ Mockito .when (event .getSession ()).thenReturn (session );
210
+ Mockito .when (event .getResponse ()).thenReturn (response );
211
+ Mockito .when (event .getOwningElement ()).thenReturn (owner );
212
+ OutputStream outputStreamMock = Mockito .mock (OutputStream .class );
213
+ Mockito .when (event .getOutputStream ()).thenReturn (outputStreamMock );
214
+
215
+ AtomicReference <Boolean > whenCompleteResult = new AtomicReference <>();
216
+
217
+ InvocationTrackingTransferProgressListener transferListener = new InvocationTrackingTransferProgressListener ();
218
+ DownloadHandler handler = DownloadHandler .fromInputStream (req -> {
219
+ throw new RuntimeException ("I/O exception" );
220
+ }, transferListener ).whenComplete ((context , success ) -> {
221
+ whenCompleteResult .set (success );
222
+ });
223
+
224
+ try {
225
+ handler .handleDownloadRequest (event );
226
+ Assert .fail ("Expected an exception to be thrown" );
227
+ } catch (Exception e ) {
228
+ }
229
+ Assert .assertEquals (List .of ("onError" ), transferListener .invocations );
230
+ Assert .assertNotNull ("Expected whenComplete to be invoked, but was not" ,
231
+ whenCompleteResult .get ());
232
+ Assert .assertFalse (
233
+ "Expected whenComplete to be invoked with false result, but got true" ,
234
+ whenCompleteResult .get ());
235
+ }
236
+
237
+ @ Test
238
+ public void transferProgressListener_addListener_callbackResponseError_errorListenerInvoked ()
239
+ throws IOException {
240
+ DownloadEvent event = Mockito .mock (DownloadEvent .class );
241
+ Mockito .when (event .getSession ()).thenReturn (session );
242
+ Mockito .when (event .getResponse ()).thenReturn (response );
243
+ Mockito .when (event .getOwningElement ()).thenReturn (owner );
244
+ OutputStream outputStreamMock = Mockito .mock (OutputStream .class );
245
+ Mockito .when (event .getOutputStream ()).thenReturn (outputStreamMock );
246
+
247
+ AtomicReference <Boolean > whenCompleteResult = new AtomicReference <>();
248
+
249
+ InvocationTrackingTransferProgressListener transferListener = new InvocationTrackingTransferProgressListener ();
250
+ DownloadHandler handler = DownloadHandler .fromInputStream (
251
+ req -> DownloadResponse .error (500 , "I/O exception" ),
252
+ transferListener ).whenComplete ((context , success ) -> {
253
+ whenCompleteResult .set (success );
254
+ });
255
+
256
+ handler .handleDownloadRequest (event );
257
+ Assert .assertEquals (List .of ("onError" ), transferListener .invocations );
258
+ Assert .assertNotNull ("Expected whenComplete to be invoked, but was not" ,
259
+ whenCompleteResult .get ());
260
+ Assert .assertFalse (
261
+ "Expected whenComplete to be invoked with false result, but got true" ,
262
+ whenCompleteResult .get ());
263
+ }
264
+
206
265
@ Test
207
266
public void inline_setFileNameInvokedByDefault () throws IOException {
208
267
DownloadEvent event = Mockito .mock (DownloadEvent .class );
0 commit comments