class User {

    public void login(final LoginInterface loginInterface) {
        if (webService.isNetworkOffline()) {
            loginInterface.onLoginFailed();
            return;
        }

        Response response = new Response() {
            @Override
            public void onRequestCompleted(boolean isSuccess, String data) {
                if (isSuccess) {
                    loginInterface.onLoginSuccess();
                } else {
                    loginInterface.onLoginFailed();
                }
            }
        };
        webService.login(userId, password, response);
    }

}

class UserTest {

    public static final int USER_ID;
    public static final String PASSWORD;
    @Rule
    public MockitoRule mockitoRule;
    @Mock
    private WebService mockWebService;
    @Mock
    private LoginInterface mockLoginInterface;
    @Captor
    private ArgumentCaptor<Response> responseArgumentCaptor;

    @Test
    public void stubMethodAnswer() throws Exception {

        User user = new User(mockWebService, USER_ID, PASSWORD);
        when(mockWebService.isNetworkOffline()).then(new Answer<Boolean>() {
            int index = 0;

            @Override
            public Boolean answer(InvocationOnMock invocation) throws Throwable {
                return index++ % 2 == 0;
            }
        });

        user.login(mockLoginInterface);
        user.login(mockLoginInterface);
        user.login(mockLoginInterface);

        verify(mockWebService, times(1)).login(anyInt(), anyString(), any(Response.class));
    }

}