本文整理汇总了Java中retrofit2.mock.Calls.response方法的典型用法代码示例。如果您正苦于以下问题:Java Calls.response方法的具体用法?Java Calls.response怎么用?Java Calls.response使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类retrofit2.mock.Calls
的用法示例。
在下文中一共展示了Calls.response方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupStartMock
import retrofit2.mock.Calls; //导入方法依赖的package包/类
private static void setupStartMock(UploadService mockUploadService) {
String jsonString = "{"
+ "'uri' : '/bucket/apikey/filename',"
+ "'region' : 'region',"
+ "'upload_id' : 'id',"
+ "'location_url' : 'url',"
+ "'upload_type' : 'intelligent_ingestion'"
+ "}";
Gson gson = new Gson();
StartResponse response = gson.fromJson(jsonString, StartResponse.class);
Call call = Calls.response(response);
Mockito
.doReturn(call)
.when(mockUploadService)
.start(Mockito.<String, RequestBody>anyMap());
}
示例2: setupCompleteMock
import retrofit2.mock.Calls; //导入方法依赖的package包/类
private static void setupCompleteMock(UploadService mockUploadService) {
String jsonString = "{"
+ "'handle' : 'handle',"
+ "'url' : 'url',"
+ "'filename' : 'filename',"
+ "'size' : '0',"
+ "'mimetype' : 'mimetype'"
+ "}";
Gson gson = new Gson();
CompleteResponse response = gson.fromJson(jsonString, CompleteResponse.class);
Call call = Calls.response(response);
Mockito
.doReturn(call)
.when(mockUploadService)
.complete(Mockito.<String, RequestBody>anyMap());
}
示例3: testRequestEmail_withSuccess
import retrofit2.mock.Calls; //导入方法依赖的package包/类
@Test
public void testRequestEmail_withSuccess() {
final User user = new UserBuilder().setEmail(TEST_EMAIL).build();
final Call<User> call = Calls.response(user);
setupMockAccountService(call);
authClient.requestEmail(mock(TwitterSession.class), new Callback<String>() {
@Override
public void success(Result<String> result) {
assertEquals(TEST_EMAIL, result.data);
}
@Override
public void failure(TwitterException exception) {
fail("Expected Callback#success to be called");
}
});
}
示例4: invokesCallback
import retrofit2.mock.Calls; //导入方法依赖的package包/类
@Test public void invokesCallback() throws ExecutionException, InterruptedException {
Message message = new TrackMessage.Builder().userId("userId").event("event").build();
transporter.enqueue(message).get();
verify(callback).success(Callback.Event.PERSIST, message);
Call<Void> call = Calls.response(Response.success((Void) null));
when(trackingAPI.batch(any(Batch.class))).thenReturn(call);
transporter.flush().get();
verify(callback).success(Callback.Event.UPLOAD, message);
}
示例5: ignoresNullCallback
import retrofit2.mock.Calls; //导入方法依赖的package包/类
@Test public void ignoresNullCallback() throws ExecutionException, InterruptedException {
transporter = new Transporter(queue, trackingAPI, null);
Message message = new TrackMessage.Builder().userId("userId").event("event").build();
transporter.enqueue(message).get();
Call<Void> call = Calls.response(Response.success((Void) null));
when(trackingAPI.batch(any(Batch.class))).thenReturn(call);
transporter.flush().get();
}
示例6: trimsBatches
import retrofit2.mock.Calls; //导入方法依赖的package包/类
@Test public void trimsBatches() throws Exception {
for (int i = 0; i < 40; i++) {
queue.add(new TrackMessage.Builder().userId("userId").event("event").build());
}
Call<Void> call = Calls.response(Response.success((Void) null));
when(trackingAPI.batch(any(Batch.class))).thenReturn(call);
transporter.flush().get();
ArgumentCaptor<Batch> batchArgumentCaptor = ArgumentCaptor.forClass(Batch.class);
verify(trackingAPI).batch(batchArgumentCaptor.capture());
assertThat(batchArgumentCaptor.getValue().batch()).hasSize(33);
}
示例7: createRawCall
import retrofit2.mock.Calls; //导入方法依赖的package包/类
/**
* Helper method for creating raw ({@link ResponseBody}) {@link Call} objects.
*/
public static Call<ResponseBody> createRawCall(String contentType, String body) {
MediaType mediaType = MediaType.parse(contentType);
ResponseBody responseBody = ResponseBody.create(mediaType, body);
return Calls.response(responseBody);
}
示例8: successResponse
import retrofit2.mock.Calls; //导入方法依赖的package包/类
private Call<ResponseBody> successResponse() {
final ResponseBody body = ResponseBody.create(MediaType.parse("application/json"), "");
return Calls.response(body);
}
示例9: errorResponse
import retrofit2.mock.Calls; //导入方法依赖的package包/类
private Call<ResponseBody> errorResponse(int statusCode) {
final ResponseBody body = ResponseBody.create(MediaType.parse("application/json"), "");
return Calls.response(Response.<ResponseBody>error(statusCode, body));
}
示例10: getTempToken
import retrofit2.mock.Calls; //导入方法依赖的package包/类
@Override
public Call<ResponseBody> getTempToken(@Header(OAuthConstants.HEADER_AUTHORIZATION) String auth) {
final ResponseBody responseBody = ResponseBody.create(MediaType.parse("application/json"), "");
return Calls.response(Response.success(responseBody));
}
示例11: getAccessToken
import retrofit2.mock.Calls; //导入方法依赖的package包/类
@Override
public Call<ResponseBody> getAccessToken(@Header(OAuthConstants.HEADER_AUTHORIZATION) String auth,
@Query(OAuthConstants.PARAM_VERIFIER) String verifier) {
final ResponseBody responseBody = ResponseBody.create(MediaType.parse("application/json"), "");
return Calls.response(Response.success(responseBody));
}
示例12: getGuestToken
import retrofit2.mock.Calls; //导入方法依赖的package包/类
@Override
public Call<GuestTokenResponse> getGuestToken(@Header(OAuthConstants.HEADER_AUTHORIZATION) String auth) {
return Calls.response(Response.success(GUEST_RESPONSE));
}
示例13: getAppAuthToken
import retrofit2.mock.Calls; //导入方法依赖的package包/类
@Override
public Call<OAuth2Token> getAppAuthToken(@Header(OAuthConstants.HEADER_AUTHORIZATION) String auth,
@Field(OAuthConstants.PARAM_GRANT_TYPE) String grantType) {
return Calls.response(Response.success(APP_TOKEN));
}
示例14: notify
import retrofit2.mock.Calls; //导入方法依赖的package包/类
@Override public Call<NotifyResult> notify(Event event) {
events.add(event);
return Calls.response((NotifyResult) null);
}