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