Advertisement
Guest User

Untitled

a guest
Apr 14th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. // THE TEST
  2.  
  3. @Test
  4. public void testOnLoginSuccessful() throws Exception {
  5. // view
  6. MainView view = mockActiveView(MainView.class);
  7. when(view.getPassword()).thenReturn("mockuser");
  8. when(view.getPassword()).thenReturn("mockpass");
  9. // presenter
  10. MainPresenter presenter = new MainPresenter();
  11. presenter.useView(view);
  12.  
  13. presenter.onLogin();
  14.  
  15. verify(view).loggingIn();
  16. verify(view).onLoginSuccessful(any(User.class));
  17. }
  18.  
  19. // THE PRESENTER onLogin
  20.  
  21. public void onLogin() {
  22. MainView view = getView();
  23. if (view == null) {
  24. return;
  25. }
  26.  
  27. CharSequence username = view.getUsername();
  28. CharSequence password = view.getPassword();
  29. LoginRequest request = new LoginRequest(username, password);
  30.  
  31. mDevelopingService.login(request)
  32. .observeOn(AndroidSchedulers.mainThread())
  33. .subscribe(
  34. this::onLoginResult,
  35. this::onLoginError
  36. );
  37.  
  38. view.loggingIn();
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement