@Test public void callGetStatusIfUrlValid() { viewModel.url.set(URL); viewModel.triggerLogin(); verify(userRepository).status(URL); }
void triggerLogin() { Log.d(TAG, "triggerLogin"); try { if (isGuest()) { userRepository.status(url.get()) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new StatusSubscriber()); } else if (isLoginValid()) { userRepository.login(url.get(), username.get(), password.get()) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new LoginSubscriber()); } } catch (IllegalArgumentException illArgE) { Log.e(TAG, illArgE.getMessage() + illArgE); loginError.setValue(illArgE); } }
LoginViewModel extends ViewModel { void triggerLogin() { Log.d(TAG, "triggerLogin"); try { if (isGuest()) { userRepository.status(url.get()) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new StatusSubscriber()); } else if (isLoginValid()) { userRepository.login(url.get(), username.get(), password.get()) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new LoginSubscriber()); } } catch (IllegalArgumentException illArgE) { Log.e(TAG, illArgE.getMessage() + illArgE); loginError.setValue(illArgE); } } }
LoginViewModel extends ViewModel { void triggerLogin() { Log.d(TAG, "triggerLogin"); try { if (isGuest()) { userRepository.status(url.get()) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new StatusSubscriber()); } else if (isLoginValid()) { userRepository.login(url.get(), username.get(), password.get()) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new LoginSubscriber()); } } catch (IllegalArgumentException illArgE) { Log.e(TAG, illArgE.getMessage() + illArgE); loginError.setValue(illArgE); } } LoginViewModel(UserManager userManager, RestUserRepository userRepository, Resources resources); }
LoginViewModel extends ViewModel { void triggerLogin() { Log.d(TAG, "triggerLogin"); try { if (isGuest()) { userRepository.status(url.get()) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new StatusSubscriber()); } else if (isLoginValid()) { userRepository.login(url.get(), username.get(), password.get()) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new LoginSubscriber()); } } catch (IllegalArgumentException illArgE) { Log.e(TAG, illArgE.getMessage() + illArgE); loginError.setValue(illArgE); } } LoginViewModel(UserManager userManager, RestUserRepository userRepository, Resources resources); boolean isGuest(); }
LoginViewModel extends ViewModel { void triggerLogin() { Log.d(TAG, "triggerLogin"); try { if (isGuest()) { userRepository.status(url.get()) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new StatusSubscriber()); } else if (isLoginValid()) { userRepository.login(url.get(), username.get(), password.get()) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new LoginSubscriber()); } } catch (IllegalArgumentException illArgE) { Log.e(TAG, illArgE.getMessage() + illArgE); loginError.setValue(illArgE); } } LoginViewModel(UserManager userManager, RestUserRepository userRepository, Resources resources); boolean isGuest(); public ObservableField<String> url; public ObservableField<String> urlError; public ObservableField<String> username; public ObservableField<String> usernameError; public ObservableField<String> password; public ObservableField<String> passwordError; }