Search in sources :

Example 36 with User

use of com.androidnetworking.model.User in project Fast-Android-Networking by amitshekhariitbhu.

the class GetObjectApiTest method testObjectListGetRequest.

public void testObjectListGetRequest() throws InterruptedException {
    server.enqueue(new MockResponse().setBody("[{\"firstName\":\"Amit\", \"lastName\":\"Shekhar\"}]"));
    final AtomicReference<String> firstNameRef = new AtomicReference<>();
    final AtomicReference<String> lastNameRef = new AtomicReference<>();
    final CountDownLatch latch = new CountDownLatch(1);
    AndroidNetworking.get(server.url("/").toString()).build().getAsObjectList(User.class, new ParsedRequestListener<List<User>>() {

        @Override
        public void onResponse(List<User> userList) {
            firstNameRef.set(userList.get(0).firstName);
            lastNameRef.set(userList.get(0).lastName);
            latch.countDown();
        }

        @Override
        public void onError(ANError anError) {
            assertTrue(false);
        }
    });
    assertTrue(latch.await(2, SECONDS));
    assertEquals("Amit", firstNameRef.get());
    assertEquals("Shekhar", lastNameRef.get());
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) User(com.androidnetworking.model.User) AtomicReference(java.util.concurrent.atomic.AtomicReference) List(java.util.List) ANError(com.androidnetworking.error.ANError) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

User (com.androidnetworking.model.User)36 MockResponse (okhttp3.mockwebserver.MockResponse)36 ANError (com.androidnetworking.error.ANError)30 CountDownLatch (java.util.concurrent.CountDownLatch)27 AtomicReference (java.util.concurrent.atomic.AtomicReference)27 ANResponse (com.androidnetworking.common.ANResponse)15 List (java.util.List)15 Response (okhttp3.Response)15 ANRequest (com.androidnetworking.common.ANRequest)9