Java Code Examples for io.reactivex.subscribers.TestSubscriber#assertValue()

The following examples show how to use io.reactivex.subscribers.TestSubscriber#assertValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MapSomethingToExecuteAsBlockingTest.java    From storio with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void verifyBehavior() {
    final PreparedOperation<String, String, Object> preparedOperation = mock(PreparedOperation.class);

    final String expectedMapResult = "expected_string";

    when(preparedOperation.executeAsBlocking())
            .thenReturn(expectedMapResult);

    TestSubscriber<String> testSubscriber = new TestSubscriber<String>();

    Flowable
            .just(1)
            .map(new MapSomethingToExecuteAsBlocking<Integer, String, String, Object>(preparedOperation))
            .subscribe(testSubscriber);

    verify(preparedOperation, times(1)).executeAsBlocking();

    testSubscriber.assertValue(expectedMapResult);
    testSubscriber.assertNoErrors();
    testSubscriber.assertComplete();
}
 
Example 2
Source File: PreparedDeleteByQueryTest.java    From storio with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldPerformDeletionByQueryFlowable() {
    final DeleteByQueryStub stub = new DeleteByQueryStub();

    final TestSubscriber<DeleteResult> testSubscriber = new TestSubscriber<DeleteResult>();

    new PreparedDeleteByQuery.Builder(stub.storIOSQLite, stub.deleteQuery)
            .withDeleteResolver(stub.deleteResolver)
            .prepare()
            .asRxFlowable(MISSING)
            .subscribe(testSubscriber);

    testSubscriber.awaitTerminalEvent();
    testSubscriber.assertNoErrors();
    testSubscriber.assertValue(stub.expectedDeleteResult);

    verify(stub.storIOSQLite).defaultRxScheduler();
    stub.verifyBehaviour();
}
 
Example 3
Source File: ChangesFilterTest.java    From storio with Apache License 2.0 6 votes vote down vote up
@Test
public void applyForTablesAndTags_shouldSendJustOnceNotificationIfBothTableAndTagAreSatisfy() {
    final TestSubscriber<Changes> testSubscriber = new TestSubscriber<Changes>();

    ChangesFilter
            .applyForTablesAndTags(
                    Flowable.just(Changes.newInstance("target_table", "target_tag")),
                    singleton("target_table"),
                    singleton("target_tag"))
            .subscribe(testSubscriber);

    testSubscriber.assertValueCount(1);
    testSubscriber.assertValue(Changes.newInstance("target_table", "target_tag"));

    testSubscriber.dispose();
}
 
Example 4
Source File: ChangesFilterTest.java    From storio with Apache License 2.0 6 votes vote down vote up
@Test
public void applyForTablesAndTags_shouldNotifyByTag() {
    final TestSubscriber<Changes> testSubscriber = new TestSubscriber<Changes>();

    ChangesFilter
            .applyForTablesAndTags(
                    Flowable.just(Changes.newInstance("another_table", "tag1"),
                            Changes.newInstance("table2", "tag2"),
                            Changes.newInstance("table3")),
                    singleton("table1"),
                    singleton("tag1"))
            .subscribe(testSubscriber);

    // All other Changes should be filtered
    testSubscriber.assertValue(Changes.newInstance("another_table", "tag1"));

    testSubscriber.dispose();
}
 
Example 5
Source File: ChangesFilterTest.java    From storio with Apache License 2.0 6 votes vote down vote up
@Test
public void applyForTablesAndTags_shouldNotifyByTable() {
    final TestSubscriber<Changes> testSubscriber = new TestSubscriber<Changes>();

    ChangesFilter
            .applyForTablesAndTags(
                    Flowable.just(Changes.newInstance("table1", "another_tag"),
                            Changes.newInstance("table2", "tag2"),
                            Changes.newInstance("table3")),
                    singleton("table1"),
                    singleton("tag1"))
            .subscribe(testSubscriber);

    // All other Changes should be filtered
    testSubscriber.assertValue(Changes.newInstance("table1", "another_tag"));

    testSubscriber.dispose();
}
 
Example 6
Source File: ChangesFilterTest.java    From storio with Apache License 2.0 6 votes vote down vote up
@Test
public void applyForTables_shouldFilterRequiredTable() {
    final TestSubscriber<Changes> testSubscriber = new TestSubscriber<Changes>();

    ChangesFilter
            .applyForTables(
                    Flowable.just(Changes.newInstance("table1"),
                            Changes.newInstance("table2"),
                            Changes.newInstance("table3")),
                    singleton("table2"))
            .subscribe(testSubscriber);

    // All other tables should be filtered
    testSubscriber.assertValue(Changes.newInstance("table2"));

    testSubscriber.dispose();
}
 
Example 7
Source File: PutOperationTest.java    From storio with Apache License 2.0 5 votes vote down vote up
@Test
public void insertContentValuesAsSingle() {
    TestSubscriber<Changes> changesTestSubscriber = new TestSubscriber<Changes>();

    storIOContentResolver
            .observeChangesOfUri(TestItem.CONTENT_URI, BackpressureStrategy.MISSING)
            .take(1)
            .subscribe(changesTestSubscriber);

    TestItem testItem = TestItem.create(null, "value");
    ContentValues cv = testItem.toContentValues();

    PutResult insertResult = storIOContentResolver
            .put()
            .contentValues(cv)
            .withPutResolver(testItemContentValuesPutResolver)
            .prepare()
            .asRxSingle()
            .blockingGet();

    assertThat(insertResult.wasInserted()).isTrue();

    Cursor cursor = contentResolver.query(TestItem.CONTENT_URI, null, null, null, null);

    Assertions.assertThat(cursor).hasCount(1);

    cursor.moveToFirst();

    assertThat(testItem.equalsWithoutId(TestItem.fromCursor(cursor))).isTrue();

    changesTestSubscriber.awaitTerminalEvent(60, SECONDS);
    changesTestSubscriber.assertNoErrors();
    changesTestSubscriber.assertValue(Changes.newInstance(TestItem.CONTENT_URI));
}
 
Example 8
Source File: UniToPublisherTest.java    From smallrye-mutiny with Apache License 2.0 5 votes vote down vote up
@Test
public void testCancellationAfterValue() {
    Publisher<Integer> publisher = Uni.createFrom().item(1).convert().toPublisher();
    assertThat(publisher).isNotNull();
    TestSubscriber<Integer> test = Flowable.fromPublisher(publisher).test(0);
    test.assertSubscribed();
    test.request(1);
    // Immediate emission, so cancel is called after the emission.
    test.cancel();
    assertThat(test.isCancelled()).isTrue();
    test.assertValue(1);
    test.assertComplete();
}
 
Example 9
Source File: PutOperationTest.java    From storio with Apache License 2.0 5 votes vote down vote up
@Test
public void insertOneWithNullField() {
    TestSubscriber<Changes> changesTestSubscriber = new TestSubscriber<Changes>();

    storIOContentResolver
            .observeChangesOfUri(TestItem.CONTENT_URI, BackpressureStrategy.MISSING)
            .take(1)
            .subscribe(changesTestSubscriber);

    TestItem testItem = TestItem.create(null, "value", null); // optional value is null

    PutResult insertResult = storIOContentResolver
            .put()
            .object(testItem)
            .prepare()
            .executeAsBlocking();

    assertThat(insertResult.wasInserted()).isTrue();

    Cursor cursor = contentResolver.query(TestItem.CONTENT_URI, null, null, null, null);

    Assertions.assertThat(cursor).hasCount(1);

    cursor.moveToFirst();

    assertThat(testItem.equalsWithoutId(TestItem.fromCursor(cursor))).isTrue();

    cursor.close();

    changesTestSubscriber.awaitTerminalEvent(60, SECONDS);
    changesTestSubscriber.assertNoErrors();
    changesTestSubscriber.assertValue(Changes.newInstance(TestItem.CONTENT_URI));
}
 
Example 10
Source File: LocalDataStoreTest.java    From ground-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetTilesOnceAndStream() {
  TestSubscriber<ImmutableSet<Tile>> subscriber = localDataStore.getTilesOnceAndStream().test();

  subscriber.assertValue(ImmutableSet.of());

  localDataStore.insertOrUpdateTile(TEST_DOWNLOADED_TILE).blockingAwait();
  localDataStore.insertOrUpdateTile(TEST_PENDING_TILE).blockingAwait();

  subscriber.assertValueSet(
      ImmutableSet.of(
          ImmutableSet.of(),
          ImmutableSet.of(TEST_DOWNLOADED_TILE),
          ImmutableSet.of(TEST_DOWNLOADED_TILE, TEST_PENDING_TILE)));
}
 
Example 11
Source File: PutOperationTest.java    From storio with Apache License 2.0 5 votes vote down vote up
@Test
public void insertObjectAsRxFlowable() {
    TestSubscriber<Changes> changesTestSubscriber = new TestSubscriber<Changes>();

    storIOContentResolver
            .observeChangesOfUri(TestItem.CONTENT_URI, BackpressureStrategy.MISSING)
            .take(1)
            .subscribe(changesTestSubscriber);

    TestItem testItem = TestItem.create(null, "value");

    PutResult insertResult = storIOContentResolver
            .put()
            .object(testItem)
            .prepare()
            .asRxFlowable(BackpressureStrategy.MISSING)
            .blockingFirst();

    assertThat(insertResult.wasInserted()).isTrue();

    Cursor cursor = contentResolver.query(TestItem.CONTENT_URI, null, null, null, null);

    Assertions.assertThat(cursor).hasCount(1);

    cursor.moveToFirst();

    assertThat(testItem.equalsWithoutId(TestItem.fromCursor(cursor))).isTrue();

    cursor.close();

    changesTestSubscriber.awaitTerminalEvent(60, SECONDS);
    changesTestSubscriber.assertNoErrors();
    changesTestSubscriber.assertValue(Changes.newInstance(TestItem.CONTENT_URI));
}
 
Example 12
Source File: AdamantApiWrapperSwitchOnFailureTest.java    From adamant-android with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testSwitchNodeIfErrorOnGetTransactionDetails() throws Exception {
    TestSubscriber<TransactionDetailsResponse> subscriber = new TestSubscriber<>();

    wrapper
            .getTransactionDetails("0000000000000000000000000")
            .subscribe(subscriber);

    scheduler.advanceTimeBy(AdamantApi.SYNCHRONIZE_DELAY_SECONDS * (2 + 1), TimeUnit.SECONDS);
    subscriber.assertValue(transactionDetailsResponse);
}
 
Example 13
Source File: GetOperationTest.java    From storio with Apache License 2.0 5 votes vote down vote up
@Test
public void getExistedObjectExecuteAsMaybe() {
    final TestSubscriber<Changes> changesTestSubscriber = new TestSubscriber<Changes>();

    storIOContentResolver
            .observeChangesOfUri(TestItem.CONTENT_URI, BackpressureStrategy.MISSING)
            .take(1)
            .subscribe(changesTestSubscriber);

    TestItem expectedItem = TestItem.create(null, "value");
    contentResolver.insert(TestItem.CONTENT_URI, expectedItem.toContentValues());
    contentResolver.insert(TestItem.CONTENT_URI, TestItem.create(null, "value1").toContentValues());
    contentResolver.insert(TestItem.CONTENT_URI, TestItem.create(null, "value2").toContentValues());

    Maybe<TestItem> testItemMaybe = storIOContentResolver
            .get()
            .object(TestItem.class)
            .withQuery(Query.builder()
                    .uri(TestItem.CONTENT_URI)
                    .where(TestItem.COLUMN_VALUE + "=?")
                    .whereArgs("value")
                    .build())
            .prepare()
            .asRxMaybe();

    TestObserver<TestItem> testObserver = new TestObserver<TestItem>();
    testItemMaybe.subscribe(testObserver);

    testObserver.awaitTerminalEvent(5, SECONDS);
    testObserver.assertNoErrors();

    List<TestItem> emmitedItems = testObserver.values();
    assertThat(emmitedItems.size()).isEqualTo(1);
    assertThat(expectedItem.equalsWithoutId(emmitedItems.get(0))).isTrue();

    changesTestSubscriber.awaitTerminalEvent(60, SECONDS);
    changesTestSubscriber.assertNoErrors();
    changesTestSubscriber.assertValue(Changes.newInstance(TestItem.CONTENT_URI));
}
 
Example 14
Source File: GetOperationTest.java    From storio with Apache License 2.0 5 votes vote down vote up
@Test
public void getNumberOfResults() {
    final TestSubscriber<Changes> changesTestSubscriber = new TestSubscriber<Changes>();

    storIOContentResolver
            .observeChangesOfUri(TestItem.CONTENT_URI, BackpressureStrategy.MISSING)
            .take(1)
            .subscribe(changesTestSubscriber);

    final int testItemsQuantity = 8;

    ContentValues[] contentValues = new ContentValues[testItemsQuantity];
    for (int i = 0; i < testItemsQuantity; ++i) {
        TestItem testItemToInsert = TestItem.create(null, "value");
        contentValues[i] = testItemToInsert.toContentValues();
    }
    contentResolver.bulkInsert(TestItem.CONTENT_URI, contentValues);

    Integer numberOfResults = storIOContentResolver
            .get()
            .numberOfResults()
            .withQuery(Query.builder()
                    .uri(TestItem.CONTENT_URI)
                    .build())
            .prepare()
            .executeAsBlocking();

    assertThat(numberOfResults).isEqualTo(testItemsQuantity);

    changesTestSubscriber.awaitTerminalEvent(60, SECONDS);
    changesTestSubscriber.assertNoErrors();
    changesTestSubscriber.assertValue(Changes.newInstance(TestItem.CONTENT_URI));
}
 
Example 15
Source File: AdamantApiWrapperSwitchOnFailureTest.java    From adamant-android with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testSwitchNodeIfErrorOnGetAdamantAllFinanceTransactions_ArgumentsCount_3() throws Exception {
    TestSubscriber<TransactionList> subscriber = new TestSubscriber<>();

    wrapper
            .getAdamantAllFinanceTransactions(1, 0, AdamantApi.ORDER_BY_TIMESTAMP_DESC)
            .subscribe(subscriber);

    scheduler.advanceTimeBy(AdamantApi.SYNCHRONIZE_DELAY_SECONDS * (2 + 1), TimeUnit.SECONDS);
    subscriber.assertValue(transactionList);
}
 
Example 16
Source File: AdamantApiWrapperSwitchOnFailureTest.java    From adamant-android with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testSwitchNodeIfErrorOnGetAdamantAllFinanceTransactions_ArgumentsCount_1() throws Exception {
    TestSubscriber<TransactionList> subscriber = new TestSubscriber<>();

    wrapper
            .getAdamantAllFinanceTransactions(AdamantApi.ORDER_BY_TIMESTAMP_DESC)
            .subscribe(subscriber);

    scheduler.advanceTimeBy(AdamantApi.SYNCHRONIZE_DELAY_SECONDS * (2 + 1), TimeUnit.SECONDS);
    subscriber.assertValue(transactionList);
}
 
Example 17
Source File: ChangesFilterTest.java    From storio with Apache License 2.0 5 votes vote down vote up
@Test
public void applyForTables_shouldFilterRequiredTableWhichIsPartOfSomeChanges() {
    final TestSubscriber<Changes> testSubscriber = new TestSubscriber<Changes>();

    ChangesFilter
            .applyForTables(
                    Flowable.just(Changes.newInstance("table1"),
                            Changes.newInstance(new HashSet<String>() {
                                {
                                    add("table1");
                                    // Notice, that required table
                                    // Is just a part of one Changes object
                                    add("table2");
                                    add("table3");
                                }
                            })),
                    singleton("table3"))
            .subscribe(testSubscriber);

    // All other Changes should be filtered
    testSubscriber.assertValue(Changes.newInstance(new HashSet<String>() {
        {
            add("table1");
            add("table2");
            add("table3");
        }
    }));

    testSubscriber.dispose();
}
 
Example 18
Source File: PutOperationTest.java    From storio with Apache License 2.0 5 votes vote down vote up
@Test
public void insertContentValuesAsCompletable() {
    TestSubscriber<Changes> changesTestSubscriber = new TestSubscriber<Changes>();

    storIOContentResolver
            .observeChangesOfUri(TestItem.CONTENT_URI, BackpressureStrategy.MISSING)
            .take(1)
            .subscribe(changesTestSubscriber);

    TestItem testItem = TestItem.create(null, "value");
    ContentValues cv = testItem.toContentValues();

    storIOContentResolver
            .put()
            .contentValues(cv)
            .withPutResolver(testItemContentValuesPutResolver)
            .prepare()
            .asRxCompletable()
            .blockingAwait(15, SECONDS);

    Cursor cursor = contentResolver.query(TestItem.CONTENT_URI, null, null, null, null);

    Assertions.assertThat(cursor).hasCount(1);

    cursor.moveToFirst();

    assertThat(testItem.equalsWithoutId(TestItem.fromCursor(cursor))).isTrue();

    changesTestSubscriber.awaitTerminalEvent(60, SECONDS);
    changesTestSubscriber.assertNoErrors();
    changesTestSubscriber.assertValue(Changes.newInstance(TestItem.CONTENT_URI));
}
 
Example 19
Source File: DefaultStorIOSQLiteTest.java    From storio with Apache License 2.0 5 votes vote down vote up
@Test
public void observeChangesInTable() {
    TestSubscriber<Changes> testSubscriber = new TestSubscriber<Changes>();

    storIOSQLite
            .observeChangesInTable("table1", LATEST)
            .subscribe(testSubscriber);

    testSubscriber.assertNoValues();

    Changes changes1 = Changes.newInstance("table2");

    storIOSQLite
            .lowLevel()
            .notifyAboutChanges(changes1);

    testSubscriber.assertNoValues();

    Changes changes2 = Changes.newInstance("table1");

    storIOSQLite
            .lowLevel()
            .notifyAboutChanges(changes2);

    testSubscriber.assertValue(changes2);

    Changes changes3 = Changes.newInstance("table3");

    storIOSQLite
            .lowLevel()
            .notifyAboutChanges(changes3);

    // Subscriber should not see changes of table2 and table3
    testSubscriber.assertValue(changes2);
    testSubscriber.assertNoErrors();
    testSubscriber.dispose();
}
 
Example 20
Source File: GetOperationTest.java    From storio with Apache License 2.0 5 votes vote down vote up
@Test
public void getListOfObjectsExecuteAsBlocking() {
    final TestSubscriber<Changes> changesTestSubscriber = new TestSubscriber<Changes>();

    storIOContentResolver
            .observeChangesOfUri(TestItem.CONTENT_URI, BackpressureStrategy.MISSING)
            .take(1)
            .subscribe(changesTestSubscriber);

    TestItem testItemToInsert = TestItem.create(null, "value");
    contentResolver.insert(TestItem.CONTENT_URI, testItemToInsert.toContentValues());

    List<TestItem> list = storIOContentResolver
            .get()
            .listOfObjects(TestItem.class)
            .withQuery(Query.builder()
                    .uri(TestItem.CONTENT_URI)
                    .build())
            .prepare()
            .executeAsBlocking();

    assertThat(list).hasSize(1);

    assertThat(testItemToInsert.equalsWithoutId(list.get(0))).isTrue();

    changesTestSubscriber.awaitTerminalEvent(60, SECONDS);
    changesTestSubscriber.assertNoErrors();
    changesTestSubscriber.assertValue(Changes.newInstance(TestItem.CONTENT_URI));
}