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());
}
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());
}
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());
}
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);
}
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);
}
Aggregations