Skip to content

Commit a84e3b9

Browse files
committed
fix tests
1 parent 7ae2c26 commit a84e3b9

File tree

5 files changed

+33
-27
lines changed

5 files changed

+33
-27
lines changed

src/main/java/rx/exceptions/OnCompletedFailedException.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ public OnCompletedFailedException(Throwable throwable) {
2323
super(throwable);
2424
}
2525

26+
public OnCompletedFailedException(String message, Throwable throwable) {
27+
super(message, throwable);
28+
}
2629
}

src/main/java/rx/exceptions/UnsubscribeFailedException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,8 @@ public UnsubscribeFailedException(Throwable throwable) {
2323
super(throwable);
2424
}
2525

26+
public UnsubscribeFailedException(String message, Throwable throwable) {
27+
super(message, throwable);
28+
}
29+
2630
}

src/main/java/rx/observers/SafeSubscriber.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ public void onCompleted() {
8686
// which can prevent it from being able to handle StackOverflow
8787
Exceptions.throwIfFatal(e);
8888
RxJavaPluginUtils.handleException(e);
89-
throw new OnCompletedFailedException(e);
89+
throw new OnCompletedFailedException(e.getMessage(), e);
9090
} finally {
9191
try {
9292
// Similarly to onError if failure occurs in unsubscribe then Rx contract is broken
9393
// and we throw an UnsubscribeFailureException.
9494
unsubscribe();
9595
} catch (Throwable e2) {
9696
RxJavaPluginUtils.handleException(e2);
97-
throw new UnsubscribeFailedException(e2);
97+
throw new UnsubscribeFailedException(e2.getMessage(), e2);
9898
}
9999
}
100100
}

src/test/java/rx/observers/SafeObserverTest.java

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import org.junit.Test;
2424

25+
import junit.framework.Assert;
2526
import rx.Subscriber;
2627
import rx.exceptions.*;
2728
import rx.functions.Action0;
@@ -68,19 +69,6 @@ public void onCompletedFailure() {
6869
}
6970
}
7071

71-
@Test
72-
public void onCompletedFailureSafe() {
73-
AtomicReference<Throwable> onError = new AtomicReference<Throwable>();
74-
try {
75-
new SafeSubscriber<String>(OBSERVER_ONCOMPLETED_FAIL(onError)).onCompleted();
76-
assertNotNull(onError.get());
77-
assertTrue(onError.get() instanceof SafeObserverTestException);
78-
assertEquals("onCompletedFail", onError.get().getMessage());
79-
} catch (Exception e) {
80-
fail("expects exception to be passed to onError");
81-
}
82-
}
83-
8472
@Test
8573
public void onErrorFailure() {
8674
try {
@@ -184,8 +172,8 @@ public void call() {
184172
e.printStackTrace();
185173

186174
assertTrue(o.isUnsubscribed());
187-
188-
assertTrue(e instanceof SafeObserverTestException);
175+
assertTrue(e instanceof UnsubscribeFailedException);
176+
assertTrue(e.getCause() instanceof SafeObserverTestException);
189177
assertEquals("failure from unsubscribe", e.getMessage());
190178
// expected since onError fails so SafeObserver can't help
191179
}
@@ -475,9 +463,12 @@ public void onCompleted() {
475463
}
476464
});
477465

478-
s.onCompleted();
479-
480-
assertTrue("Error not received", error.get() instanceof TestException);
466+
try {
467+
s.onCompleted();
468+
Assert.fail();
469+
} catch (OnCompletedFailedException e) {
470+
assertNull(error.get());
471+
}
481472
}
482473

483474
@Test

src/test/java/rx/observers/SafeSubscriberTest.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@
2626
import org.junit.Before;
2727
import org.junit.Test;
2828

29+
import rx.exceptions.OnCompletedFailedException;
2930
import rx.exceptions.OnErrorFailedException;
3031
import rx.exceptions.OnErrorNotImplementedException;
3132
import rx.exceptions.TestException;
33+
import rx.exceptions.UnsubscribeFailedException;
3234
import rx.functions.Action0;
3335
import rx.plugins.RxJavaErrorHandler;
3436
import rx.plugins.RxJavaPlugins;
@@ -59,10 +61,12 @@ public void onCompleted() {
5961
}
6062
};
6163
SafeSubscriber<Integer> safe = new SafeSubscriber<Integer>(ts);
62-
64+
try {
6365
safe.onCompleted();
64-
65-
assertTrue(safe.isUnsubscribed());
66+
Assert.fail();
67+
} catch (OnCompletedFailedException e) {
68+
assertTrue(safe.isUnsubscribed());
69+
}
6670
}
6771

6872
@Test
@@ -84,7 +88,7 @@ public void onCompleted() {
8488
assertTrue(safe.isUnsubscribed());
8589
}
8690

87-
@Test
91+
@Test(expected=OnCompletedFailedException.class)
8892
public void testPluginException() {
8993
RxJavaPlugins.getInstance().registerErrorHandler(new RxJavaErrorHandler() {
9094
@Override
@@ -261,8 +265,12 @@ public void call() {
261265
}
262266
}));
263267

264-
safe.onCompleted();
265-
assertEquals(1, (int) calls.get());
266-
assertEquals(0, (int) errors.get());
268+
try {
269+
safe.onCompleted();
270+
Assert.fail();
271+
} catch(UnsubscribeFailedException e) {
272+
assertEquals(1, (int) calls.get());
273+
assertEquals(0, (int) errors.get());
274+
}
267275
}
268276
}

0 commit comments

Comments
 (0)