I need some advices on how to mock a rest api. My application is in MVP architecture.
My interface for API:
public interface MyAPI {
@GET(\"{cmd
You can do it in next way:
@Test
public void testLoginWithCorrectUserNameAndPassword() throws Exception {
// create or mock response object
when(service.login(anyString(), anyString(), anyString).thenReturn(Observable.just(response));
mLoginPresenter.login("user@email.com","password");
verify(view).loginSuccess();
}
@Test
public void testLoginWithIncorrectUserNameAndPassword() throws Exception {
// create or mock response object
when(service.login(anyString(), anyString(), anyString).thenReturn(Observable.error(new IOException()));
mLoginPresenter.login("user@email.com","password");
verify(view).showError(anyString);
}