@@ -154,6 +154,21 @@ public static void assertError(List<Throwable> list, int index, Class<? extends
154
154
}
155
155
}
156
156
157
+ public static void assertUndeliverable (List <Throwable > list , int index , Class <? extends Throwable > clazz ) {
158
+ Throwable ex = list .get (index );
159
+ if (!(ex instanceof UndeliverableException )) {
160
+ AssertionError err = new AssertionError ("Outer exception UndeliverableException expected but got " + list .get (index ));
161
+ err .initCause (list .get (index ));
162
+ throw err ;
163
+ }
164
+ ex = ex .getCause ();
165
+ if (!clazz .isInstance (ex )) {
166
+ AssertionError err = new AssertionError ("Inner exception " + clazz + " expected but got " + list .get (index ));
167
+ err .initCause (list .get (index ));
168
+ throw err ;
169
+ }
170
+ }
171
+
157
172
public static void assertError (List <Throwable > list , int index , Class <? extends Throwable > clazz , String message ) {
158
173
Throwable ex = list .get (index );
159
174
if (!clazz .isInstance (ex )) {
@@ -168,6 +183,26 @@ public static void assertError(List<Throwable> list, int index, Class<? extends
168
183
}
169
184
}
170
185
186
+ public static void assertUndeliverable (List <Throwable > list , int index , Class <? extends Throwable > clazz , String message ) {
187
+ Throwable ex = list .get (index );
188
+ if (!(ex instanceof UndeliverableException )) {
189
+ AssertionError err = new AssertionError ("Outer exception UndeliverableException expected but got " + list .get (index ));
190
+ err .initCause (list .get (index ));
191
+ throw err ;
192
+ }
193
+ ex = ex .getCause ();
194
+ if (!clazz .isInstance (ex )) {
195
+ AssertionError err = new AssertionError ("Inner exception " + clazz + " expected but got " + list .get (index ));
196
+ err .initCause (list .get (index ));
197
+ throw err ;
198
+ }
199
+ if (!ObjectHelper .equals (message , ex .getMessage ())) {
200
+ AssertionError err = new AssertionError ("Message " + message + " expected but got " + ex .getMessage ());
201
+ err .initCause (ex );
202
+ throw err ;
203
+ }
204
+ }
205
+
171
206
public static void assertError (TestObserver <?> ts , int index , Class <? extends Throwable > clazz ) {
172
207
Throwable ex = ts .errors ().get (0 );
173
208
try {
@@ -386,6 +421,9 @@ public void run() {
386
421
* @return the list of Throwables
387
422
*/
388
423
public static List <Throwable > compositeList (Throwable ex ) {
424
+ if (ex instanceof UndeliverableException ) {
425
+ ex = ex .getCause ();
426
+ }
389
427
return ((CompositeException )ex ).getExceptions ();
390
428
}
391
429
@@ -2428,7 +2466,7 @@ protected void subscribeActual(Observer<? super T> observer) {
2428
2466
}
2429
2467
}
2430
2468
2431
- assertError (errors , 0 , TestException .class , "second" );
2469
+ assertUndeliverable (errors , 0 , TestException .class , "second" );
2432
2470
} catch (AssertionError ex ) {
2433
2471
throw ex ;
2434
2472
} catch (Throwable ex ) {
@@ -2587,7 +2625,7 @@ protected void subscribeActual(Subscriber<? super T> observer) {
2587
2625
}
2588
2626
}
2589
2627
2590
- assertError (errors , 0 , TestException .class , "second" );
2628
+ assertUndeliverable (errors , 0 , TestException .class , "second" );
2591
2629
} catch (AssertionError ex ) {
2592
2630
throw ex ;
2593
2631
} catch (Throwable ex ) {
0 commit comments