Source:
public void getCardsByCurrencyShouldReturnTheListOfCardsWithCurrency() throws Exception { final AtomicReference<List<Card>> bodyRefResponse = new AtomicReference<>(); final AtomicReference<Request> bodyRefRequest = new AtomicReference<>(); final CountDownLatch latch = new CountDownLatch(1); User mockedUserResponse = Fixtures.loadUser(); BitreserveRestAdapter mockRestAdapter = new BitreserveRestAdapter("foobar"); mockRestAdapter.setAdapter(new RestAdapter.Builder().setEndpoint(GlobalConfigurations.SERVER_URL).setClient(new Client() { @Override public Response execute(Request request) throws IOException { String responseString = "[ { \"id\": \"FOOBAR\", \"currency\": \"USD\" }, { \"id\": \"FOOBIZ\", \"currency\": \"BTC\" } ]"; bodyRefRequest.set(request); return new Response("some/url", 200, "reason", new ArrayList<retrofit.client.Header>() {{ add(new retrofit.client.Header("foo", "bar")); }}, new TypedByteArray("application/json", responseString.getBytes())); } }).build()); mockedUserResponse.setBitreserveRestAdapter(mockRestAdapter); mockedUserResponse.getCardsByCurrency("BTC").then(new PromiseAction<List<Card>>() { @Override public void call(List<Card> cards) { bodyRefResponse.set(cards); latch.countDown(); } }).fail(new PromiseAction<Exception>() { @Override public void call(Exception e) { latch.countDown(); } }); latch.await(); List<Card> cards = bodyRefResponse.get(); Request request = bodyRefRequest.get(); Assert.assertEquals(request.getMethod(), "GET"); Assert.assertEquals(request.getUrl(), "<LINK_0>"); Assert.assertEquals(cards.size(), 1); Assert.assertEquals(cards.get(0).getId(), "FOOBIZ"); }

Target:
public void getCardsByCurrencyShouldReturnTheListOfCardsWithCurrency() throws Exception { final AtomicReference<List<Card>> bodyRefResponse = new AtomicReference<>(); final AtomicReference<Request> bodyRefRequest = new AtomicReference<>(); final CountDownLatch latch = new CountDownLatch(1); User mockedUserResponse = Fixtures.loadUser(); BitreserveRestAdapter mockRestAdapter = new BitreserveRestAdapter("foobar"); mockRestAdapter.setAdapter(new RestAdapter.Builder().setEndpoint(GlobalConfigurations.SERVER_URL).setClient(new Client() { @Override public Response execute(Request request) throws IOException { String responseString = "[ { \"id\": \"FOOBAR\", \"currency\": \"USD\" }, { \"id\": \"FOOBIZ\", \"currency\": \"BTC\" } ]"; bodyRefRequest.set(request); return new Response("some/url", 200, "reason", new ArrayList<retrofit.client.Header>(), new TypedByteArray("application/json", responseString.getBytes())); } }).build()); mockedUserResponse.setBitreserveRestAdapter(mockRestAdapter); mockedUserResponse.getCardsByCurrency("BTC").then(new PromiseAction<List<Card>>() { @Override public void call(List<Card> cards) { bodyRefResponse.set(cards); latch.countDown(); } }).fail(new PromiseAction<Exception>() { @Override public void call(Exception e) { latch.countDown(); } }); latch.await(); List<Card> cards = bodyRefResponse.get(); Request request = bodyRefRequest.get(); Assert.assertEquals(request.getMethod(), "GET"); Assert.assertEquals(request.getUrl(), "<LINK_0>"); Assert.assertEquals(cards.size(), 1); Assert.assertEquals(cards.get(0).getId(), "FOOBIZ"); }