Search in sources :

Example 26 with MockClient

use of com.recurly.v3.fixtures.MockClient in project recurly-client-java by recurly.

the class PagerTest method testFirst.

@Test
public void testFirst() throws IOException {
    final Call mCall = mock(Call.class);
    Answer answer = (i) -> {
        Request request = i.getArgument(0);
        HttpUrl url = request.url();
        assertEquals("1", url.queryParameter("limit"));
        return mCall;
    };
    when(mCall.execute()).thenReturn(MockClient.buildResponse(200, "OK", getResourceFirstItemJson()));
    OkHttpClient mockOkHttpClient = MockClient.getMockOkHttpClient(answer);
    final MockClient client = new MockClient("apiKey", mockOkHttpClient);
    Pager<MyResource> pager = client.listResources(null);
    MyResource resource = pager.getFirst();
    assertEquals("Resource First Item", resource.getMyString());
}
Also used : Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) Answer(org.mockito.stubbing.Answer) MockClient(com.recurly.v3.fixtures.MockClient) Request(okhttp3.Request) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) okhttp3(okhttp3) Assertions(org.junit.jupiter.api.Assertions) MyResource(com.recurly.v3.fixtures.MyResource) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IOException(java.io.IOException) NoSuchElementException(java.util.NoSuchElementException) Answer(org.mockito.stubbing.Answer) Request(okhttp3.Request) MockClient(com.recurly.v3.fixtures.MockClient) MyResource(com.recurly.v3.fixtures.MyResource) Test(org.junit.jupiter.api.Test)

Aggregations

MockClient (com.recurly.v3.fixtures.MockClient)26 Test (org.junit.jupiter.api.Test)26 MyResource (com.recurly.v3.fixtures.MyResource)20 IOException (java.io.IOException)20 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)20 Request (okhttp3.Request)20 Answer (org.mockito.stubbing.Answer)20 HashMap (java.util.HashMap)18 ApiException (com.recurly.v3.ApiException)14 ExceptionFactory (com.recurly.v3.exception.ExceptionFactory)14 InternalServerException (com.recurly.v3.exception.InternalServerException)14 InvalidApiKeyException (com.recurly.v3.exception.InvalidApiKeyException)14 NotFoundException (com.recurly.v3.exception.NotFoundException)14 TransactionException (com.recurly.v3.exception.TransactionException)14 ValidationException (com.recurly.v3.exception.ValidationException)14 FixtureConstants (com.recurly.v3.fixtures.FixtureConstants)14 MockQueryParams (com.recurly.v3.fixtures.MockQueryParams)14 MyRequest (com.recurly.v3.fixtures.MyRequest)14 InputStream (java.io.InputStream)14 Field (java.lang.reflect.Field)14