Skip to content

Commit 0a6c9f5

Browse files
dsreesakarnokd
authored andcommitted
Moved tests to FromCallableTest from FromCompletableTest (#5705)
1 parent 98ee8bc commit 0a6c9f5

File tree

2 files changed

+74
-97
lines changed

2 files changed

+74
-97
lines changed

src/test/java/io/reactivex/internal/operators/observable/ObservableFromCallableTest.java

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@
2020
import static org.mockito.ArgumentMatchers.any;
2121
import static org.mockito.Mockito.*;
2222

23+
import java.util.List;
2324
import java.util.concurrent.*;
2425

26+
import io.reactivex.exceptions.TestException;
27+
import io.reactivex.plugins.RxJavaPlugins;
2528
import org.junit.Test;
2629
import org.mockito.invocation.InvocationOnMock;
2730
import org.mockito.stubbing.Answer;
@@ -239,4 +242,75 @@ public Object call() throws Exception {
239242
.test()
240243
.assertFailure(NullPointerException.class);
241244
}
245+
246+
@Test
247+
public void disposedOnArrival() {
248+
final int[] count = { 0 };
249+
Observable.fromCallable(new Callable<Object>() {
250+
@Override
251+
public Object call() throws Exception {
252+
count[0]++;
253+
return 1;
254+
}
255+
})
256+
.test(true)
257+
.assertEmpty();
258+
259+
assertEquals(0, count[0]);
260+
}
261+
262+
@Test
263+
public void disposedOnCall() {
264+
final TestObserver<Integer> to = new TestObserver<Integer>();
265+
266+
Observable.fromCallable(new Callable<Integer>() {
267+
@Override
268+
public Integer call() throws Exception {
269+
to.cancel();
270+
return 1;
271+
}
272+
})
273+
.subscribe(to);
274+
275+
to.assertEmpty();
276+
}
277+
278+
@Test
279+
public void disposedOnCallThrows() {
280+
List<Throwable> errors = TestHelper.trackPluginErrors();
281+
try {
282+
final TestObserver<Integer> to = new TestObserver<Integer>();
283+
284+
Observable.fromCallable(new Callable<Integer>() {
285+
@Override
286+
public Integer call() throws Exception {
287+
to.cancel();
288+
throw new TestException();
289+
}
290+
})
291+
.subscribe(to);
292+
293+
to.assertEmpty();
294+
295+
TestHelper.assertUndeliverable(errors, 0, TestException.class);
296+
} finally {
297+
RxJavaPlugins.reset();
298+
}
299+
}
300+
301+
@Test
302+
public void take() {
303+
Observable.fromCallable(new Callable<Object>() {
304+
@Override
305+
public Object call() throws Exception {
306+
return 1;
307+
}
308+
})
309+
.take(1)
310+
.test()
311+
.assertResult(1);
312+
}
313+
314+
315+
242316
}

src/test/java/io/reactivex/internal/operators/observable/ObservableFromCompletableTest.java

Lines changed: 0 additions & 97 deletions
This file was deleted.

0 commit comments

Comments
 (0)