本文整理汇总了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");
}
示例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);
}
示例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);
}
});
}
示例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);
}
});
}
示例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);
}
});
}
示例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));
}
示例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);
}
}