Source:
public void getBalanceByCurrencyShouldReturnTheCurrency() throws Exception { final AtomicReference<Currency> bodyRefResponse = new AtomicReference<>(); final AtomicReference<Request> bodyRefRequest = new AtomicReference<>(); final CountDownLatch latch = new CountDownLatch(1); User user = Fixtures.loadUser(); BitreserveRestAdapter mockRestDapter = new BitreserveRestAdapter("foobar"); mockRestDapter.setAdapter(new RestAdapter.Builder().setEndpoint(GlobalConfigurations.SERVER_URL).setClient(new Client() { @Override public Response execute(Request request) throws IOException { String responseString = "{" + "\"balances\": {" + "\"total\": \"1083.77\"," + "\"currencies\": {" + "\"CNY\": {" + "\"amount\": \"6.98\"," + "\"balance\": \"42.82\"," + "\"currency\": \"USD\"," + "\"rate\": \"6.13880\"" + "}," + "\"EUR\": {" + "\"amount\": \"75.01\"," + "\"balance\": \"58.05\"," + "\"currency\": \"USD\"," + "\"rate\": \"1.29220\"" + "}" + "}" + "}" + "}"; 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()); user.setBitreserveRestAdapter(mockRestDapter); user.getBalanceByCurrency("EUR").then(new PromiseAction<Currency>() { @Override public void call(Currency currency) { bodyRefResponse.set(currency); latch.countDown(); } }).fail(new PromiseAction<Exception>() { @Override public void call(Exception e) { latch.countDown(); } }); latch.await(); Currency currency = bodyRefResponse.get(); Request request = bodyRefRequest.get(); Assert.assertEquals(request.getMethod(), "GET"); Assert.assertEquals(request.getUrl(), "<LINK_0>"); Assert.assertEquals(currency.getAmount(), "75.01"); Assert.assertEquals(currency.getBalance(), "58.05"); Assert.assertEquals(currency.getCurrency(), "USD"); Assert.assertEquals(currency.getRate(), "1.29220"); }

Target:
public void getBalanceByCurrencyShouldReturnTheCurrency() throws Exception { final AtomicReference<Currency> bodyRefResponse = new AtomicReference<>(); final AtomicReference<Request> bodyRefRequest = new AtomicReference<>(); final CountDownLatch latch = new CountDownLatch(1); User user = 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 = "{" + "\"balances\": {" + "\"total\": \"1083.77\"," + "\"currencies\": {" + "\"CNY\": {" + "\"amount\": \"6.98\"," + "\"balance\": \"42.82\"," + "\"currency\": \"USD\"," + "\"rate\": \"6.13880\"" + "}," + "\"EUR\": {" + "\"amount\": \"75.01\"," + "\"balance\": \"58.05\"," + "\"currency\": \"USD\"," + "\"rate\": \"1.29220\"" + "}" + "}" + "}" + "}"; bodyRefRequest.set(request); return new Response("some/url", 200, "reason", new ArrayList<retrofit.client.Header>(), new TypedByteArray("application/json", responseString.getBytes())); } }).build()); user.setBitreserveRestAdapter(mockRestAdapter); user.getBalanceByCurrency("EUR").then(new PromiseAction<Currency>() { @Override public void call(Currency currency) { bodyRefResponse.set(currency); latch.countDown(); } }).fail(new PromiseAction<Exception>() { @Override public void call(Exception e) { latch.countDown(); } }); latch.await(); Currency currency = bodyRefResponse.get(); Request request = bodyRefRequest.get(); Assert.assertEquals(request.getMethod(), "GET"); Assert.assertEquals(request.getUrl(), "<LINK_0>"); Assert.assertEquals(currency.getAmount(), "75.01"); Assert.assertEquals(currency.getBalance(), "58.05"); Assert.assertEquals(currency.getCurrency(), "USD"); Assert.assertEquals(currency.getRate(), "1.29220"); }