First time testing Rx, so please give some advice.
Need to test observable chain in model that gives as a result 21 data objects:
public Observable<BaseUnit> exec(int inputNumber) {
return getListObservable(inputNumber).subscribeOn(Schedulers.computation())
.flatMap(resultList -> getOperationsObservable()
.flatMap(operationElem -> getResultListObservable(resultList)
.flatMap(listElem -> Observable.just(listElem)
.flatMap(__ -> calculate(operationElem, listElem)
.subscribeOn(Schedulers.computation())))));
}
Here is some way I tried.
First try (here I have problems with get results and check them separately, because results of calculations inside each object unknown):
TestObserver<BaseUnit> observer = repository.exec(1000000)
.test()
.awaitDone(5, TimeUnit.SECONDS)
.assertNoErrors()
.assertValueCount(21)
.assertComplete();
Second way:
ArrayList<BaseUnit> result = new ArrayList<>();
Observable<BaseUnit> observable = repository.exec(1000000);
observable.subscribe(result::add);
try {
TimeUnit.MILLISECONDS.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
assertNotNull(result);
assertEquals(21, result.size());
// here may be some loop of "assers"
Is that correct to test like I pointed it second way with time delay and loop?
How to check correctly that as a result it gives 21 object and check with condition that some property of data class is greater than zero? Is there any other cheks that need to be performed?
Also have one general question: need to test mvp presenter that use this model method and as a result display recieved values. How to do this using only JUnit4?