use of io.reark.rxgithubapp.shared.pojo.GitHubRepository 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));
}
use of io.reark.rxgithubapp.shared.pojo.GitHubRepository 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);
}
use of io.reark.rxgithubapp.shared.pojo.GitHubRepository in project reark by reark.
the class GitHubRepositorySearchFetcher method fetchGitHubSearch.
private void fetchGitHubSearch(@NonNull final String searchString) {
checkNotNull(searchString);
Log.d(TAG, "fetchGitHubSearch(" + searchString + ")");
if (isOngoingRequest(searchString.hashCode())) {
Log.d(TAG, "Found an ongoing request for repository " + searchString);
return;
}
final String uri = getUniqueId(searchString);
Subscription subscription = createNetworkObservable(searchString).subscribeOn(Schedulers.computation()).map((repositories) -> {
final List<Integer> repositoryIds = new ArrayList<>(repositories.size());
for (GitHubRepository repository : repositories) {
gitHubRepositoryStore.put(repository);
repositoryIds.add(repository.getId());
}
return new GitHubRepositorySearch(searchString, repositoryIds);
}).doOnSubscribe(() -> startRequest(uri)).doOnCompleted(() -> completeRequest(uri)).doOnError(doOnError(uri)).subscribe(gitHubRepositorySearchStore::put, e -> Log.e(TAG, "Error fetching GitHub repository search for '" + searchString + "'", e));
addRequest(searchString.hashCode(), subscription);
}
use of io.reark.rxgithubapp.shared.pojo.GitHubRepository in project reark by reark.
the class RepositoryViewModelTest method testRepositoryViewModelFetchesValidGitHubRepository.
@Test(timeout = 1000)
public void testRepositoryViewModelFetchesValidGitHubRepository() throws Exception {
GitHubRepository gitHubRepository = new GitHubRepository(2, "repo", 3, 4, mock(GitHubOwner.class));
RepositoryViewModel repositoryViewModel = new RepositoryViewModel(() -> Observable.just(new UserSettings(1)), repositoryId -> Observable.just(gitHubRepository));
TestSubscriber<GitHubRepository> observer = new TestSubscriber<>();
repositoryViewModel.getRepository().subscribe(observer);
repositoryViewModel.subscribeToDataStore();
observer.awaitTerminalEvent();
assertEquals("Invalid number of repositories", 1, observer.getOnNextEvents().size());
assertEquals("Provided GitHubRepository does not match", gitHubRepository, observer.getOnNextEvents().get(0));
}
use of io.reark.rxgithubapp.shared.pojo.GitHubRepository in project reark by reark.
the class GitHubRepositoryStoreTest method getOnceAndStream_ReturnsOnlyValuesForSubscribedId_AndDoesNotComplete.
@Test
public void getOnceAndStream_ReturnsOnlyValuesForSubscribedId_AndDoesNotComplete() throws InterruptedException {
final GitHubRepository value1 = create(100, "repository1");
final GitHubRepository value2 = create(200, "repository2");
gitHubRepositoryStore.getOnceAndStream(100).subscribe(testSubscriber);
Thread.sleep(Constants.Tests.PROVIDER_WAIT_TIME);
gitHubRepositoryStore.put(value1);
gitHubRepositoryStore.put(value2);
testSubscriber.awaitTerminalEvent(Constants.Tests.PROVIDER_WAIT_TIME, TimeUnit.MILLISECONDS);
testSubscriber.assertNotCompleted();
testSubscriber.assertNoErrors();
testSubscriber.assertReceivedOnNext(asList(none(), value1));
}
Aggregations