Search in sources :

Example 51 with TestSubscriber

use of rx.observers.TestSubscriber in project sqlbrite by square.

the class QueryTest method mapToListIgnoresNullCursor.

@Test
public void mapToListIgnoresNullCursor() {
    Query nully = new Query() {

        @Nullable
        @Override
        public Cursor run() {
            return null;
        }
    };
    TestSubscriber<List<Employee>> subscriber = new TestSubscriber<>();
    Observable.just(nully).lift(Query.mapToList(Employee.MAPPER)).subscribe(subscriber);
    subscriber.assertNoValues();
    subscriber.assertCompleted();
}
Also used : Query(com.squareup.sqlbrite.SqlBrite.Query) TestSubscriber(rx.observers.TestSubscriber) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 52 with TestSubscriber

use of rx.observers.TestSubscriber in project sqlbrite by square.

the class QueryTest method mapToOneOrDefaultReturnsDefaultWhenNullCursor.

@Test
public void mapToOneOrDefaultReturnsDefaultWhenNullCursor() {
    Employee defaultEmployee = new Employee("bob", "Bob Bobberson");
    Query nully = new Query() {

        @Nullable
        @Override
        public Cursor run() {
            return null;
        }
    };
    TestSubscriber<Employee> subscriber = new TestSubscriber<>();
    Observable.just(nully).lift(Query.mapToOneOrDefault(Employee.MAPPER, defaultEmployee)).subscribe(subscriber);
    subscriber.assertValues(defaultEmployee);
    subscriber.assertCompleted();
}
Also used : Employee(com.squareup.sqlbrite.TestDb.Employee) Query(com.squareup.sqlbrite.SqlBrite.Query) TestSubscriber(rx.observers.TestSubscriber) Test(org.junit.Test)

Example 53 with TestSubscriber

use of rx.observers.TestSubscriber in project reark by reark.

the class GitHubRepositoryStoreCoreTest method getStream_EmitsValuesForId_AndDoesNotComplete.

// GET STREAM
@Test
public void getStream_EmitsValuesForId_AndDoesNotComplete() {
    final GitHubRepository value1 = create(100, "test name 1");
    final GitHubRepository value2 = create(200, "test name 2");
    TestSubscriber<GitHubRepository> testSubscriber1 = new TestSubscriber<>();
    TestSubscriber<GitHubRepository> testSubscriber2 = new TestSubscriber<>();
    gitHubRepositoryStoreCore.getStream(100).subscribe(testSubscriber1);
    gitHubRepositoryStoreCore.getStream(200).subscribe(testSubscriber2);
    gitHubRepositoryStoreCore.put(100, value1);
    gitHubRepositoryStoreCore.put(200, value2);
    testSubscriber1.awaitTerminalEvent(Constants.Tests.PROVIDER_WAIT_TIME, TimeUnit.MILLISECONDS);
    testSubscriber1.assertNotCompleted();
    testSubscriber1.assertNoErrors();
    testSubscriber1.assertValue(value1);
    testSubscriber2.awaitTerminalEvent(Constants.Tests.PROVIDER_WAIT_TIME, TimeUnit.MILLISECONDS);
    testSubscriber2.assertNotCompleted();
    testSubscriber2.assertNoErrors();
    testSubscriber2.assertValue(value2);
}
Also used : TestSubscriber(rx.observers.TestSubscriber) GitHubRepository(io.reark.rxgithubapp.shared.pojo.GitHubRepository) Test(org.junit.Test)

Example 54 with TestSubscriber

use of rx.observers.TestSubscriber in project reark by reark.

the class GitHubRepositoryStoreCoreTest method getAllStream_ReturnsAllData_AndDoesNotComplete.

// GET ALL STREAM
@Test
public void getAllStream_ReturnsAllData_AndDoesNotComplete() throws InterruptedException {
    // ARRANGE
    final GitHubRepository value1 = create(100, "test name 1");
    final GitHubRepository value2 = create(200, "test name 2");
    final GitHubRepository value3 = create(300, "test name 3");
    TestSubscriber<GitHubRepository> testSubscriber = new TestSubscriber<>();
    // ACT
    gitHubRepositoryStoreCore.put(100, value1);
    Thread.sleep(Constants.Tests.PROVIDER_WAIT_TIME);
    gitHubRepositoryStoreCore.getAllStream().subscribe(testSubscriber);
    gitHubRepositoryStoreCore.put(200, value2);
    Thread.sleep(Constants.Tests.PROVIDER_WAIT_TIME);
    gitHubRepositoryStoreCore.put(300, value3);
    // ASSERT
    testSubscriber.awaitTerminalEvent(Constants.Tests.PROVIDER_WAIT_TIME, TimeUnit.MILLISECONDS);
    testSubscriber.assertNotCompleted();
    testSubscriber.assertNoErrors();
    testSubscriber.assertReceivedOnNext(asList(value2, value3));
}
Also used : TestSubscriber(rx.observers.TestSubscriber) GitHubRepository(io.reark.rxgithubapp.shared.pojo.GitHubRepository) Test(org.junit.Test)

Example 55 with TestSubscriber

use of rx.observers.TestSubscriber in project reark by reark.

the class GitHubRepositoryStoreCoreTest method put_WithTwoDifferentIds_StoresTwoValues.

// PUT
@Test
public void put_WithTwoDifferentIds_StoresTwoValues() throws InterruptedException {
    final GitHubRepository value1 = create(100, "test name 1");
    final GitHubRepository value2 = create(200, "test name 2");
    TestSubscriber<GitHubRepository> testSubscriber1 = new TestSubscriber<>();
    TestSubscriber<GitHubRepository> testSubscriber2 = new TestSubscriber<>();
    gitHubRepositoryStoreCore.put(100, value1);
    gitHubRepositoryStoreCore.put(200, value2);
    Thread.sleep(Constants.Tests.PROVIDER_WAIT_TIME);
    gitHubRepositoryStoreCore.getCached(100).subscribe(testSubscriber1);
    gitHubRepositoryStoreCore.getCached(200).subscribe(testSubscriber2);
    testSubscriber1.awaitTerminalEvent();
    testSubscriber1.assertCompleted();
    testSubscriber1.assertNoErrors();
    testSubscriber1.assertValue(value1);
    testSubscriber2.awaitTerminalEvent();
    testSubscriber2.assertCompleted();
    testSubscriber2.assertNoErrors();
    testSubscriber2.assertValue(value2);
}
Also used : TestSubscriber(rx.observers.TestSubscriber) GitHubRepository(io.reark.rxgithubapp.shared.pojo.GitHubRepository) Test(org.junit.Test)

Aggregations

TestSubscriber (rx.observers.TestSubscriber)238 Test (org.junit.Test)213 Intent (android.content.Intent)48 Environment (com.kickstarter.libs.Environment)43 Cursor (android.database.Cursor)36 Changes (com.pushtorefresh.storio.contentresolver.Changes)34 Project (com.kickstarter.models.Project)33 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)21 MockApiClient (com.kickstarter.services.MockApiClient)21 ApiClientType (com.kickstarter.services.ApiClientType)20 TargetApi (android.annotation.TargetApi)18 CurrentUserType (com.kickstarter.libs.CurrentUserType)18 StorIOSQLite (com.pushtorefresh.storio.sqlite.StorIOSQLite)18 StorIOException (com.pushtorefresh.storio.StorIOException)17 TestCollapserTimer (com.netflix.hystrix.HystrixCollapserTest.TestCollapserTimer)16 Matchers.anyString (org.mockito.Matchers.anyString)16 User (com.kickstarter.models.User)15 PutResult (com.pushtorefresh.storio.contentresolver.operations.put.PutResult)15 Uri (android.net.Uri)14 NonNull (android.support.annotation.NonNull)14