当前位置: 首页>>代码示例>>Java>>正文


Java Calls.failure方法代码示例

本文整理汇总了Java中retrofit2.mock.Calls.failure方法的典型用法代码示例。如果您正苦于以下问题:Java Calls.failure方法的具体用法?Java Calls.failure怎么用?Java Calls.failure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在retrofit2.mock.Calls的用法示例。


在下文中一共展示了Calls.failure方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testExecution

import retrofit2.mock.Calls; //导入方法依赖的package包/类
@Test
public void testExecution() throws Exception {
    ApiPendingResult<Applet> pendingResult = new ApiPendingResult<>(Calls.<Applet>failure(new IOException()),
            new Moshi.Builder().build().adapter(ErrorResponse.class));
    final AtomicReference<ErrorResponse> errorResponseAtomicReference = new AtomicReference<>();
    pendingResult.execute(new PendingResult.ResultCallback<Applet>() {
        @Override
        public void onSuccess(@NonNull Applet result) {
            fail();
        }

        @Override
        public void onFailure(@NonNull ErrorResponse errorResponse) {
            errorResponseAtomicReference.set(errorResponse);
        }
    });

    assertThat(errorResponseAtomicReference.get().code).isEqualTo("exception");
    assertThat(errorResponseAtomicReference.get().message).isEqualTo("Unexpected error");
}
 
开发者ID:IFTTT,项目名称:IFTTTSDK-Android,代码行数:21,代码来源:ApiPendingResultTest.java

示例2: invokesUploadErrorCallback

import retrofit2.mock.Calls; //导入方法依赖的package包/类
@Test public void invokesUploadErrorCallback() throws Exception {
  transporter = new Transporter(queue, trackingAPI, callback);

  Message message = new TrackMessage.Builder().userId("userId").event("event").build();
  IOException testException = new IOException("test");

  Call<Void> call = Calls.failure(testException);
  when(trackingAPI.batch(any(Batch.class))).thenReturn(call);

  transporter.enqueue(message).get();

  try {
    transporter.flush().get();
  } catch (ExecutionException e) {
    assertThat(e.getCause()).isEqualTo(testException);
  }
  verify(callback).error(Callback.Event.UPLOAD, message, testException);
}
 
开发者ID:f2prateek,项目名称:segment-android,代码行数:19,代码来源:TransporterTest.java

示例3: testRequestGuestAuthToken_guestFailure

import retrofit2.mock.Calls; //导入方法依赖的package包/类
@Test
public void testRequestGuestAuthToken_guestFailure() {

    service.api = new MockOAuth2Api() {
        @Override
        public Call<GuestTokenResponse> getGuestToken(@Header(OAuthConstants.HEADER_AUTHORIZATION) String auth) {
            return Calls.failure(new IOException());
        }
    };

    service.requestGuestAuthToken(new Callback<GuestAuthToken>() {
        @Override
        public void success(Result<GuestAuthToken> result) {
            fail();
        }

        @Override
        public void failure(TwitterException error) {
            assertNotNull(error);
        }
    });
}
 
开发者ID:twitter,项目名称:twitter-kit-android,代码行数:23,代码来源:OAuth2ServiceTest.java

示例4: testRequestGuestAuthToken_appAuthFailure

import retrofit2.mock.Calls; //导入方法依赖的package包/类
@Test
public void testRequestGuestAuthToken_appAuthFailure() {

    service.api = new MockOAuth2Api() {
        @Override
        public Call<OAuth2Token> getAppAuthToken(@Header(OAuthConstants.HEADER_AUTHORIZATION) String auth,
                @Field(OAuthConstants.PARAM_GRANT_TYPE) String grantType) {
            return Calls.failure(new IOException());
        }
    };

    service.requestGuestAuthToken(new Callback<GuestAuthToken>() {
        @Override
        public void success(Result<GuestAuthToken> result) {
            fail();
        }

        @Override
        public void failure(TwitterException error) {
            assertNotNull(error);
        }
    });
}
 
开发者ID:twitter,项目名称:twitter-kit-android,代码行数:24,代码来源:OAuth2ServiceTest.java

示例5: testRequestEmail_withFailure

import retrofit2.mock.Calls; //导入方法依赖的package包/类
@Test
public void testRequestEmail_withFailure() {
    final IOException networkException = new IOException("Network failure");
    final Call<User> call = Calls.failure(networkException);
    setupMockAccountService(call);

    authClient.requestEmail(mock(TwitterSession.class), new Callback<String>() {
        @Override
        public void success(Result<String> result) {
            fail("Expected Callback#failure to be called");
        }

        @Override
        public void failure(TwitterException exception) {
            assertEquals(exception.getCause(), networkException);
        }
    });
}
 
开发者ID:twitter,项目名称:twitter-kit-android,代码行数:19,代码来源:TwitterAuthClientTest.java

示例6: testRequestEmail_scribesImpression

import retrofit2.mock.Calls; //导入方法依赖的package包/类
@Test
public void testRequestEmail_scribesImpression() {
    final IOException networkException = new IOException("Network failure");
    final Call<User> call = Calls.failure(networkException);
    setupMockAccountService(call);

    final TwitterSession mockSession = mock(TwitterSession.class);
    when(mockSession.getId()).thenReturn(TestFixtures.USER_ID);
    authClient = new TwitterAuthClient(mockTwitterCore, mockAuthConfig, mockSessionManager,
            mockAuthState) {
        @Override
        protected DefaultScribeClient getScribeClient() {
            return mockScribeClient;
        }
    };

    authClient.requestEmail(mockSession, mock(Callback.class));

    verify(mockScribeClient).scribe(any(EventNamespace.class));
}
 
开发者ID:twitter,项目名称:twitter-kit-android,代码行数:21,代码来源:TwitterAuthClientTest.java

示例7: getQuoteOfTheDay

import retrofit2.mock.Calls; //导入方法依赖的package包/类
@Override
public Call<QuoteOfTheDayResponse> getQuoteOfTheDay() {
    za.co.riggaroo.retrofittestexample.pojo.Error error = new Error();
    error.setCode(404);
    error.setMessage("Quote Not Found");
    QuoteOfTheDayErrorResponse quoteOfTheDayErrorResponse = new QuoteOfTheDayErrorResponse();
    quoteOfTheDayErrorResponse.setError(error);

    ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
    String json = "";
    try {
        json = ow.writeValueAsString(quoteOfTheDayErrorResponse);
        Response response = Response.error(404, ResponseBody.create(MediaType.parse("application/json") ,json));
        return delegate.returning(Calls.response(response)).getQuoteOfTheDay();
       // return delegate.returningResponse(response).getQuoteOfTheDay();
    } catch (JsonProcessingException e) {
        Log.e(TAG, "JSON Processing exception:",e);
        return Calls.failure(e);
    }

}
 
开发者ID:riggaroo,项目名称:android-retrofit-test-examples,代码行数:22,代码来源:MockFailedQODService.java


注:本文中的retrofit2.mock.Calls.failure方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。