Skip to content

3.x: Simplify JUnit tests with more appropriate assert methods #6549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/test/java/io/reactivex/NotificationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ public void valueOfOnCompleteIsNull() {
@Test
public void notEqualsToObject() {
Notification<Integer> n1 = Notification.createOnNext(0);
assertFalse(n1.equals(0));
assertNotEquals(0, n1);
Notification<Integer> n2 = Notification.createOnError(new TestException());
assertFalse(n2.equals(0));
assertNotEquals(0, n2);
Notification<Integer> n3 = Notification.createOnComplete();
assertFalse(n3.equals(0));
assertNotEquals(0, n3);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4285,7 +4285,7 @@ public boolean test(Throwable t) {
Assert.assertEquals(2, errors.size());

Assert.assertTrue(errors.get(0).toString(), errors.get(0) instanceof TestException);
Assert.assertEquals(errors.get(0).toString(), null, errors.get(0).getMessage());
Assert.assertNull(errors.get(0).toString(), errors.get(0).getMessage());
Assert.assertTrue(errors.get(1).toString(), errors.get(1) instanceof TestException);
Assert.assertEquals(errors.get(1).toString(), "Forced inner failure", errors.get(1).getMessage());
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/io/reactivex/exceptions/OnNextValueTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void onError(Throwable e) {

assertTrue(trace, trace.contains("OnNextValue"));

assertTrue("No Cause on throwable" + e, e.getCause() != null);
assertNotNull("No Cause on throwable" + e, e.getCause());
// assertTrue(e.getCause().getClass().getSimpleName() + " no OnNextValue",
// e.getCause() instanceof OnErrorThrowable.OnNextValue);
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/io/reactivex/flowable/FlowableMergeTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void mergeCovariance3() {

assertTrue(values.get(0) instanceof HorrorMovie);
assertTrue(values.get(1) instanceof Movie);
assertTrue(values.get(2) != null);
assertNotNull(values.get(2));
assertTrue(values.get(3) instanceof HorrorMovie);
}

Expand All @@ -92,7 +92,7 @@ public Publisher<Movie> get() {

assertTrue(values.get(0) instanceof HorrorMovie);
assertTrue(values.get(1) instanceof Movie);
assertTrue(values.get(2) != null);
assertNotNull(values.get(2));
assertTrue(values.get(3) instanceof HorrorMovie);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,58 +23,58 @@ public class FlowableNotificationTest {
public void onNextIntegerNotificationDoesNotEqualNullNotification() {
final Notification<Integer> integerNotification = Notification.createOnNext(1);
final Notification<Integer> nullNotification = Notification.createOnNext(null);
Assert.assertFalse(integerNotification.equals(nullNotification));
Assert.assertNotEquals(integerNotification, nullNotification);
}

@Test(expected = NullPointerException.class)
public void onNextNullNotificationDoesNotEqualIntegerNotification() {
final Notification<Integer> integerNotification = Notification.createOnNext(1);
final Notification<Integer> nullNotification = Notification.createOnNext(null);
Assert.assertFalse(nullNotification.equals(integerNotification));
Assert.assertNotEquals(nullNotification, integerNotification);
}

@Test
public void onNextIntegerNotificationsWhenEqual() {
final Notification<Integer> integerNotification = Notification.createOnNext(1);
final Notification<Integer> integerNotification2 = Notification.createOnNext(1);
Assert.assertTrue(integerNotification.equals(integerNotification2));
Assert.assertEquals(integerNotification, integerNotification2);
}

@Test
public void onNextIntegerNotificationsWhenNotEqual() {
final Notification<Integer> integerNotification = Notification.createOnNext(1);
final Notification<Integer> integerNotification2 = Notification.createOnNext(2);
Assert.assertFalse(integerNotification.equals(integerNotification2));
Assert.assertNotEquals(integerNotification, integerNotification2);
}

@Test
@Ignore("Nulls are not allowed")
public void onErrorIntegerNotificationDoesNotEqualNullNotification() {
final Notification<Integer> integerNotification = Notification.createOnError(new Exception());
final Notification<Integer> nullNotification = Notification.createOnError(null);
Assert.assertFalse(integerNotification.equals(nullNotification));
Assert.assertNotEquals(integerNotification, nullNotification);
}

@Test
@Ignore("Nulls are not allowed")
public void onErrorNullNotificationDoesNotEqualIntegerNotification() {
final Notification<Integer> integerNotification = Notification.createOnError(new Exception());
final Notification<Integer> nullNotification = Notification.createOnError(null);
Assert.assertFalse(nullNotification.equals(integerNotification));
Assert.assertNotEquals(nullNotification, integerNotification);
}

@Test
public void onErrorIntegerNotificationsWhenEqual() {
final Exception exception = new Exception();
final Notification<Integer> onErrorNotification = Notification.createOnError(exception);
final Notification<Integer> onErrorNotification2 = Notification.createOnError(exception);
Assert.assertTrue(onErrorNotification.equals(onErrorNotification2));
Assert.assertEquals(onErrorNotification, onErrorNotification2);
}

@Test
public void onErrorIntegerNotificationWhenNotEqual() {
final Notification<Integer> onErrorNotification = Notification.createOnError(new Exception());
final Notification<Integer> onErrorNotification2 = Notification.createOnError(new Exception());
Assert.assertFalse(onErrorNotification.equals(onErrorNotification2));
Assert.assertNotEquals(onErrorNotification, onErrorNotification2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ public void simple() {
for (int i = 0; i < 9; i++) {
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);

Assert.assertEquals(true, it.hasNext());
Assert.assertTrue(it.hasNext());

Assert.assertEquals(Long.valueOf(i), it.next());
}

scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
Assert.assertEquals(false, it.hasNext());
Assert.assertFalse(it.hasNext());
}

@Test(timeout = 1000)
Expand All @@ -69,13 +69,13 @@ public void sameSourceMultipleIterators() {
for (int i = 0; i < 9; i++) {
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);

Assert.assertEquals(true, it.hasNext());
Assert.assertTrue(it.hasNext());

Assert.assertEquals(Long.valueOf(i), it.next());
}

scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
Assert.assertEquals(false, it.hasNext());
Assert.assertFalse(it.hasNext());
}
}

Expand All @@ -87,7 +87,7 @@ public void empty() {

Iterator<Long> it = iter.iterator();

Assert.assertEquals(false, it.hasNext());
Assert.assertFalse(it.hasNext());

it.next();
}
Expand Down Expand Up @@ -166,7 +166,7 @@ public void fasterSource() {
source.onNext(7);
source.onComplete();

Assert.assertEquals(false, it.hasNext());
Assert.assertFalse(it.hasNext());
}

@Ignore("THe target is an enum")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
public class BlockingFlowableMostRecentTest {
@Test
public void mostRecentNull() {
assertEquals(null, Flowable.<Void>never().blockingMostRecent(null).iterator().next());
assertNull(Flowable.<Void>never().blockingMostRecent(null).iterator().next());
}

@Test
Expand Down Expand Up @@ -88,12 +88,12 @@ public void singleSourceManyIterators() {
for (int i = 0; i < 9; i++) {
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);

Assert.assertEquals(true, it.hasNext());
Assert.assertTrue(it.hasNext());
Assert.assertEquals(Long.valueOf(i), it.next());
}
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);

Assert.assertEquals(false, it.hasNext());
Assert.assertFalse(it.hasNext());
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public void singleSourceManyIterators() throws InterruptedException {
BlockingFlowableNext.NextIterator<Long> it = (BlockingFlowableNext.NextIterator<Long>)iter.iterator();

for (long i = 0; i < 10; i++) {
Assert.assertEquals(true, it.hasNext());
Assert.assertTrue(it.hasNext());
Assert.assertEquals(j + "th iteration next", Long.valueOf(i), it.next());
}
terminal.onNext(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,6 @@ public void getWithEmptyFlowable() throws Throwable {
public void getWithASingleNullItem() throws Exception {
Flowable<String> obs = Flowable.just((String)null);
Future<String> f = obs.toFuture();
assertEquals(null, f.get());
assertNull(f.get());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ public void toIterator() {

Iterator<String> it = obs.blockingIterable().iterator();

assertEquals(true, it.hasNext());
assertTrue(it.hasNext());
assertEquals("one", it.next());

assertEquals(true, it.hasNext());
assertTrue(it.hasNext());
assertEquals("two", it.next());

assertEquals(true, it.hasNext());
assertTrue(it.hasNext());
assertEquals("three", it.next());

assertEquals(false, it.hasNext());
assertFalse(it.hasNext());

}

Expand All @@ -60,10 +60,10 @@ public void subscribe(Subscriber<? super String> subscriber) {

Iterator<String> it = obs.blockingIterable().iterator();

assertEquals(true, it.hasNext());
assertTrue(it.hasNext());
assertEquals("one", it.next());

assertEquals(true, it.hasNext());
assertTrue(it.hasNext());
it.next();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1379,7 +1379,7 @@ public void accept(String s) {
});
}
});
assertEquals(null, key[0]);
assertNull(key[0]);
assertEquals(Arrays.asList("a", "b", "c"), values);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void run() {

int size = ts.values().size();
assertTrue(size <= 150); // will get up to 50 more
assertTrue(ts.values().get(size - 1) == size - 1);
assertEquals((long)ts.values().get(size - 1), size - 1);
}

static final Flowable<Long> infinite = Flowable.unsafeCreate(new Publisher<Long>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void subscribe(Subscriber<? super Integer> t1) {

System.out.println("unsubscribeThread: " + unsubscribeThread);
System.out.println("subscribeThread.get(): " + subscribeThread.get());
assertTrue(unsubscribeThread == uiEventLoop.getThread());
assertSame(unsubscribeThread, uiEventLoop.getThread());

ts.assertValues(1, 2);
ts.assertTerminated();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ public void simple() {
for (int i = 0; i < 9; i++) {
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);

Assert.assertEquals(true, it.hasNext());
Assert.assertTrue(it.hasNext());

Assert.assertEquals(Long.valueOf(i), it.next());
}

scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
Assert.assertEquals(false, it.hasNext());
Assert.assertFalse(it.hasNext());
}

@Test(timeout = 1000)
Expand All @@ -69,13 +69,13 @@ public void sameSourceMultipleIterators() {
for (int i = 0; i < 9; i++) {
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);

Assert.assertEquals(true, it.hasNext());
Assert.assertTrue(it.hasNext());

Assert.assertEquals(Long.valueOf(i), it.next());
}

scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
Assert.assertEquals(false, it.hasNext());
Assert.assertFalse(it.hasNext());
}
}

Expand All @@ -87,7 +87,7 @@ public void empty() {

Iterator<Long> it = iter.iterator();

Assert.assertEquals(false, it.hasNext());
Assert.assertFalse(it.hasNext());

it.next();
}
Expand Down Expand Up @@ -166,7 +166,7 @@ public void fasterSource() {
source.onNext(7);
source.onComplete();

Assert.assertEquals(false, it.hasNext());
Assert.assertFalse(it.hasNext());
}

@Test(expected = UnsupportedOperationException.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
public class BlockingObservableMostRecentTest {
@Test
public void mostRecentNull() {
assertEquals(null, Observable.<Void>never().blockingMostRecent(null).iterator().next());
assertNull(Observable.<Void>never().blockingMostRecent(null).iterator().next());
}

static <T> Iterable<T> mostRecent(Observable<T> source, T initialValue) {
Expand Down Expand Up @@ -91,12 +91,12 @@ public void singleSourceManyIterators() {
for (int i = 0; i < 9; i++) {
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);

Assert.assertEquals(true, it.hasNext());
Assert.assertTrue(it.hasNext());
Assert.assertEquals(Long.valueOf(i), it.next());
}
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);

Assert.assertEquals(false, it.hasNext());
Assert.assertFalse(it.hasNext());
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public void singleSourceManyIterators() throws InterruptedException {
BlockingObservableNext.NextIterator<Long> it = (BlockingObservableNext.NextIterator<Long>)iter.iterator();

for (long i = 0; i < 10; i++) {
Assert.assertEquals(true, it.hasNext());
Assert.assertTrue(it.hasNext());
Assert.assertEquals(j + "th iteration next", Long.valueOf(i), it.next());
}
terminal.onNext(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,6 @@ public void getWithEmptyFlowable() throws Throwable {
public void getWithASingleNullItem() throws Exception {
Observable<String> obs = Observable.just((String)null);
Future<String> f = obs.toFuture();
assertEquals(null, f.get());
assertNull(f.get());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ public void toIterator() {

Iterator<String> it = obs.blockingIterable().iterator();

assertEquals(true, it.hasNext());
assertTrue(it.hasNext());
assertEquals("one", it.next());

assertEquals(true, it.hasNext());
assertTrue(it.hasNext());
assertEquals("two", it.next());

assertEquals(true, it.hasNext());
assertTrue(it.hasNext());
assertEquals("three", it.next());

assertEquals(false, it.hasNext());
assertFalse(it.hasNext());

}

Expand All @@ -61,10 +61,10 @@ public void subscribe(Observer<? super String> observer) {

Iterator<String> it = obs.blockingIterable().iterator();

assertEquals(true, it.hasNext());
assertTrue(it.hasNext());
assertEquals("one", it.next());

assertEquals(true, it.hasNext());
assertTrue(it.hasNext());
it.next();
}

Expand Down
Loading