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


Java TestScheduler.triggerActions方法代码示例

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


在下文中一共展示了TestScheduler.triggerActions方法的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: 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

示例4: 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

示例5: 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

示例6: 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

示例7: testMaxIdleTime

import io.reactivex.schedulers.TestScheduler; //导入方法依赖的package包/类
@Test
public void testMaxIdleTime() throws InterruptedException {
    TestScheduler s = new TestScheduler();
    AtomicInteger count = new AtomicInteger();
    AtomicInteger disposed = new AtomicInteger();
    Pool<Integer> pool = NonBlockingPool //
            .factory(() -> count.incrementAndGet()) //
            .healthCheck(n -> true) //
            .maxSize(3) //
            .maxIdleTime(1, TimeUnit.MINUTES) //
            .disposer(n -> disposed.incrementAndGet()) //
            .scheduler(s) //
            .build();
    TestSubscriber<Member<Integer>> ts = new FlowableSingleDeferUntilRequest<>( //
            pool.member()) //
                    .doOnNext(m -> m.checkin()) //
                    .doOnNext(System.out::println) //
                    .doOnRequest(t -> System.out.println("test request=" + t)) //
                    .test(1);
    s.triggerActions();
    ts.assertValueCount(1);
    assertEquals(0, disposed.get());
    s.advanceTimeBy(1, TimeUnit.MINUTES);
    s.triggerActions();
    assertEquals(1, disposed.get());
}
 
开发者ID:davidmoten,项目名称:rxjava2-jdbc,代码行数:27,代码来源:NonBlockingPoolTest.java

示例8: testConnectionPoolRecylesAlternating

import io.reactivex.schedulers.TestScheduler; //导入方法依赖的package包/类
@Test
public void testConnectionPoolRecylesAlternating() {
    TestScheduler s = new TestScheduler();
    AtomicInteger count = new AtomicInteger();
    Pool<Integer> pool = NonBlockingPool //
            .factory(() -> count.incrementAndGet()) //
            .healthCheck(n -> true) //
            .maxSize(2) //
            .maxIdleTime(1, TimeUnit.MINUTES) //
            .scheduler(s) //
            .build();
    TestSubscriber<Integer> ts = new FlowableSingleDeferUntilRequest<>(pool.member()) //
            .repeat() //
            .doOnNext(m -> m.checkin()) //
            .map(m -> m.value()) //
            .test(4); //
    s.triggerActions();
    ts.assertValueCount(4) //
            .assertNotTerminated();
    List<Object> list = ts.getEvents().get(0);
    // all 4 connections released were the same
    assertTrue(list.get(0) == list.get(1));
    assertTrue(list.get(1) == list.get(2));
    assertTrue(list.get(2) == list.get(3));
}
 
开发者ID:davidmoten,项目名称:rxjava2-jdbc,代码行数:26,代码来源:NonBlockingPoolTest.java

示例9: testMemberAvailableAfterCreationScheduledIsUsedImmediately

import io.reactivex.schedulers.TestScheduler; //导入方法依赖的package包/类
@Test
public void testMemberAvailableAfterCreationScheduledIsUsedImmediately() throws InterruptedException {
    TestScheduler ts = new TestScheduler();
    Scheduler s = createScheduleToDelayCreation(ts);
    AtomicInteger count = new AtomicInteger();
    Pool<Integer> pool = NonBlockingPool //
            .factory(() -> count.incrementAndGet()) //
            .createRetryInterval(10, TimeUnit.MINUTES) //
            .maxSize(2) //
            .maxIdleTime(1, TimeUnit.HOURS) //
            .scheduler(s) //
            .build();
    List<Member<Integer>> list = new ArrayList<Member<Integer>>();
    pool.member().doOnSuccess(m -> list.add(m)).subscribe();
    assertEquals(0, list.size());
    ts.advanceTimeBy(1, TimeUnit.MINUTES);
    ts.triggerActions();
    assertEquals(1, list.size());
    pool.member().doOnSuccess(m -> list.add(m)).subscribe();
    list.get(0).checkin();
    ts.triggerActions();
    assertEquals(2, list.size());
}
 
开发者ID:davidmoten,项目名称:rxjava2-jdbc,代码行数:24,代码来源:NonBlockingPoolTest.java

示例10: onViewCreatedUsersReceived

import io.reactivex.schedulers.TestScheduler; //导入方法依赖的package包/类
@Test
public void onViewCreatedUsersReceived() throws Exception {
    List<User> users = new ArrayList<>();
    TestScheduler scheduler = new TestScheduler();
    PublishSubject<List<User>> subject = PublishSubject.create();
    subject.subscribeOn(scheduler);
    when(mInteractor.getUserList()).thenReturn(subject);
    ListingActivity mock = Mockito.mock(ListingActivity.class, new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            if (invocation.getMethod().getReturnType().equals(Observable.class))
                return PublishSubject.create();
            else return null;
        }
    });
    mPresenter.attachView(mock);
    mPresenter.detachView(false);
    verify(mInteractor).getUserList();
    subject.onNext(users);
    scheduler.triggerActions();
    verify(mView, never()).setUserList(users);
    verify(mView, never()).showContent();
    verify(mView, never()).showError(any(Throwable.class));
}
 
开发者ID:mkoslacz,项目名称:Moviper,代码行数:25,代码来源:ListingPresenterWithoutViewTest.java

示例11: onViewCreatedFailed

import io.reactivex.schedulers.TestScheduler; //导入方法依赖的package包/类
@Test
public void onViewCreatedFailed() throws Exception {
    TestScheduler scheduler = new TestScheduler();
    PublishSubject<List<User>> subject = PublishSubject.create();
    subject.subscribeOn(scheduler);
    when(mInteractor.getUserList()).thenReturn(subject);
    ListingActivity mock = Mockito.mock(ListingActivity.class, new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            if (invocation.getMethod().getReturnType().equals(Observable.class))
                return PublishSubject.create();
            else return null;
        }
    });
    mPresenter.attachView(mock);
    mPresenter.detachView(false);
    verify(mInteractor).getUserList();
    IOException e = new IOException();
    subject.onError(e);
    scheduler.triggerActions();
    verify(mView, never()).setUserList(any(List.class));
    verify(mView, never()).showContent();
    verify(mView, never()).showError(e);
}
 
开发者ID:mkoslacz,项目名称:Moviper,代码行数:25,代码来源:ListingPresenterWithoutViewTest.java

示例12: onViewCreatedUsersReceived

import io.reactivex.schedulers.TestScheduler; //导入方法依赖的package包/类
@Test
public void onViewCreatedUsersReceived() throws Exception {
    List<User> users = new ArrayList<>();
    TestScheduler scheduler = new TestScheduler();
    PublishSubject<List<User>> subject = PublishSubject.create();
    subject.subscribeOn(scheduler);
    when(mInteractor.getUserList()).thenReturn(subject);
    mPresenter.attachView(mView);
    verify(mView).showLoading();
    verify(mInteractor).getUserList();
    subject.onNext(users);
    scheduler.triggerActions();
    verify(mView).setUserList(users);
    verify(mView).showContent();
    verify(mView, never()).showError(any(Throwable.class));
}
 
开发者ID:mkoslacz,项目名称:Moviper,代码行数:17,代码来源:ListingPresenterTest.java

示例13: onViewCreatedFailed

import io.reactivex.schedulers.TestScheduler; //导入方法依赖的package包/类
@Test
public void onViewCreatedFailed() throws Exception {
    TestScheduler scheduler = new TestScheduler();
    PublishSubject<List<User>> subject = PublishSubject.create();
    subject.subscribeOn(scheduler);
    when(mInteractor.getUserList()).thenReturn(subject);
    mPresenter.attachView(mView);
    verify(mView).showLoading();
    verify(mInteractor).getUserList();
    IOException e = new IOException();
    subject.onError(e);
    scheduler.triggerActions();
    verify(mView, never()).setUserList(any(List.class));
    verify(mView, never()).showContent();
    verify(mView).showError(e);
}
 
开发者ID:mkoslacz,项目名称:Moviper,代码行数:17,代码来源:ListingPresenterTest.java

示例14: testPoolFactoryWhenFailsThenRecovers

import io.reactivex.schedulers.TestScheduler; //导入方法依赖的package包/类
@Test
public void testPoolFactoryWhenFailsThenRecovers() {
    AtomicReference<Throwable> ex = new AtomicReference<>();
    Consumer<? super Throwable> handler = RxJavaPlugins.getErrorHandler();
    RxJavaPlugins.setErrorHandler(t -> ex.set(t));
    try {
        TestScheduler s = new TestScheduler();
        AtomicInteger c = new AtomicInteger();
        NonBlockingPool<Integer> pool = NonBlockingPool.factory(() -> {
            if (c.getAndIncrement() == 0) {
                throw new TestException();
            } else {
                return c.get();
            }
        }) //
                .maxSize(1) //
                .scheduler(s) //
                .createRetryInterval(10, TimeUnit.SECONDS) //
                .build();
        TestObserver<Integer> ts = pool.member() //
                .map(m -> m.value()) //
                .test() //
                .assertNotTerminated() //
                .assertNoValues();
        s.triggerActions();
        assertTrue(ex.get() instanceof UndeliverableException);
        assertTrue(((UndeliverableException) ex.get()).getCause() instanceof TestException);
        s.advanceTimeBy(10, TimeUnit.SECONDS);
        s.triggerActions();
        ts.assertComplete();
        ts.assertValue(2);
    } finally {
        RxJavaPlugins.setErrorHandler(handler);
    }
}
 
开发者ID:davidmoten,项目名称:rxjava2-jdbc,代码行数:36,代码来源:NonBlockingPoolTest.java

示例15: onViewCreatedUsersReceived

import io.reactivex.schedulers.TestScheduler; //导入方法依赖的package包/类
@Test
public void onViewCreatedUsersReceived() throws Exception {
    List<User> users = new ArrayList<>();
    TestScheduler scheduler = new TestScheduler();
    TestSubject<List<User>> subject = TestSubject.create(scheduler);
    when(mInteractor.getUserList()).thenReturn(subject);
    mPresenter.onViewCreated();
    verify(mView, never()).showLoading();
    verify(mInteractor).getUserList();
    subject.onNext(users);
    scheduler.triggerActions();
    verify(mView, never()).setUserList(users);
    verify(mView, never()).showContent();
    verify(mView, never()).showError(any());
}
 
开发者ID:mkoslacz,项目名称:Moviper,代码行数:16,代码来源:ListingPresenterWithoutViewTest.java


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