Search in sources :

Example 1 with Repository

use of uk.ivanc.archimvvm.model.Repository in project archi by ivacf.

the class ItemRepoViewModelTest method shouldGetStars.

@Test
public void shouldGetStars() {
    Repository repository = new Repository();
    repository.stars = 10;
    String expectedString = application.getString(R.string.text_stars, repository.stars);
    ItemRepoViewModel itemRepoViewModel = new ItemRepoViewModel(application, repository);
    assertEquals(expectedString, itemRepoViewModel.getStars());
}
Also used : Repository(uk.ivanc.archimvvm.model.Repository) ItemRepoViewModel(uk.ivanc.archimvvm.viewmodel.ItemRepoViewModel) Test(org.junit.Test)

Example 2 with Repository

use of uk.ivanc.archimvvm.model.Repository in project archi by ivacf.

the class ItemRepoViewModelTest method shouldGetWatchers.

@Test
public void shouldGetWatchers() {
    Repository repository = new Repository();
    repository.watchers = 7;
    String expectedString = application.getString(R.string.text_watchers, repository.watchers);
    ItemRepoViewModel itemRepoViewModel = new ItemRepoViewModel(application, repository);
    assertEquals(expectedString, itemRepoViewModel.getWatchers());
}
Also used : Repository(uk.ivanc.archimvvm.model.Repository) ItemRepoViewModel(uk.ivanc.archimvvm.viewmodel.ItemRepoViewModel) Test(org.junit.Test)

Example 3 with Repository

use of uk.ivanc.archimvvm.model.Repository in project archi by ivacf.

the class ItemRepoViewModelTest method shouldNotifyPropertyChangeWhenSetRepository.

@Test
public void shouldNotifyPropertyChangeWhenSetRepository() {
    Repository repository = new Repository();
    ItemRepoViewModel itemRepoViewModel = new ItemRepoViewModel(application, repository);
    Observable.OnPropertyChangedCallback mockCallback = mock(Observable.OnPropertyChangedCallback.class);
    itemRepoViewModel.addOnPropertyChangedCallback(mockCallback);
    itemRepoViewModel.setRepository(repository);
    verify(mockCallback).onPropertyChanged(any(Observable.class), anyInt());
}
Also used : Repository(uk.ivanc.archimvvm.model.Repository) ItemRepoViewModel(uk.ivanc.archimvvm.viewmodel.ItemRepoViewModel) Observable(android.databinding.Observable) Test(org.junit.Test)

Example 4 with Repository

use of uk.ivanc.archimvvm.model.Repository in project archi by ivacf.

the class MainViewModelTest method shouldSearchUsernameWithNoRepos.

@Test
public void shouldSearchUsernameWithNoRepos() {
    String username = "usernameWithoutRepos";
    TextView textView = new TextView(application);
    textView.setText(username);
    when(githubService.publicRepositories(username)).thenReturn(Observable.just(Collections.<Repository>emptyList()));
    mainViewModel.onSearchAction(textView, EditorInfo.IME_ACTION_SEARCH, null);
    verify(dataListener).onRepositoriesChanged(Collections.<Repository>emptyList());
    assertEquals(mainViewModel.infoMessage.get(), application.getString(R.string.text_empty_repos));
    assertEquals(mainViewModel.infoMessageVisibility.get(), View.VISIBLE);
    assertEquals(mainViewModel.progressVisibility.get(), View.INVISIBLE);
    assertEquals(mainViewModel.recyclerViewVisibility.get(), View.INVISIBLE);
}
Also used : Repository(uk.ivanc.archimvvm.model.Repository) TextView(android.widget.TextView) Test(org.junit.Test)

Example 5 with Repository

use of uk.ivanc.archimvvm.model.Repository in project archi by ivacf.

the class MainViewModelTest method shouldSearchInvalidUsername.

@Test
public void shouldSearchInvalidUsername() {
    String username = "invalidUsername";
    TextView textView = new TextView(application);
    textView.setText(username);
    HttpException mockHttpException = new HttpException(Response.error(404, mock(ResponseBody.class)));
    when(githubService.publicRepositories(username)).thenReturn(Observable.<List<Repository>>error(mockHttpException));
    mainViewModel.onSearchAction(textView, EditorInfo.IME_ACTION_SEARCH, null);
    verify(dataListener, never()).onRepositoriesChanged(anyListOf(Repository.class));
    assertEquals(mainViewModel.infoMessage.get(), application.getString(R.string.error_username_not_found));
    assertEquals(mainViewModel.infoMessageVisibility.get(), View.VISIBLE);
    assertEquals(mainViewModel.progressVisibility.get(), View.INVISIBLE);
    assertEquals(mainViewModel.recyclerViewVisibility.get(), View.INVISIBLE);
}
Also used : Repository(uk.ivanc.archimvvm.model.Repository) TextView(android.widget.TextView) HttpException(retrofit2.adapter.rxjava.HttpException) Test(org.junit.Test)

Aggregations

Repository (uk.ivanc.archimvvm.model.Repository)13 Test (org.junit.Test)10 ItemRepoViewModel (uk.ivanc.archimvvm.viewmodel.ItemRepoViewModel)7 TextView (android.widget.TextView)3 Context (android.content.Context)1 Intent (android.content.Intent)1 Observable (android.databinding.Observable)1 ActionBar (android.support.v7.app.ActionBar)1 View (android.view.View)1 List (java.util.List)1 Random (java.util.Random)1 HttpException (retrofit2.adapter.rxjava.HttpException)1 Subscriber (rx.Subscriber)1 ArchiApplication (uk.ivanc.archimvvm.ArchiApplication)1 GithubService (uk.ivanc.archimvvm.model.GithubService)1 RepositoryViewModel (uk.ivanc.archimvvm.viewmodel.RepositoryViewModel)1