Skip to content

Commit 684e9c7

Browse files
authored
Fix ErrorsRule to fix master tests (#39)
RxJava 2.0.6 introduced UndeliverableException, which wraps everything that goes to RxJavaPlugins.onError() that isn't an NPE (to better distinguish between different types of exceptions). Also opportunistically fixed a deprecation from the bump to Truth 0.32 This was missed because the lambda observer tests went into master and then the deps bump went in after, but we don't have CI turned on to check that the tests would have failed in between those two changes.
1 parent 0c88fd4 commit 684e9c7

6 files changed

Lines changed: 32 additions & 14 deletions

File tree

autodispose/src/test/java/com/uber/autodispose/LambdaCompletableObserverTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,10 @@
130130
CompositeException ex = errors.takeCompositeException();
131131
List<Throwable> ce = ex.getExceptions();
132132
assertThat(ce).hasSize(2);
133-
assertThat(ce.get(0)).hasMessage("Outer");
134-
assertThat(ce.get(1)).hasMessage("Inner");
133+
assertThat(ce.get(0)).hasMessageThat()
134+
.isEqualTo("Outer");
135+
assertThat(ce.get(1)).hasMessageThat()
136+
.isEqualTo("Inner");
135137
}
136138

137139
@Test public void onCompleteThrows() {
@@ -160,7 +162,7 @@
160162

161163
assertTrue(o.isDisposed());
162164

163-
assertThat(errors.take()).isInstanceOf(TestException.class);
165+
assertThat(errors.takeThrowableFromUndeliverableException()).isInstanceOf(TestException.class);
164166
}
165167

166168
@Test @Ignore public void badSourceOnSubscribe() {

autodispose/src/test/java/com/uber/autodispose/LambdaMaybeObserverTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,10 @@
144144
CompositeException ex = errors.takeCompositeException();
145145
List<Throwable> ce = ex.getExceptions();
146146
assertThat(ce).hasSize(2);
147-
assertThat(ce.get(0)).hasMessage("Outer");
148-
assertThat(ce.get(1)).hasMessage("Inner");
147+
assertThat(ce.get(0)).hasMessageThat()
148+
.isEqualTo("Outer");
149+
assertThat(ce.get(1)).hasMessageThat()
150+
.isEqualTo("Inner");
149151
}
150152

151153
@Test public void onCompleteThrows() {
@@ -177,7 +179,7 @@
177179

178180
assertTrue(o.isDisposed());
179181

180-
assertThat(errors.take()).isInstanceOf(TestException.class);
182+
assertThat(errors.takeThrowableFromUndeliverableException()).isInstanceOf(TestException.class);
181183
}
182184

183185
@Test @Ignore public void badSourceOnSubscribe() {

autodispose/src/test/java/com/uber/autodispose/LambdaObserverTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,10 @@
144144
CompositeException ex = errors.takeCompositeException();
145145
List<Throwable> ce = ex.getExceptions();
146146
assertThat(ce).hasSize(2);
147-
assertThat(ce.get(0)).hasMessage("Outer");
148-
assertThat(ce.get(1)).hasMessage("Inner");
147+
assertThat(ce.get(0)).hasMessageThat()
148+
.isEqualTo("Outer");
149+
assertThat(ce.get(1)).hasMessageThat()
150+
.isEqualTo("Inner");
149151
}
150152

151153
@Test public void onCompleteThrows() {
@@ -177,7 +179,7 @@
177179

178180
assertTrue(o.isDisposed());
179181

180-
assertThat(errors.take()).isInstanceOf(TestException.class);
182+
assertThat(errors.takeThrowableFromUndeliverableException()).isInstanceOf(TestException.class);
181183
}
182184

183185
@Test @Ignore public void badSourceOnSubscribe() {

autodispose/src/test/java/com/uber/autodispose/LambdaSingleObserverTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,10 @@
125125
CompositeException ex = errors.takeCompositeException();
126126
List<Throwable> ce = ex.getExceptions();
127127
assertThat(ce).hasSize(2);
128-
assertThat(ce.get(0)).hasMessage("Outer");
129-
assertThat(ce.get(1)).hasMessage("Inner");
128+
assertThat(ce.get(0)).hasMessageThat()
129+
.isEqualTo("Outer");
130+
assertThat(ce.get(1)).hasMessageThat()
131+
.isEqualTo("Inner");
130132
}
131133

132134
@Test @Ignore public void badSourceOnSubscribe() {

autodispose/src/test/java/com/uber/autodispose/LambdaSubscriberTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,10 @@ public class LambdaSubscriberTest {
144144
CompositeException ex = errors.takeCompositeException();
145145
List<Throwable> ce = ex.getExceptions();
146146
assertThat(ce).hasSize(2);
147-
assertThat(ce.get(0)).hasMessage("Outer");
148-
assertThat(ce.get(1)).hasMessage("Inner");
147+
assertThat(ce.get(0)).hasMessageThat()
148+
.isEqualTo("Outer");
149+
assertThat(ce.get(1)).hasMessageThat()
150+
.isEqualTo("Inner");
149151
} finally {
150152
RxJavaPlugins.reset();
151153
}
@@ -182,7 +184,8 @@ public class LambdaSubscriberTest {
182184

183185
assertTrue(o.isDisposed());
184186

185-
assertThat(errors.take()).isInstanceOf(TestException.class);
187+
assertThat(errors.takeThrowableFromUndeliverableException()).isInstanceOf(TestException
188+
.class);
186189
} finally {
187190
RxJavaPlugins.reset();
188191
}

autodispose/src/test/java/com/uber/autodispose/RxErrorsRule.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.uber.autodispose;
22

33
import io.reactivex.exceptions.CompositeException;
4+
import io.reactivex.exceptions.UndeliverableException;
45
import io.reactivex.functions.Consumer;
56
import io.reactivex.plugins.RxJavaPlugins;
67
import java.util.ArrayList;
@@ -51,6 +52,12 @@ public Throwable take() {
5152
return error;
5253
}
5354

55+
public Throwable takeThrowableFromUndeliverableException() {
56+
Throwable error = take();
57+
assertThat(error).isInstanceOf(UndeliverableException.class);
58+
return error.getCause();
59+
}
60+
5461
public CompositeException takeCompositeException() {
5562
Throwable error = take();
5663
assertThat(error).isInstanceOf(CompositeException.class);

0 commit comments

Comments
 (0)