Search in sources :

Example 6 with TestScheduler

use of rx.schedulers.TestScheduler in project frodo by android10.

the class LogStreamObservableTest method shouldFillInObservableItemsInfo.

@Test
public void shouldFillInObservableItemsInfo() throws Throwable {
    final TestScheduler testScheduler = new TestScheduler();
    loggableObservable.get(observableRule.stringType()).delay(2, TimeUnit.SECONDS).subscribeOn(testScheduler).subscribe(subscriber);
    testScheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    testScheduler.advanceTimeBy(2, TimeUnit.SECONDS);
    final ObservableInfo observableInfo = loggableObservable.getInfo();
    final Optional<Integer> totalEmittedItems = observableInfo.getTotalEmittedItems();
    final Optional<Long> totalExecutionTime = observableInfo.getTotalExecutionTime();
    assertThat(totalEmittedItems.isPresent()).isTrue();
    assertThat(totalEmittedItems.get()).isEqualTo(1);
}
Also used : TestScheduler(rx.schedulers.TestScheduler) Test(org.junit.Test)

Example 7 with TestScheduler

use of rx.schedulers.TestScheduler in project RxLifecycle by trello.

the class UntilCorrespondingEventSingleTransformerTest method setup.

@Before
public void setup() {
    lifecycle = PublishSubject.create();
    testSubscriber = new TestSubscriber<>();
    testScheduler = new TestScheduler();
}
Also used : TestScheduler(rx.schedulers.TestScheduler) Before(org.junit.Before)

Example 8 with TestScheduler

use of rx.schedulers.TestScheduler in project RxLifecycle by trello.

the class UntilEventSingleTransformerTest method setup.

@Before
public void setup() {
    lifecycle = PublishSubject.create();
    testSubscriber = new TestSubscriber<>();
    testScheduler = new TestScheduler();
}
Also used : TestScheduler(rx.schedulers.TestScheduler) Before(org.junit.Before)

Example 9 with TestScheduler

use of rx.schedulers.TestScheduler in project RxLifecycle by trello.

the class UntilLifecycleSingleTransformerTest method setup.

@Before
public void setup() {
    lifecycle = PublishSubject.create();
    testSubscriber = new TestSubscriber<>();
    testScheduler = new TestScheduler();
}
Also used : TestScheduler(rx.schedulers.TestScheduler) Before(org.junit.Before)

Example 10 with TestScheduler

use of rx.schedulers.TestScheduler in project AnDevCon-RxPatterns by colintheshots.

the class Example16Test method should_test_observable_interval.

// http://stackoverflow.com/questions/26699147/how-to-use-testscheduler-in-rxjava
@Test
public void should_test_observable_interval() {
    TestScheduler scheduler = new TestScheduler();
    final List<Long> result = new ArrayList<>();
    Observable.interval(1, TimeUnit.SECONDS, scheduler).take(5).subscribe(new Action1<Long>() {

        @Override
        public void call(Long aLong) {
            result.add(aLong);
        }
    });
    assertTrue(result.isEmpty());
    scheduler.advanceTimeBy(2, TimeUnit.SECONDS);
    assertEquals(2, result.size());
    scheduler.advanceTimeBy(10, TimeUnit.SECONDS);
    assertEquals(5, result.size());
}
Also used : ArrayList(java.util.ArrayList) Long(java.lang.Long) TestScheduler(rx.schedulers.TestScheduler) Override(java.lang.Override) Test(org.junit.Test)

Aggregations

TestScheduler (rx.schedulers.TestScheduler)11 Test (org.junit.Test)8 TestSubscriber (rx.observers.TestSubscriber)6 Override (java.lang.Override)3 List (java.util.List)3 Before (org.junit.Before)3 Scheduler (rx.Scheduler)2 Action0 (rx.functions.Action0)2 KSRobolectricTestCase (com.kickstarter.KSRobolectricTestCase)1 Environment (com.kickstarter.libs.Environment)1 Long (java.lang.Long)1 ArrayList (java.util.ArrayList)1 TimeUnit (java.util.concurrent.TimeUnit)1 TimeoutException (java.util.concurrent.TimeoutException)1