Search in sources :

Example 1 with TaskError

use of com.khmelenko.lab.varis.task.TaskError in project Varis-Android by dkhmelenko.

the class TestAuthPresenter method testLoginAuthFailed.

@Test
public void testLoginAuthFailed() {
    final String login = "login";
    final String password = "password";
    String auth = EncryptionUtils.generateBasicAuthorization(login, password);
    final String gitHubToken = "gitHubToken";
    Authorization authorization = new Authorization();
    authorization.setToken(gitHubToken);
    authorization.setId(1L);
    when(mGitHubRestClient.getApiService().createNewAuthorization(eq(auth), any(AuthorizationRequest.class))).thenReturn(authorization);
    AccessTokenRequest request = new AccessTokenRequest();
    request.setGithubToken(gitHubToken);
    TaskError taskError = new TaskError(500, "error");
    TaskException exception = new TaskException(taskError);
    when(mTravisRestClient.getApiService().auth(request)).thenThrow(exception);
    mAuthPresenter.login(login, password);
    verify(mTaskManager).createNewAuthorization(eq(auth), any(AuthorizationRequest.class));
    verify(mTaskManager).startAuth(gitHubToken);
    verify(mAuthView).hideProgress();
    verify(mAuthView).showErrorMessage(taskError.getMessage());
}
Also used : Authorization(com.khmelenko.lab.varis.network.response.Authorization) AuthorizationRequest(com.khmelenko.lab.varis.network.request.AuthorizationRequest) TaskException(com.khmelenko.lab.varis.task.TaskException) TaskError(com.khmelenko.lab.varis.task.TaskError) AccessTokenRequest(com.khmelenko.lab.varis.network.request.AccessTokenRequest) Test(org.junit.Test)

Example 2 with TaskError

use of com.khmelenko.lab.varis.task.TaskError in project Varis-Android by dkhmelenko.

the class TestAuthPresenter method testLoginGitHubAuthFailed.

@Test
public void testLoginGitHubAuthFailed() {
    final String login = "login";
    final String password = "password";
    String auth = EncryptionUtils.generateBasicAuthorization(login, password);
    TaskError taskError = new TaskError(500, "error");
    TaskException exception = new TaskException(taskError);
    when(mGitHubRestClient.getApiService().createNewAuthorization(eq(auth), any(AuthorizationRequest.class))).thenThrow(exception);
    mAuthPresenter.login(login, password);
    verify(mTaskManager).createNewAuthorization(eq(auth), any(AuthorizationRequest.class));
    verify(mAuthView).hideProgress();
    verify(mAuthView).showErrorMessage(taskError.getMessage());
}
Also used : AuthorizationRequest(com.khmelenko.lab.varis.network.request.AuthorizationRequest) TaskException(com.khmelenko.lab.varis.task.TaskException) TaskError(com.khmelenko.lab.varis.task.TaskError) Test(org.junit.Test)

Example 3 with TaskError

use of com.khmelenko.lab.varis.task.TaskError in project Varis-Android by dkhmelenko.

the class TestRepoDetailsPresenter method testLoadBranchesFailed.

@Test
public void testLoadBranchesFailed() {
    final String slug = "test";
    final int errorCode = 401;
    final String errorMsg = "error";
    TaskError error = spy(new TaskError(errorCode, errorMsg));
    TaskException exception = spy(new TaskException(error));
    when(mTravisRestClient.getApiService().getBranches(slug)).thenThrow(exception);
    mRepoDetailsPresenter.setRepoSlug(slug);
    mRepoDetailsPresenter.loadBranches();
    verify(mTaskManager).getBranches(slug);
    verify(mRepoDetailsView).showBranchesLoadingError(error.getMessage());
}
Also used : TaskException(com.khmelenko.lab.varis.task.TaskException) TaskError(com.khmelenko.lab.varis.task.TaskError) Test(org.junit.Test)

Example 4 with TaskError

use of com.khmelenko.lab.varis.task.TaskError in project Varis-Android by dkhmelenko.

the class TestSearchResultsPresenter method testStartRepoSearchFailed.

@Test
public void testStartRepoSearchFailed() {
    final String searchQuery = "test";
    final int errorCode = 401;
    final String errorMsg = "error";
    TaskError error = spy(new TaskError(errorCode, errorMsg));
    TaskException exception = spy(new TaskException(error));
    when(mTravisRestClient.getApiService().getRepos(searchQuery)).thenThrow(exception);
    mSearchResultsPresenter.startRepoSearch(searchQuery);
    verify(mTaskManager).findRepos(searchQuery);
    verify(mSearchResultsView).hideProgress();
    verify(mSearchResultsView).showLoadingError(eq(error.getMessage()));
}
Also used : TaskException(com.khmelenko.lab.varis.task.TaskException) TaskError(com.khmelenko.lab.varis.task.TaskError) Test(org.junit.Test)

Example 5 with TaskError

use of com.khmelenko.lab.varis.task.TaskError in project Varis-Android by dkhmelenko.

the class TestBuildDetailsPresenter method testStartLoadingDataIntentUrlFailed.

@Test
public void testStartLoadingDataIntentUrlFailed() throws Exception {
    final long buildId = 0L;
    final String slug = "dkhmelenko/Varis-Android";
    final String intentUrl = "https://travis-ci.org/dkhmelenko/Varis-Android/builds";
    final String expectedUrl = "https://sample.org";
    Request request = new Request.Builder().url(expectedUrl).build();
    com.squareup.okhttp.Response response = new com.squareup.okhttp.Response.Builder().request(request).protocol(Protocol.HTTP_1_1).code(200).build();
    final int errorCode = TaskError.NETWORK_ERROR;
    final String errorMsg = "";
    TaskError error = spy(new TaskError(errorCode, errorMsg));
    when(mRawClient.singleRequest(intentUrl)).thenReturn(response);
    mBuildsDetailsPresenter.startLoadingData(intentUrl, slug, buildId);
    verify(mTaskManager).intentUrl(intentUrl);
    verify(mBuildDetailsView).hideProgress();
    verify(mBuildDetailsView).updateBuildDetails(null);
    verify(mBuildDetailsView).showLoadingError(error.getMessage());
}
Also used : Request(com.squareup.okhttp.Request) TaskError(com.khmelenko.lab.varis.task.TaskError) Test(org.junit.Test)

Aggregations

TaskError (com.khmelenko.lab.varis.task.TaskError)12 Test (org.junit.Test)12 TaskException (com.khmelenko.lab.varis.task.TaskException)11 AuthorizationRequest (com.khmelenko.lab.varis.network.request.AuthorizationRequest)3 Response (retrofit.client.Response)3 AccessTokenRequest (com.khmelenko.lab.varis.network.request.AccessTokenRequest)2 Authorization (com.khmelenko.lab.varis.network.response.Authorization)2 TypedOutput (retrofit.mime.TypedOutput)2 AccessToken (com.khmelenko.lab.varis.network.response.AccessToken)1 Request (com.squareup.okhttp.Request)1 ArrayList (java.util.ArrayList)1 Header (retrofit.client.Header)1