當前位置: 首頁>>代碼示例>>Java>>正文


Java TestSubscriber.assertValue方法代碼示例

本文整理匯總了Java中io.reactivex.subscribers.TestSubscriber.assertValue方法的典型用法代碼示例。如果您正苦於以下問題:Java TestSubscriber.assertValue方法的具體用法?Java TestSubscriber.assertValue怎麽用?Java TestSubscriber.assertValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.reactivex.subscribers.TestSubscriber的用法示例。


在下文中一共展示了TestSubscriber.assertValue方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getTasks_repositoryCachesAfterFirstSubscription_whenTasksAvailableInLocalStorage

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void getTasks_repositoryCachesAfterFirstSubscription_whenTasksAvailableInLocalStorage() {
    // Given that the local data source has data available
    setTasksAvailable(mTasksLocalDataSource, TASKS);
    // And the remote data source does not have any data available
    setTasksNotAvailable(mTasksRemoteDataSource);

    // When two subscriptions are set
    TestSubscriber<List<Task>> testSubscriber1 = new TestSubscriber<>();
    mTasksRepository.getTasks().subscribe(testSubscriber1);

    TestSubscriber<List<Task>> testSubscriber2 = new TestSubscriber<>();
    mTasksRepository.getTasks().subscribe(testSubscriber2);

    // Then tasks were only requested once from remote and local sources
    verify(mTasksRemoteDataSource).getTasks();
    verify(mTasksLocalDataSource).getTasks();
    //
    assertFalse(mTasksRepository.mCacheIsDirty);
    testSubscriber1.assertValue(TASKS);
    testSubscriber2.assertValue(TASKS);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:TasksRepositoryTest.java

示例2: getTasks_repositoryCachesAfterFirstSubscription_whenTasksAvailableInRemoteStorage

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void getTasks_repositoryCachesAfterFirstSubscription_whenTasksAvailableInRemoteStorage() {
    // Given that the local data source has data available
    setTasksAvailable(mTasksRemoteDataSource, TASKS);
    // And the remote data source does not have any data available
    setTasksNotAvailable(mTasksLocalDataSource);

    // When two subscriptions are set
    TestSubscriber<List<Task>> testSubscriber1 = new TestSubscriber<>();
    mTasksRepository.getTasks().subscribe(testSubscriber1);

    TestSubscriber<List<Task>> testSubscriber2 = new TestSubscriber<>();
    mTasksRepository.getTasks().subscribe(testSubscriber2);

    // Then tasks were only requested once from remote and local sources
    verify(mTasksRemoteDataSource).getTasks();
    verify(mTasksLocalDataSource).getTasks();
    assertFalse(mTasksRepository.mCacheIsDirty);
    testSubscriber1.assertValue(TASKS);
    testSubscriber2.assertValue(TASKS);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:22,代碼來源:TasksRepositoryTest.java

示例3: getTask_requestsSingleTaskFromLocalDataSource

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void getTask_requestsSingleTaskFromLocalDataSource() {
    // Given a stub completed task with title and description in the local repository
    Task task = new Task(TASK_TITLE, "Some Task Description", true);
    Optional<Task> taskOptional = Optional.of(task);
    setTaskAvailable(mTasksLocalDataSource, taskOptional);
    // And the task not available in the remote repository
    setTaskNotAvailable(mTasksRemoteDataSource, taskOptional.get().getId());

    // When a task is requested from the tasks repository
    TestSubscriber<Optional<Task>> testSubscriber = new TestSubscriber<>();
    mTasksRepository.getTask(task.getId()).subscribe(testSubscriber);

    // Then the task is loaded from the database
    verify(mTasksLocalDataSource).getTask(eq(task.getId()));
    testSubscriber.assertValue(taskOptional);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:TasksRepositoryTest.java

示例4: getTask_whenDataNotLocal_fails

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void getTask_whenDataNotLocal_fails() {
    // Given a stub completed task with title and description in the remote repository
    Task task = new Task(TASK_TITLE, "Some Task Description", true);
    Optional<Task> taskOptional = Optional.of(task);
    setTaskAvailable(mTasksRemoteDataSource, taskOptional);
    // And the task not available in the local repository
    setTaskNotAvailable(mTasksLocalDataSource, task.getId());

    // When a task is requested from the tasks repository
    TestSubscriber<Optional<Task>> testSubscriber = new TestSubscriber<>();
    mTasksRepository.getTask(task.getId()).subscribe(testSubscriber);

    // then empty Optional is returned
    testSubscriber.assertValue(Optional.absent());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:TasksRepositoryTest.java

示例5: getTaskWithBothDataSourcesUnavailable_firesOnError

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void getTaskWithBothDataSourcesUnavailable_firesOnError() {
    // Given a task id
    final String taskId = "123";
    // And the local data source has no data available
    setTaskNotAvailable(mTasksLocalDataSource, taskId);
    // And the remote data source has no data available
    setTaskNotAvailable(mTasksRemoteDataSource, taskId);

    // When calling getTask in the repository
    TestSubscriber<Optional<Task>> testSubscriber = new TestSubscriber<>();
    mTasksRepository.getTask(taskId).subscribe(testSubscriber);

    // Verify that error is returned
    testSubscriber.assertValue(Optional.absent());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:TasksRepositoryTest.java

示例6: test

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test public void test() {

        PublishProcessor<String> subject = PublishProcessor.create();
        Flowable<String> source = subject.hide();



        TestSubscriber testSubscriber = new TestSubscriber();
        CompositeDisposable composite = new CompositeDisposable();
        Disposable disposable = source
                .compose(DisposableAttach.<String>to(composite))
                .subscribeWith(testSubscriber);

        subject.onNext("Foo");
        testSubscriber.assertValue("Foo");
        assertTrue(composite.size() == 1);
        composite.dispose();
        assertTrue(composite.size() == 0);
        assertTrue(composite.isDisposed());
        assertTrue(disposable.isDisposed());
        assertTrue(testSubscriber.isDisposed());
    }
 
開發者ID:cp949,項目名稱:DisposableAttach,代碼行數:23,代碼來源:DisposableAttachFlowableTest.java

示例7: getQuestion_ShouldReturnFromCache

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test public void getQuestion_ShouldReturnFromCache() {
  // Given
  question1.setId(1);
  question2.setId(2);
  question3.setId(3);
  repository.caches.addAll(questions);
  TestSubscriber<Question> subscriber = new TestSubscriber<>();

  // When
  repository.getQuestion(1).subscribe(subscriber);

  // Then
  // No interaction with local storage or remote source
  then(localDataSource).shouldHaveZeroInteractions();
  then(remoteDataSource).shouldHaveZeroInteractions();
  // Should return correct question
  subscriber.assertValue(question1);
}
 
開發者ID:quangctkm9207,項目名稱:mvp-android-arch-component,代碼行數:19,代碼來源:QuestionRepositoryTest.java

示例8: shouldPassMessageToLocalStreamWhenSendMessage

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void shouldPassMessageToLocalStreamWhenSendMessage() throws Exception {

    String message = "hello @alex http://youtube.com/q=look (love) there @yui you go http://twitter.com";

    final List<Link> expectedLinks = asList(
            new Link("http://youtube.com/q=look", ""),
            new Link("http://twitter.com", ""));

    when(userResolver.getLoggedInUser()).thenReturn(TestUtils.createMockUser());

    final TestSubscriber<Message> userTestSubscriber = new TestSubscriber<>();
    final Observable<Message> messageViewModelMessages = messageViewModel.localMessageStream();
    messageViewModelMessages.toFlowable(BackpressureStrategy.LATEST).subscribe(userTestSubscriber);
    final Message m = new Message(id, message, Arrays.asList("alex", "yui"),
            Arrays.asList("love"), expectedLinks, TestUtils.createMockUser());

    messageViewModel.sendMessage(message, Arrays.asList("love"), sendScheduler);
    userTestSubscriber.assertValue(m);

}
 
開發者ID:charafau,項目名稱:TurboChat,代碼行數:22,代碼來源:MessageViewModelTest.java

示例9: saveTask_retrievesTask

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void saveTask_retrievesTask() {
    // Given a new task
    final Task newTask = new Task(TITLE, "");
    final Optional<Task> newTaskOptional = Optional.of(newTask);

    // When saved into the persistent repository
    mLocalDataSource.saveTask(newTask);

    // Then the task can be retrieved from the persistent repository
    TestSubscriber<Optional<Task>> testSubscriber = new TestSubscriber<>();
    mLocalDataSource.getTask(newTask.getId()).subscribe(testSubscriber);
    testSubscriber.assertValue(newTaskOptional);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:15,代碼來源:TasksLocalDataSourceTest.java

示例10: getTask_whenTaskNotSaved

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void getTask_whenTaskNotSaved() {
    //Given that no task has been saved
    //When querying for a task, null is returned.
    TestSubscriber<Optional<Task>> testSubscriber = new TestSubscriber<>();
    mLocalDataSource.getTask("1").subscribe(testSubscriber);
    testSubscriber.assertValue(Optional.absent());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:9,代碼來源:TasksLocalDataSourceTest.java

示例11: testProvidedStreamCanBeDiscovered

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testProvidedStreamCanBeDiscovered() {
    providingService.provide(ANY_STREAM_ID, ANY_REACTIVE_STREAM);

    TestSubscriber test = rxFrom(ANY_STREAM_ID).test();
    test.awaitTerminalEvent();
    test.assertValueCount(1);
    test.assertValue(1);
}
 
開發者ID:streamingpool,項目名稱:streamingpool-core,代碼行數:10,代碼來源:ProviderTest.java

示例12: testProvidedUsingHelpersIsDiscovered

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testProvidedUsingHelpersIsDiscovered() {
    provide(ANY_REACTIVE_STREAM).as(ANY_STREAM_ID);
    TestSubscriber test = rxFrom(ANY_STREAM_ID).test();
    test.awaitTerminalEvent();
    test.assertValueCount(1);
    test.assertValue(1);
}
 
開發者ID:streamingpool,項目名稱:streamingpool-core,代碼行數:9,代碼來源:ProviderTest.java

示例13: testOrderedInOrderedOut

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testOrderedInOrderedOut() throws InterruptedException
{
    final int iterations = 100;
    final AtomicInteger counter = new AtomicInteger(0);
    TestSubscriber<Update<Integer>> testSubscriber = new TestSubscriber<>();
    ExecutorService executorService = Executors.newFixedThreadPool(iterations / 4);

    List<Callable<Object>> callbales = new ArrayList<>();
    List<Integer> allEntries = new ArrayList<>();

    for (int i = 0; i < iterations; ++i) {
        allEntries.add(i + 1);

        callbales.add(new Callable<Object>() {
            @Override
            public Object call() throws Exception
            {
                synchronized (counter) {
                    list.add(counter.incrementAndGet());
                }

                return null;
            }
        });
    }

    list.updates().skip(iterations).subscribe(testSubscriber);

    executorService.invokeAll(callbales);

    testSubscriber.assertValue(new Update<>(allEntries, Change.inserted(iterations - 1)));
}
 
開發者ID:mproberts,項目名稱:rxtools,代碼行數:34,代碼來源:BaseFlowableListTest.java

示例14: testAddTransform

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testAddTransform()
{
    SimpleFlowableList<Integer> list = new SimpleFlowableList<>(Arrays.asList(1, 2, 3));

    TestSubscriber<Update<Flowable<String>>> testSubscriber = createIndexedList(list);

    testSubscriber.assertValueCount(1);

    List<Update<Flowable<String>>> onNextEvents = testSubscriber.values();

    assertEquals(Arrays.asList(Change.reloaded()), onNextEvents.get(0).changes);

    List<Flowable<String>> list1 = onNextEvents.get(0).list;

    Flowable<String> item1 = list1.get(0);
    Flowable<String> item2 = list1.get(1);
    Flowable<String> item3 = list1.get(2);

    TestSubscriber<String> test1 = item1.test();
    TestSubscriber<String> test2 = item2.test();
    TestSubscriber<String> test3 = item3.test();

    test1.assertValue("? < 1 > 2");
    test2.assertValue("1 < 2 > 3");
    test3.assertValue("2 < 3 > ?");

    list.add(1, 4);

    test1.assertValues("? < 1 > 2", "? < 1 > 4");
    test2.assertValues("1 < 2 > 3", "4 < 2 > 3");
    test3.assertValueCount(1);

    list.add(5);

    test1.assertValues("? < 1 > 2", "? < 1 > 4");
    test2.assertValues("1 < 2 > 3", "4 < 2 > 3");
    test3.assertValues("2 < 3 > ?", "2 < 3 > 5");
}
 
開發者ID:mproberts,項目名稱:rxtools,代碼行數:40,代碼來源:IndexedFlowableListTest.java

示例15: testRemoveTransform

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testRemoveTransform()
{
    SimpleFlowableList<Integer> list = new SimpleFlowableList<>(Arrays.asList(1, 2, 3, 4));

    TestSubscriber<Update<Flowable<String>>> testSubscriber = createIndexedList(list);

    testSubscriber.assertValueCount(1);

    List<Update<Flowable<String>>> onNextEvents = testSubscriber.values();

    assertEquals(Arrays.asList(Change.reloaded()), onNextEvents.get(0).changes);

    List<Flowable<String>> list1 = onNextEvents.get(0).list;

    Flowable<String> item1 = list1.get(0);
    Flowable<String> item2 = list1.get(1);
    Flowable<String> item3 = list1.get(2);
    Flowable<String> item4 = list1.get(3);

    TestSubscriber<String> test1 = item1.test();
    TestSubscriber<String> test2 = item2.test();
    TestSubscriber<String> test3 = item3.test();
    TestSubscriber<String> test4 = item4.test();

    test1.assertValue("? < 1 > 2");
    test2.assertValue("1 < 2 > 3");
    test3.assertValue("2 < 3 > 4");
    test4.assertValue("3 < 4 > ?");

    list.remove(3);

    test3.assertValues("2 < 3 > 4", "2 < 3 > ?");

    list.remove(1);

    test1.assertValues("? < 1 > 2", "? < 1 > 3");
    test3.assertValues("2 < 3 > 4", "2 < 3 > ?", "1 < 3 > ?");
}
 
開發者ID:mproberts,項目名稱:rxtools,代碼行數:40,代碼來源:IndexedFlowableListTest.java


注:本文中的io.reactivex.subscribers.TestSubscriber.assertValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。