@Override protected Void doInBackground(Void... params) { if (application.isConnected()) { try { shapeShiftCoins = application.getShapeShift().getCoins(); } catch (Exception e) { error = e; } } else { error = new ShapeShiftException("No connection"); } return null; }
@Test public void testGetCoins() throws ShapeShiftException, IOException, InterruptedException, JSONException { // Schedule some responses. server.enqueue(new MockResponse().setBody(GET_COINS_JSON)); ShapeShiftCoins coinsReply = shapeShift.getCoins(); assertFalse(coinsReply.isError); assertEquals(3, coinsReply.coins.size()); assertEquals(1, coinsReply.availableCoinTypes.size()); assertEquals(BTC, coinsReply.availableCoinTypes.get(0)); JSONObject coinsJson = new JSONObject(GET_COINS_JSON); for (ShapeShiftCoin coin : coinsReply.coins) { JSONObject json = coinsJson.getJSONObject(coin.symbol); assertEquals(json.getString("name"), coin.name); assertEquals(json.getString("symbol"), coin.symbol); assertEquals(json.getString("image"), coin.image.toString()); assertEquals(json.getString("status").equals("available"), coin.isAvailable); } // Optional: confirm that your app made the HTTP requests you were expecting. RecordedRequest request = server.takeRequest(); assertEquals("/getcoins", request.getPath()); }