Skip to content

Commit ae8025d

Browse files
slievrlyakarnokd
authored andcommitted
3.x: Simplify JUnit tests with more appropriate assert methods (#6549)
1 parent cc7fce8 commit ae8025d

32 files changed

+84
-84
lines changed

src/test/java/io/reactivex/NotificationTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ public void valueOfOnCompleteIsNull() {
4141
@Test
4242
public void notEqualsToObject() {
4343
Notification<Integer> n1 = Notification.createOnNext(0);
44-
assertFalse(n1.equals(0));
44+
assertNotEquals(0, n1);
4545
Notification<Integer> n2 = Notification.createOnError(new TestException());
46-
assertFalse(n2.equals(0));
46+
assertNotEquals(0, n2);
4747
Notification<Integer> n3 = Notification.createOnComplete();
48-
assertFalse(n3.equals(0));
48+
assertNotEquals(0, n3);
4949
}
5050

5151
@Test

src/test/java/io/reactivex/completable/CompletableTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4285,7 +4285,7 @@ public boolean test(Throwable t) {
42854285
Assert.assertEquals(2, errors.size());
42864286

42874287
Assert.assertTrue(errors.get(0).toString(), errors.get(0) instanceof TestException);
4288-
Assert.assertEquals(errors.get(0).toString(), null, errors.get(0).getMessage());
4288+
Assert.assertNull(errors.get(0).toString(), errors.get(0).getMessage());
42894289
Assert.assertTrue(errors.get(1).toString(), errors.get(1) instanceof TestException);
42904290
Assert.assertEquals(errors.get(1).toString(), "Forced inner failure", errors.get(1).getMessage());
42914291
}

src/test/java/io/reactivex/exceptions/OnNextValueTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void onError(Throwable e) {
7171

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

74-
assertTrue("No Cause on throwable" + e, e.getCause() != null);
74+
assertNotNull("No Cause on throwable" + e, e.getCause());
7575
// assertTrue(e.getCause().getClass().getSimpleName() + " no OnNextValue",
7676
// e.getCause() instanceof OnErrorThrowable.OnNextValue);
7777
}

src/test/java/io/reactivex/flowable/FlowableMergeTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void mergeCovariance3() {
6969

7070
assertTrue(values.get(0) instanceof HorrorMovie);
7171
assertTrue(values.get(1) instanceof Movie);
72-
assertTrue(values.get(2) != null);
72+
assertNotNull(values.get(2));
7373
assertTrue(values.get(3) instanceof HorrorMovie);
7474
}
7575

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

9393
assertTrue(values.get(0) instanceof HorrorMovie);
9494
assertTrue(values.get(1) instanceof Movie);
95-
assertTrue(values.get(2) != null);
95+
assertNotNull(values.get(2));
9696
assertTrue(values.get(3) instanceof HorrorMovie);
9797
}
9898

src/test/java/io/reactivex/flowable/FlowableNotificationTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,58 +23,58 @@ public class FlowableNotificationTest {
2323
public void onNextIntegerNotificationDoesNotEqualNullNotification() {
2424
final Notification<Integer> integerNotification = Notification.createOnNext(1);
2525
final Notification<Integer> nullNotification = Notification.createOnNext(null);
26-
Assert.assertFalse(integerNotification.equals(nullNotification));
26+
Assert.assertNotEquals(integerNotification, nullNotification);
2727
}
2828

2929
@Test(expected = NullPointerException.class)
3030
public void onNextNullNotificationDoesNotEqualIntegerNotification() {
3131
final Notification<Integer> integerNotification = Notification.createOnNext(1);
3232
final Notification<Integer> nullNotification = Notification.createOnNext(null);
33-
Assert.assertFalse(nullNotification.equals(integerNotification));
33+
Assert.assertNotEquals(nullNotification, integerNotification);
3434
}
3535

3636
@Test
3737
public void onNextIntegerNotificationsWhenEqual() {
3838
final Notification<Integer> integerNotification = Notification.createOnNext(1);
3939
final Notification<Integer> integerNotification2 = Notification.createOnNext(1);
40-
Assert.assertTrue(integerNotification.equals(integerNotification2));
40+
Assert.assertEquals(integerNotification, integerNotification2);
4141
}
4242

4343
@Test
4444
public void onNextIntegerNotificationsWhenNotEqual() {
4545
final Notification<Integer> integerNotification = Notification.createOnNext(1);
4646
final Notification<Integer> integerNotification2 = Notification.createOnNext(2);
47-
Assert.assertFalse(integerNotification.equals(integerNotification2));
47+
Assert.assertNotEquals(integerNotification, integerNotification2);
4848
}
4949

5050
@Test
5151
@Ignore("Nulls are not allowed")
5252
public void onErrorIntegerNotificationDoesNotEqualNullNotification() {
5353
final Notification<Integer> integerNotification = Notification.createOnError(new Exception());
5454
final Notification<Integer> nullNotification = Notification.createOnError(null);
55-
Assert.assertFalse(integerNotification.equals(nullNotification));
55+
Assert.assertNotEquals(integerNotification, nullNotification);
5656
}
5757

5858
@Test
5959
@Ignore("Nulls are not allowed")
6060
public void onErrorNullNotificationDoesNotEqualIntegerNotification() {
6161
final Notification<Integer> integerNotification = Notification.createOnError(new Exception());
6262
final Notification<Integer> nullNotification = Notification.createOnError(null);
63-
Assert.assertFalse(nullNotification.equals(integerNotification));
63+
Assert.assertNotEquals(nullNotification, integerNotification);
6464
}
6565

6666
@Test
6767
public void onErrorIntegerNotificationsWhenEqual() {
6868
final Exception exception = new Exception();
6969
final Notification<Integer> onErrorNotification = Notification.createOnError(exception);
7070
final Notification<Integer> onErrorNotification2 = Notification.createOnError(exception);
71-
Assert.assertTrue(onErrorNotification.equals(onErrorNotification2));
71+
Assert.assertEquals(onErrorNotification, onErrorNotification2);
7272
}
7373

7474
@Test
7575
public void onErrorIntegerNotificationWhenNotEqual() {
7676
final Notification<Integer> onErrorNotification = Notification.createOnError(new Exception());
7777
final Notification<Integer> onErrorNotification2 = Notification.createOnError(new Exception());
78-
Assert.assertFalse(onErrorNotification.equals(onErrorNotification2));
78+
Assert.assertNotEquals(onErrorNotification, onErrorNotification2);
7979
}
8080
}

src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableLatestTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ public void simple() {
4444
for (int i = 0; i < 9; i++) {
4545
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
4646

47-
Assert.assertEquals(true, it.hasNext());
47+
Assert.assertTrue(it.hasNext());
4848

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

5252
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
53-
Assert.assertEquals(false, it.hasNext());
53+
Assert.assertFalse(it.hasNext());
5454
}
5555

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

72-
Assert.assertEquals(true, it.hasNext());
72+
Assert.assertTrue(it.hasNext());
7373

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

7777
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
78-
Assert.assertEquals(false, it.hasNext());
78+
Assert.assertFalse(it.hasNext());
7979
}
8080
}
8181

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

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

90-
Assert.assertEquals(false, it.hasNext());
90+
Assert.assertFalse(it.hasNext());
9191

9292
it.next();
9393
}
@@ -166,7 +166,7 @@ public void fasterSource() {
166166
source.onNext(7);
167167
source.onComplete();
168168

169-
Assert.assertEquals(false, it.hasNext());
169+
Assert.assertFalse(it.hasNext());
170170
}
171171

172172
@Ignore("THe target is an enum")

src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableMostRecentTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
public class BlockingFlowableMostRecentTest {
3030
@Test
3131
public void mostRecentNull() {
32-
assertEquals(null, Flowable.<Void>never().blockingMostRecent(null).iterator().next());
32+
assertNull(Flowable.<Void>never().blockingMostRecent(null).iterator().next());
3333
}
3434

3535
@Test
@@ -88,12 +88,12 @@ public void singleSourceManyIterators() {
8888
for (int i = 0; i < 9; i++) {
8989
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
9090

91-
Assert.assertEquals(true, it.hasNext());
91+
Assert.assertTrue(it.hasNext());
9292
Assert.assertEquals(Long.valueOf(i), it.next());
9393
}
9494
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
9595

96-
Assert.assertEquals(false, it.hasNext());
96+
Assert.assertFalse(it.hasNext());
9797
}
9898

9999
}

src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableNextTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ public void singleSourceManyIterators() throws InterruptedException {
319319
BlockingFlowableNext.NextIterator<Long> it = (BlockingFlowableNext.NextIterator<Long>)iter.iterator();
320320

321321
for (long i = 0; i < 10; i++) {
322-
Assert.assertEquals(true, it.hasNext());
322+
Assert.assertTrue(it.hasNext());
323323
Assert.assertEquals(j + "th iteration next", Long.valueOf(i), it.next());
324324
}
325325
terminal.onNext(1);

src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableToFutureTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,6 @@ public void getWithEmptyFlowable() throws Throwable {
120120
public void getWithASingleNullItem() throws Exception {
121121
Flowable<String> obs = Flowable.just((String)null);
122122
Future<String> f = obs.toFuture();
123-
assertEquals(null, f.get());
123+
assertNull(f.get());
124124
}
125125
}

src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableToIteratorTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ public void toIterator() {
3333

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

36-
assertEquals(true, it.hasNext());
36+
assertTrue(it.hasNext());
3737
assertEquals("one", it.next());
3838

39-
assertEquals(true, it.hasNext());
39+
assertTrue(it.hasNext());
4040
assertEquals("two", it.next());
4141

42-
assertEquals(true, it.hasNext());
42+
assertTrue(it.hasNext());
4343
assertEquals("three", it.next());
4444

45-
assertEquals(false, it.hasNext());
45+
assertFalse(it.hasNext());
4646

4747
}
4848

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

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

63-
assertEquals(true, it.hasNext());
63+
assertTrue(it.hasNext());
6464
assertEquals("one", it.next());
6565

66-
assertEquals(true, it.hasNext());
66+
assertTrue(it.hasNext());
6767
it.next();
6868
}
6969

0 commit comments

Comments
 (0)