def subject = TestSubject.<ScanResult>create(scheduler) def subscriber = new TestSubscriber() def subscription = repo.scan(3000, unit, schueduler) .subscribe(subscriber) // stubbing scanner.startScan() >> subject when: subject.onNext(Mock(ScanResult)) scheduler.triggerActions() then: 1 * cache.isCached(_) >> false 1 * cache.put(_) >> { Observable.just(it) } 0 * api._ subscriber.assertValueCount(0) when: scheduler.advanceTimeBy(3000, unit) then: 1 * api.check({ it.size() == 1 }) >> Observable.just([...]) subscriber.assertValueCount(1)