当前位置: 首页>>代码示例>>Java>>正文


Java TestScheduler类代码示例

本文整理汇总了Java中io.reactivex.schedulers.TestScheduler的典型用法代码示例。如果您正苦于以下问题:Java TestScheduler类的具体用法?Java TestScheduler怎么用?Java TestScheduler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TestScheduler类属于io.reactivex.schedulers包,在下文中一共展示了TestScheduler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setUp

import io.reactivex.schedulers.TestScheduler; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);

    testScheduler = new TestScheduler();
    homePresenter = new HomePresenter(contentRepository,
            new TestSchedulerProvider(testScheduler),
            new HomeItemViewModelFactory());

    // mock the Single:
    when(contentRepository.getContentItems()).thenReturn(Single.just(Collections.emptyList()));

    homePresenter.attachView(homeView);

    // trigger the initial load:
    testScheduler.triggerActions();

    // The presenter wont't update the view unless it's active:
    when(homeView.isActive()).thenReturn(true);
}
 
开发者ID:Frank1234,项目名称:FireBaseTest,代码行数:21,代码来源:HomePresenterTest.java

示例2: setUp

import io.reactivex.schedulers.TestScheduler; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);

    int itemId = 2;
    viewModel = new ContentViewModel();
    testScheduler = new TestScheduler();
    contentPresenter = new ContentPresenter(contentRepository,
            new TestSchedulerProvider(testScheduler),
            itemId, viewModel);

    // mock the Single:
    when(contentRepository.getContentItem(itemId)).thenReturn(Single.just(contentItem));

    contentPresenter.attachView(contentView);

    // trigger the initial load:
    testScheduler.triggerActions();

    // The presenter wont't update the view unless it's active:
    when(contentView.isActive()).thenReturn(true);
}
 
开发者ID:Frank1234,项目名称:FireBaseTest,代码行数:23,代码来源:ContentPresenterTest.java

示例3: test_interval

import io.reactivex.schedulers.TestScheduler; //导入依赖的package包/类
@Test
public void test_interval()
{
	TestScheduler testScheduler=new TestScheduler();
	Observable<Long>observable=Observable.interval(1, TimeUnit.SECONDS,testScheduler).take(5);
	TestObserver<Long> testObserver=new TestObserver<>();

	
	observable.subscribeOn(testScheduler).subscribe(testObserver);
	
	testObserver.assertNoValues();
	testObserver.assertNotComplete();
	testObserver.assertNoErrors();
	
	testScheduler.advanceTimeBy(1, TimeUnit.SECONDS);
	testObserver.assertValueCount(1);
	testObserver.assertValues(0l);
	
	testScheduler.advanceTimeTo(6, TimeUnit.SECONDS);
	testObserver.assertValueCount(5);
	testObserver.assertValues(0l,1l,2l,3l,4l);
}
 
开发者ID:PacktPublishing,项目名称:Reactive-Programming-With-Java-9,代码行数:23,代码来源:Modern_Testing.java

示例4: shouldBeAbleToDisplayMovies

import io.reactivex.schedulers.TestScheduler; //导入依赖的package包/类
@Test
    public void shouldBeAbleToDisplayMovies() {
//        System.out.println(MainThread);


        TestScheduler testScheduler = new TestScheduler();
        TestObserver<List<Movie>> testObserver = new TestObserver<>();
        Observable<List<Movie>> responseObservable = Observable.just(movies)
                .subscribeOn(testScheduler)
                .observeOn(testScheduler);

        responseObservable.subscribe(testObserver);
        when(interactor.fetchMovies()).thenReturn(responseObservable);

        presenter.setView(view);
        testScheduler.triggerActions();

        testObserver.assertNoErrors();
        testObserver.onComplete();
        verify(view).showMovies(movies);
    }
 
开发者ID:boyangyuu,项目名称:ILoveMovie,代码行数:22,代码来源:MoviesListingPresenterImplTest.java

示例5: shouldBeAbleToShowTrailers

import io.reactivex.schedulers.TestScheduler; //导入依赖的package包/类
@Test
public void shouldBeAbleToShowTrailers() {
    //
    TestScheduler testScheduler1 = new TestScheduler();
    Observable<VideoWrapper> response1 = Observable.just(videoWrapper)
            .subscribeOn(testScheduler1)
            .observeOn(AndroidSchedulers.mainThread());
    TestObserver<VideoWrapper> observer = new TestObserver<>();
    response1.subscribe(observer);

    when(movieDetailsInteractor.fetchVideos(anyString())).thenReturn(response1);
    movieDetailsPresenter.displayTrails(movie.getId());
    testScheduler1.triggerActions(); // 为什么在前面
    observer.assertNoErrors();
    observer.assertComplete();
    verify(view).showTrailers(videoWrapper.getVideos());
}
 
开发者ID:boyangyuu,项目名称:ILoveMovie,代码行数:18,代码来源:MovieDetailsPresenterImplTest.java

示例6: shouldBeAbleToShowReviews

import io.reactivex.schedulers.TestScheduler; //导入依赖的package包/类
@Test
public void shouldBeAbleToShowReviews() {
    TestScheduler testScheduler = new TestScheduler();
    TestObserver<ReviewWrapper> testObserver = new TestObserver<>();
    Observable<ReviewWrapper> responseObservable = Observable.just(reviewWrapper)
            .subscribeOn(testScheduler)
            .observeOn(AndroidSchedulers.mainThread());

    responseObservable.subscribe(testObserver);

    when(movieDetailsInteractor.fetchReviews(anyString())).thenReturn(responseObservable);

    movieDetailsPresenter.displayReviews(movie.getId());
    testScheduler.triggerActions();

    testObserver.assertNoErrors();
    testObserver.assertComplete();
    verify(view).showReviews(reviewWrapper.getReviews());
}
 
开发者ID:boyangyuu,项目名称:ILoveMovie,代码行数:20,代码来源:MovieDetailsPresenterImplTest.java

示例7: testATestScheduler

import io.reactivex.schedulers.TestScheduler; //导入依赖的package包/类
@Test
public void testATestScheduler() throws Exception {
    TestSubscriber<Long> testSubscriber = new TestSubscriber<>();
    TestScheduler testScheduler = new TestScheduler();

    Flowable.interval(5, TimeUnit.MILLISECONDS, testScheduler)
            .map(x -> x + 1)
            .filter(x -> x % 2 == 0)
            .subscribe(testSubscriber);

    testScheduler.advanceTimeBy(10, TimeUnit.MILLISECONDS);

    testSubscriber.assertNoErrors();
    testSubscriber.assertValues(2L);

    testScheduler.advanceTimeBy(10, TimeUnit.MILLISECONDS);

    testSubscriber.assertNoErrors();
    testSubscriber.assertValues(2L, 4L);
}
 
开发者ID:dhinojosa,项目名称:rxjavatraining,代码行数:21,代码来源:ObservableTestingTest.java

示例8: testBufferingWithNoUpdates

import io.reactivex.schedulers.TestScheduler; //导入依赖的package包/类
@Test
public void testBufferingWithNoUpdates() throws InterruptedException
{
    TestScheduler testScheduler = new TestScheduler();
    SimpleFlowableList<Integer> list = new SimpleFlowableList<>();
    FlowableList<Integer> bufferedList = list.buffer(50, TimeUnit.MILLISECONDS, testScheduler);

    TestSubscriber testSubscriber = new TestSubscriber();

    bufferedList.updates().subscribe(testSubscriber);

    testScheduler.advanceTimeBy(50, TimeUnit.MILLISECONDS);
    testScheduler.triggerActions();
    testSubscriber.awaitCount(1);

    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);

    testScheduler.advanceTimeBy(50, TimeUnit.MILLISECONDS);
    testScheduler.triggerActions();
    testSubscriber.awaitCount(1);

    testSubscriber.dispose();
}
 
开发者ID:mproberts,项目名称:rxtools,代码行数:25,代码来源:BackpressureFlowableListTest.java

示例9: should_not_send_notification_occurring_before_subscribe

import io.reactivex.schedulers.TestScheduler; //导入依赖的package包/类
@Test
public void should_not_send_notification_occurring_before_subscribe() {
    // given
    TestScheduler scheduler = new TestScheduler();
    Recorded<String> event = new Recorded<>(10, Notification.createOnNext("Hello world!"));
    final HotObservable<String> hotObservable = HotObservable.create(scheduler, event);
    // when
    final TestObserver<String> observer = new TestObserver<>();
    scheduler.createWorker().schedule(new Runnable() {
        @Override
        public void run() {
            hotObservable.subscribe(observer);
        }
    }, 15, TimeUnit.MILLISECONDS);
    // then
    scheduler.advanceTimeBy(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
    observer.assertNoValues();
}
 
开发者ID:alexvictoor,项目名称:MarbleTest4J,代码行数:19,代码来源:HotObservableTest.java

示例10: should_not_send_notification_occurring_after_unsubscribe

import io.reactivex.schedulers.TestScheduler; //导入依赖的package包/类
@Test
public void should_not_send_notification_occurring_after_unsubscribe() {
    // given
    TestScheduler scheduler = new TestScheduler();
    Recorded<String> event = new Recorded<>(10, Notification.createOnNext("Hello world!"));
    final HotObservable<String> hotObservable = HotObservable.create(scheduler, event);
    // when
    final TestObserver<String> observer = new TestObserver<>();
    hotObservable.subscribe(observer);

    scheduler.createWorker().schedule(new Runnable() {
        @Override
        public void run() {
            observer.dispose();
        }
    }, 5, TimeUnit.MILLISECONDS);
    // then
    scheduler.advanceTimeBy(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
    observer.assertNoValues();
}
 
开发者ID:alexvictoor,项目名称:MarbleTest4J,代码行数:21,代码来源:HotObservableTest.java

示例11: should_keep_track_of_subscriptions

import io.reactivex.schedulers.TestScheduler; //导入依赖的package包/类
@Test
public void should_keep_track_of_subscriptions() {
    // given
    TestScheduler scheduler = new TestScheduler();
    final HotObservable<String> hotObservable = HotObservable.create(scheduler);
    // when
    final TestObserver<String> observer = new TestObserver<>();

    scheduler.createWorker().schedule(new Runnable() {
        @Override
        public void run() {
            hotObservable.subscribe(observer);
        }
    }, 42, TimeUnit.MILLISECONDS);
    // then
    scheduler.advanceTimeBy(42, TimeUnit.MILLISECONDS);
    assertThat(hotObservable.getSubscriptions())
            .containsExactly(
                    new SubscriptionLog(42, Long.MAX_VALUE)
            );
}
 
开发者ID:alexvictoor,项目名称:MarbleTest4J,代码行数:22,代码来源:HotObservableTest.java

示例12: should_keep_track_of_unsubscriptions

import io.reactivex.schedulers.TestScheduler; //导入依赖的package包/类
@Test
public void should_keep_track_of_unsubscriptions() {
    // given
    TestScheduler scheduler = new TestScheduler();
    final HotObservable<String> hotObservable = HotObservable.create(scheduler);
    // when
    final TestObserver<String> observer = new TestObserver<>();
    hotObservable.subscribe(observer);
    scheduler.createWorker().schedule(new Runnable() {
        @Override
        public void run() {
            observer.dispose();
        }
    }, 42, TimeUnit.MILLISECONDS);
    // then
    scheduler.advanceTimeBy(42, TimeUnit.MILLISECONDS);
    assertThat(hotObservable.getSubscriptions())
            .containsExactly(
                    new SubscriptionLog(0, 42)
            );
}
 
开发者ID:alexvictoor,项目名称:MarbleTest4J,代码行数:22,代码来源:HotObservableTest.java

示例13: should_send_notification_on_subscribe_using_offset

import io.reactivex.schedulers.TestScheduler; //导入依赖的package包/类
@Test
public void should_send_notification_on_subscribe_using_offset() {
    // given
    TestScheduler scheduler = new TestScheduler();
    long offset = 10;
    Recorded<String> event = new Recorded<>(offset, Notification.createOnNext("Hello world!"));
    ColdObservable<String> coldObservable = ColdObservable.create(scheduler, event);
    // when
    TestObserver<String> observer = new TestObserver<>();
    coldObservable.subscribe(observer);
    // then
    scheduler.advanceTimeBy(9, TimeUnit.MILLISECONDS);
    observer.assertNoValues();
    scheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS);
    observer.assertValue("Hello world!");
}
 
开发者ID:alexvictoor,项目名称:MarbleTest4J,代码行数:17,代码来源:ColdObservableTest.java

示例14: should_not_send_notification_after_unsubscribe

import io.reactivex.schedulers.TestScheduler; //导入依赖的package包/类
@Test
public void should_not_send_notification_after_unsubscribe() {
    // given
    TestScheduler scheduler = new TestScheduler();
    long offset = 10;
    Recorded<String> event = new Recorded<>(offset, Notification.createOnNext("Hello world!"));
    ColdObservable<String> coldObservable = ColdObservable.create(scheduler, event);
    final TestObserver<String> observer = new TestObserver<>();
    coldObservable.subscribe(observer);
    // when
    scheduler.createWorker().schedule(new Runnable() {
        @Override
        public void run() {
            observer.dispose();
        }
    }, 5, TimeUnit.MILLISECONDS);
    // then
    scheduler.advanceTimeBy(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
    observer.assertNoValues();
}
 
开发者ID:alexvictoor,项目名称:MarbleTest4J,代码行数:21,代码来源:ColdObservableTest.java

示例15: should_be_cold_and_send_notification_at_subscribe_time

import io.reactivex.schedulers.TestScheduler; //导入依赖的package包/类
@Test
public void should_be_cold_and_send_notification_at_subscribe_time() {
    // given
    TestScheduler scheduler = new TestScheduler();
    Recorded<String> event = new Recorded<>(0, Notification.createOnNext("Hello world!"));
    final ColdObservable<String> coldObservable = ColdObservable.create(scheduler, event);
    // when
    final TestObserver<String> observer = new TestObserver<>();
    scheduler.createWorker().schedule(new Runnable() {
        @Override
        public void run() {
            coldObservable.subscribe(observer);
        }
    }, 42, TimeUnit.SECONDS);
    // then
    scheduler.advanceTimeBy(42, TimeUnit.SECONDS);
    observer.assertValue("Hello world!");
}
 
开发者ID:alexvictoor,项目名称:MarbleTest4J,代码行数:19,代码来源:ColdObservableTest.java


注:本文中的io.reactivex.schedulers.TestScheduler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。