### Question:
LoginViewModel extends BaseViewModel { public void login() { if (InputHelper.isEmpty(userName) || InputHelper.isEmpty(password)) { AlertUtils.showToastShortMessage(App.getInstance(), "Please input username and password!"); return; } String auth = StringUtils.getBasicAuth(userName, password); execute(true, RestHelper.createRemoteSourceMapper(githubService.login(auth), null), user -> { userManager.startUserSession(user, auth); navigatorHelper.navigateMainActivity(true); }); } @Inject  LoginViewModel(GithubService githubService, UserManager userManager); void login(); public String userName; public String password; }### Answer:
@Test public void loginSuccess() throws Exception { String pass = "abc"; User user = sampleUser(1L); String token = StringUtils.getBasicAuth(user.getLogin(), pass); when(githubService.login(any())).thenReturn(successResponse(user)); when(userManager.startUserSession(any(), any())).thenReturn(null); viewModel.setUserName(user.login); viewModel.setPassword(pass); viewModel.login(); verify(stateLiveData, times(1)).setValue(State.loading(null)); verify(stateLiveData, times(1)).setValue(State.success(null)); verify(userManager).startUserSession(user, token); verify(mNavigatorHelper).navigateMainActivity(true); }
@Test public void loginError() throws Exception { when(githubService.login(any())).thenReturn(errorResponse(401, "blah blah")); viewModel.login(); verify(stateLiveData, times(1)).setValue(State.loading(null)); verify(stateLiveData, times(1)).setValue(State.error("blah blah")); verifyZeroInteractions(userManager); }