Skip to content

Commit

Permalink
Merge pull request #2862 from davidmoten/test-warnings
Browse files Browse the repository at this point in the history
Cleanup warnings in test source
  • Loading branch information
akarnokd committed Apr 9, 2015
2 parents a9cd938 + 5d513f2 commit 4d4a33c
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 40 deletions.
6 changes: 5 additions & 1 deletion src/test/java/rx/CovarianceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public String call(Movie m) {
assertEquals(6, ts.getOnNextEvents().size());
}

@SuppressWarnings("unused")
@Test
public void testCovarianceOfCompose() {
Observable<HorrorMovie> movie = Observable.just(new HorrorMovie());
Expand All @@ -119,6 +120,7 @@ public Observable<Movie> call(Observable<Movie> t1) {
});
}

@SuppressWarnings("unused")
@Test
public void testCovarianceOfCompose2() {
Observable<Movie> movie = Observable.<Movie> just(new HorrorMovie());
Expand All @@ -130,6 +132,7 @@ public Observable<HorrorMovie> call(Observable<Movie> t1) {
});
}

@SuppressWarnings("unused")
@Test
public void testCovarianceOfCompose3() {
Observable<Movie> movie = Observable.<Movie>just(new HorrorMovie());
Expand All @@ -147,6 +150,7 @@ public HorrorMovie call(HorrorMovie horrorMovie) {
});
}

@SuppressWarnings("unused")
@Test
public void testCovarianceOfCompose4() {
Observable<HorrorMovie> movie = Observable.just(new HorrorMovie());
Expand Down Expand Up @@ -201,7 +205,7 @@ public Observable<Movie> call(List<List<Movie>> listOfLists) {
oldList.removeAll(newList);

// for all left in the oldList we'll create DROP events
for (Movie old : oldList) {
for (@SuppressWarnings("unused") Movie old : oldList) {
delta.add(new Movie());
}

Expand Down
6 changes: 3 additions & 3 deletions src/test/java/rx/ObservableTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -1054,9 +1054,9 @@ public Observable<String> call(String s) {

@Test
public void testTakeWhileToList() {
int[] nums = {1, 2, 3};
final int expectedCount = 3;
final AtomicInteger count = new AtomicInteger();
for(final int n: nums) {
for (int i = 0;i < expectedCount; i++) {
Observable
.just(Boolean.TRUE, Boolean.FALSE)
.takeWhile(new Func1<Boolean, Boolean>() {
Expand All @@ -1074,7 +1074,7 @@ public void call(List<Boolean> booleans) {
})
.subscribe();
}
assertEquals(nums.length, count.get());
assertEquals(expectedCount, count.get());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void testCancelledBeforeSubscribe() throws Exception {

TestSubscriber<Object> testSubscriber = new TestSubscriber<Object>(o);
testSubscriber.unsubscribe();
Subscription sub = Observable.from(future).subscribe(testSubscriber);
Observable.from(future).subscribe(testSubscriber);
assertEquals(0, testSubscriber.getOnErrorEvents().size());
assertEquals(0, testSubscriber.getOnCompletedEvents().size());
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/rx/internal/operators/OperatorConcatTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -485,11 +485,11 @@ public boolean isUnsubscribed() {
private final T seed;
private final int size;

public TestObservable(T... values) {
public TestObservable(@SuppressWarnings("unchecked") T... values) {
this(null, null, values);
}

public TestObservable(CountDownLatch once, CountDownLatch okToContinue, T... values) {
public TestObservable(CountDownLatch once, CountDownLatch okToContinue, @SuppressWarnings("unchecked") T... values) {
this.values = Arrays.asList(values);
this.size = this.values.size();
this.once = once;
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/rx/internal/operators/OperatorDoOnEachTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ public void call(String s) {
@Test
public void testIssue1451Case1() {
// https://github.com/Netflix/RxJava/issues/1451
int[] nums = { 1, 2, 3 };
final int expectedCount = 3;
final AtomicInteger count = new AtomicInteger();
for (final int n : nums) {
for (int i=0; i < expectedCount; i++) {
Observable
.just(Boolean.TRUE, Boolean.FALSE)
.takeWhile(new Func1<Boolean, Boolean>() {
Expand All @@ -143,15 +143,15 @@ public void call(List<Boolean> booleans) {
})
.subscribe();
}
assertEquals(nums.length, count.get());
assertEquals(expectedCount, count.get());
}

@Test
public void testIssue1451Case2() {
// https://github.com/Netflix/RxJava/issues/1451
int[] nums = { 1, 2, 3 };
final int expectedCount = 3;
final AtomicInteger count = new AtomicInteger();
for (final int n : nums) {
for (int i=0; i < expectedCount; i++) {
Observable
.just(Boolean.TRUE, Boolean.FALSE, Boolean.FALSE)
.takeWhile(new Func1<Boolean, Boolean>() {
Expand All @@ -169,7 +169,7 @@ public void call(List<Boolean> booleans) {
})
.subscribe();
}
assertEquals(nums.length, count.get());
assertEquals(expectedCount, count.get());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import org.junit.Assert;
import org.junit.Test;

import rx.Observer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import java.util.concurrent.TimeUnit;

import org.junit.Test;
import org.mockito.Mockito;

Expand Down Expand Up @@ -109,7 +107,6 @@ public String call(String s) {

@Test
public void testResumeNextWithFailedOnSubscribe() {
Subscription s = mock(Subscription.class);
Observable<String> testObservable = Observable.create(new OnSubscribe<String>() {

@Override
Expand All @@ -132,7 +129,6 @@ public void call(Subscriber<? super String> t1) {

@Test
public void testResumeNextWithFailedOnSubscribeAsync() {
Subscription s = mock(Subscription.class);
Observable<String> testObservable = Observable.create(new OnSubscribe<String>() {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public void testConnectWithNoSubscriber() {
co.connect();
// Emit 0
scheduler.advanceTimeBy(15, TimeUnit.MILLISECONDS);
TestSubscriber subscriber = new TestSubscriber<Long>();
TestSubscriber<Long> subscriber = new TestSubscriber<Long>();
co.subscribe(subscriber);
// Emit 1 and 2
scheduler.advanceTimeBy(50, TimeUnit.MILLISECONDS);
Expand Down
45 changes: 27 additions & 18 deletions src/test/java/rx/internal/operators/OperatorReplayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,24 @@
*/
package rx.internal.operators;

import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.notNull;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.notNull;
import static org.mockito.Mockito.*;

import org.junit.Test;
import org.mockito.InOrder;


import rx.Observable;
import rx.Observer;
import rx.Scheduler;
Expand Down Expand Up @@ -523,14 +529,15 @@ public void call() {
/**
* test the basic expectation of OperatorMulticast via replay
*/
@SuppressWarnings("unchecked")
@Test
public void testIssue2191_UnsubscribeSource() {
// setup mocks
Action1 sourceNext = mock(Action1.class);
Action1<Integer> sourceNext = mock(Action1.class);
Action0 sourceCompleted = mock(Action0.class);
Action0 sourceUnsubscribed = mock(Action0.class);
Observer spiedSubscriberBeforeConnect = mock(Observer.class);
Observer spiedSubscriberAfterConnect = mock(Observer.class);
Observer<Integer> spiedSubscriberBeforeConnect = mock(Observer.class);
Observer<Integer> spiedSubscriberAfterConnect = mock(Observer.class);

// Observable under test
Observable<Integer> source = Observable.just(1,2);
Expand Down Expand Up @@ -570,17 +577,18 @@ public void testIssue2191_UnsubscribeSource() {
*
* @throws Exception
*/
@SuppressWarnings("unchecked")
@Test
public void testIssue2191_SchedulerUnsubscribe() throws Exception {
// setup mocks
Action1 sourceNext = mock(Action1.class);
Action1<Integer> sourceNext = mock(Action1.class);
Action0 sourceCompleted = mock(Action0.class);
Action0 sourceUnsubscribed = mock(Action0.class);
final Scheduler mockScheduler = mock(Scheduler.class);
final Subscription mockSubscription = mock(Subscription.class);
Worker spiedWorker = workerSpy(mockSubscription);
Observer mockObserverBeforeConnect = mock(Observer.class);
Observer mockObserverAfterConnect = mock(Observer.class);
Observer<Integer> mockObserverBeforeConnect = mock(Observer.class);
Observer<Integer> mockObserverAfterConnect = mock(Observer.class);

when(mockScheduler.createWorker()).thenReturn(spiedWorker);

Expand Down Expand Up @@ -626,18 +634,19 @@ public void testIssue2191_SchedulerUnsubscribe() throws Exception {
*
* @throws Exception
*/
@SuppressWarnings("unchecked")
@Test
public void testIssue2191_SchedulerUnsubscribeOnError() throws Exception {
// setup mocks
Action1 sourceNext = mock(Action1.class);
Action1<Integer> sourceNext = mock(Action1.class);
Action0 sourceCompleted = mock(Action0.class);
Action1 sourceError = mock(Action1.class);
Action1<Throwable> sourceError = mock(Action1.class);
Action0 sourceUnsubscribed = mock(Action0.class);
final Scheduler mockScheduler = mock(Scheduler.class);
final Subscription mockSubscription = mock(Subscription.class);
Worker spiedWorker = workerSpy(mockSubscription);
Observer mockObserverBeforeConnect = mock(Observer.class);
Observer mockObserverAfterConnect = mock(Observer.class);
Observer<Integer> mockObserverBeforeConnect = mock(Observer.class);
Observer<Integer> mockObserverAfterConnect = mock(Observer.class);

when(mockScheduler.createWorker()).thenReturn(spiedWorker);

Expand Down Expand Up @@ -682,14 +691,14 @@ public void testIssue2191_SchedulerUnsubscribeOnError() throws Exception {
verifyNoMoreInteractions(mockObserverAfterConnect);
}

private static void verifyObserverMock(Observer mock, int numSubscriptions, int numItemsExpected) {
verify(mock, times(numItemsExpected)).onNext(notNull());
private static void verifyObserverMock(Observer<Integer> mock, int numSubscriptions, int numItemsExpected) {
verify(mock, times(numItemsExpected)).onNext((Integer) notNull());
verify(mock, times(numSubscriptions)).onCompleted();
verifyNoMoreInteractions(mock);
}

private static void verifyObserver(Observer mock, int numSubscriptions, int numItemsExpected, Throwable error) {
verify(mock, times(numItemsExpected)).onNext(notNull());
private static void verifyObserver(Observer<Integer> mock, int numSubscriptions, int numItemsExpected, Throwable error) {
verify(mock, times(numItemsExpected)).onNext((Integer) notNull());
verify(mock, times(numSubscriptions)).onError(error);
verifyNoMoreInteractions(mock);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import rx.functions.Action0;
import rx.schedulers.TestScheduler;
import rx.subjects.PublishSubject;
import rx.subscriptions.Subscriptions;

public class OperatorSampleTest {
private TestScheduler scheduler;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/rx/internal/operators/OperatorScanTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public void testScanShouldNotRequestZero() {
final AtomicReference<Producer> producer = new AtomicReference<Producer>();
Observable<Integer> o = Observable.create(new Observable.OnSubscribe<Integer>() {
@Override
public void call(final Subscriber subscriber) {
public void call(final Subscriber<? super Integer> subscriber) {
Producer p = spy(new Producer() {

private AtomicBoolean requested = new AtomicBoolean(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import rx.Observable;
import rx.Observer;
import rx.functions.Func1;
import rx.functions.Func2;

public class OperatorSkipWhileTest {

Expand Down

0 comments on commit 4d4a33c

Please sign in to comment.