• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Calls类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



Calls类属于retrofit2.mock包,在下文中一共展示了Calls类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: testStoreExternal

import retrofit2.mock.Calls; //导入依赖的package包/类
@Test
public void testStoreExternal() throws Exception {
  String jsonString = "{'url': 'https://cdn.filestackcontent.com/handle'}";
  Gson gson = new Gson();
  StoreResponse storeResponse = gson.fromJson(jsonString, StoreResponse.class);
  String url = "https://example.com/image.jpg";

  Mockito
      .doReturn(Calls.response(storeResponse))
      .when(Networking.getCdnService())
      .transformStoreExt("apiKey", "store", url);

  Config config = new Config("apiKey");
  ImageTransform transform = new ImageTransform(config, url, true);

  Assert.assertNotNull(transform.store());
}
 
开发者ID:filestack,项目名称:filestack-java,代码行数:18,代码来源:TestImageTransform.java


示例3: 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());
}
 
开发者ID:filestack,项目名称:filestack-java,代码行数:18,代码来源:TestClient.java


示例4: setupUploadMock

import retrofit2.mock.Calls; //导入依赖的package包/类
private static void setupUploadMock(UploadService mockUploadService) {
  String jsonString = "{"
      + "'url' : 'https://s3.amazonaws.com/path',"
      + "'headers' : {"
      + "'Authorization' : 'auth_value',"
      + "'Content-MD5' : 'md5_value',"
      + "'x-amz-content-sha256' : 'sha256_value',"
      + "'x-amz-date' : 'date_value',"
      + "'x-amz-acl' : 'acl_value'"
      + "},"
      + "'location_url' : 'url'"
      + "}";

  Gson gson = new Gson();
  final UploadResponse response = gson.fromJson(jsonString, UploadResponse.class);
  Mockito
      .doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
          return Calls.response(response);
        }
      })
      .when(mockUploadService)
      .upload(Mockito.<String, RequestBody>anyMap());
}
 
开发者ID:filestack,项目名称:filestack-java,代码行数:26,代码来源:TestClient.java


示例5: setupUploadS3Mock

import retrofit2.mock.Calls; //导入依赖的package包/类
private static void setupUploadS3Mock(UploadService mockUploadService) {
  MediaType mediaType = MediaType.parse("text/xml");
  ResponseBody responseBody = ResponseBody.create(mediaType, "");
  final Response<ResponseBody> response = Response.success(responseBody,
      Headers.of("ETag", "test-etag"));
  Mockito
      .doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
          return Calls.response(response);
        }
      })
      .when(mockUploadService)
      .uploadS3(Mockito.<String, String>anyMap(), Mockito.anyString(),
          Mockito.any(RequestBody.class));
}
 
开发者ID:filestack,项目名称:filestack-java,代码行数:17,代码来源:TestClient.java


示例6: 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());
}
 
开发者ID:filestack,项目名称:filestack-java,代码行数:18,代码来源:TestClient.java


示例7: testImageSfw

import retrofit2.mock.Calls; //导入依赖的package包/类
@Test
public void testImageSfw() throws Exception {
  Mockito.doAnswer(new Answer() {
    @Override
    public Call<ResponseBody> answer(InvocationOnMock invocation) throws Throwable {
      String handle = invocation.getArgument(1);
      String json = "{'sfw': " + (handle.equals("safe") ? "true" : "false") + "}";
      MediaType mediaType = MediaType.parse("application/json");
      return Calls.response(ResponseBody.create(mediaType, json));
    }
  })
      .when(Networking.getCdnService())
      .transform(Mockito.anyString(), Mockito.anyString());

  Config config = new Config("apiKey", "policy", "signature");

  FileLink safe = new FileLink(config, "safe");
  FileLink notSafe = new FileLink(config, "notSafe");

  Assert.assertTrue(safe.imageSfw());
  Assert.assertFalse(notSafe.imageSfw());
}
 
开发者ID:filestack,项目名称:filestack-java,代码行数:23,代码来源:TestFileLink.java


示例8: 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


示例9: refreshAuthToken

import retrofit2.mock.Calls; //导入依赖的package包/类
@Override
public Observable<AuthToken> refreshAuthToken(@Body RefreshReqBody credentials) {
    if (credentials.refreshToken.equals("refresh-token")) {
        AuthToken token = new AuthToken();
        token.setAccessToken("refreshed-access-token");
        // token.setRefreshToken("refresh-token");      // refreshed tokens don't have a new refresh token
        token.setCreatedAt(System.currentTimeMillis());
        token.setExpiresIn(60 * 1000);
        return mDelegate
                .returningResponse(token)
                .refreshAuthToken(credentials);
    } else {
        // expired / invalid refresh token
        ResponseBody body = ResponseBody.create(MediaType.parse("application/json"),
                "{\"errors\":[{\"message\":\"Expired or invalid refresh token\",\"errorType\":\"UnauthorizedError\"}]}");
        Response<Object> res = Response.error(401, body);
        return mDelegate
                .returning(Calls.response(res))
                .refreshAuthToken(credentials);
    }
}
 
开发者ID:vickychijwani,项目名称:quill,代码行数:22,代码来源:MockGhostApiService.java


示例10: 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


示例11: 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


示例12: 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");
        }
    });
}
 
开发者ID:twitter,项目名称:twitter-kit-android,代码行数:19,代码来源:TwitterAuthClientTest.java


示例13: 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


示例14: 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


示例15: setUp

import retrofit2.mock.Calls; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    context = RuntimeEnvironment.application;
    mockMediaService = mock(MediaService.class);
    mockStatusesService = mock(StatusesService.class);
    tweet =  new TweetBuilder().setId(123L).setText(EXPECTED_TWEET_TEXT).build();
    when(mockMediaService
            .upload(any(RequestBody.class), any(RequestBody.class), any(RequestBody.class)))
            .thenReturn(mock(Call.class));
    when(mockStatusesService.update(anyString(), isNull(Long.class), isNull(Boolean.class),
            isNull(Double.class), isNull(Double.class), isNull(String.class),
            isNull(Boolean.class), eq(true), isNull(String.class)))
            .thenReturn(Calls.response(tweet));

    mockTwitterApiClient = mock(TwitterApiClient.class);
    when(mockTwitterApiClient.getStatusesService()).thenReturn(mockStatusesService);
    when(mockTwitterApiClient.getMediaService()).thenReturn(mockMediaService);

    mockDependencyProvider = mock(TweetUploadService.DependencyProvider.class);
    when(mockDependencyProvider.getTwitterApiClient(any(TwitterSession.class)))
            .thenReturn(mockTwitterApiClient);

    service = spy(Robolectric.buildService(TweetUploadService.class).create().get());
    service.dependencyProvider = mockDependencyProvider;
}
 
开发者ID:twitter,项目名称:twitter-kit-android,代码行数:26,代码来源:TweetUploadServiceTest.java


示例16: testUploadTweet_withNoMediaFailure

import retrofit2.mock.Calls; //导入依赖的package包/类
@Test
public void testUploadTweet_withNoMediaFailure() {
    when(mockStatusesService.update(anyString(), isNull(Long.class), isNull(Boolean.class),
            isNull(Double.class), isNull(Double.class), isNull(String.class),
            isNull(Boolean.class), eq(true), isNull(String.class)))
            .thenReturn(Calls.failure(new IOException("")));

    service.uploadTweet(mock(TwitterSession.class), EXPECTED_TWEET_TEXT, null);

    verify(mockStatusesService).update(eq(EXPECTED_TWEET_TEXT), isNull(Long.class),
            isNull(Boolean.class), isNull(Double.class), isNull(Double.class),
            isNull(String.class), isNull(Boolean.class), eq(true), isNull(String.class));
    verifyZeroInteractions(mockMediaService);
    verify(service).fail(any(TwitterException.class));
    verify(service).stopSelf();
}
 
开发者ID:twitter,项目名称:twitter-kit-android,代码行数:17,代码来源:TweetUploadServiceTest.java


示例17: 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


示例18: testDebugHandle

import retrofit2.mock.Calls; //导入依赖的package包/类
@Test
public void testDebugHandle() throws Exception {
  Config config = new Config("apiKey");
  ImageTransform transform = new ImageTransform(config, "handle", false);

  Mockito
      .doReturn(Calls.response(new JsonObject()))
      .when(Networking.getCdnService())
      .transformDebug("", "handle");

  Assert.assertNotNull(transform.debug());
}
 
开发者ID:filestack,项目名称:filestack-java,代码行数:13,代码来源:TestImageTransform.java


示例19: testDebugExternal

import retrofit2.mock.Calls; //导入依赖的package包/类
@Test
public void testDebugExternal() throws Exception {
  String url = "https://example.com/image.jpg";
  Config config = new Config("apiKey");
  ImageTransform transform = new ImageTransform(config, url, true);

  Mockito
      .doReturn(Calls.response(new JsonObject()))
      .when(Networking.getCdnService())
      .transformDebugExt("apiKey", "", url);

  Assert.assertNotNull(transform.debug());
}
 
开发者ID:filestack,项目名称:filestack-java,代码行数:14,代码来源:TestImageTransform.java


示例20: testStoreHandle

import retrofit2.mock.Calls; //导入依赖的package包/类
@Test
public void testStoreHandle() throws Exception {
  Config config = new Config("apiKey");
  ImageTransform transform = new ImageTransform(config, "handle", false);
  String jsonString = "{'url': 'https://cdn.filestackcontent.com/handle'}";
  Gson gson = new Gson();
  StoreResponse storeResponse = gson.fromJson(jsonString, StoreResponse.class);

  Mockito
      .doReturn(Calls.response(storeResponse))
      .when(Networking.getCdnService())
      .transformStore("store", "handle");

  Assert.assertNotNull(transform.store());
}
 
开发者ID:filestack,项目名称:filestack-java,代码行数:16,代码来源:TestImageTransform.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Pattern类代码示例发布时间:2022-05-22
下一篇:
Java DriverService类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap