### Question:
Api { @NonNull @WorkerThread public CallResult<Depth> depth(@NonNull String pair) { final String serverPair = PairUtils.localToServer(pair); final String url = hostUrl + "/api/3/depth/" + serverPair; JsonObject response = guestApi.call(url); CallResult<Depth> result = new CallResult<>(); if (response == null || response.has(SUCCESS_KEY)) { result.isSuccess = false; result.error = response == null ? generalErrorText : response.get(ERROR_KEY).getAsString(); return result; } result.isSuccess = true; result.payload = Depth.create(pair, response.getAsJsonObject(serverPair)); return result; } Api(@NonNull Context appContext, @NonNull String hostUrl,
               @Nullable String apiKey, @Nullable String apiSecret); @VisibleForTesting  Api(@NonNull Context appContext, @NonNull String hostUrl,
        @NonNull GuestApi guestApi, @NonNull AuthApi authApi); void setCredentials(@NonNull String apiKey, @NonNull String apiSecret); void setHostUrl(@NonNull String hostUrl); @WorkerThread @NonNull CallResult<ExchangeInfo> getExchangeInfo(); @WorkerThread @NonNull CallResult<List<Ticker>> getPairInfo(@NonNull Set<String> pairs); @NonNull @WorkerThread CallResult<Depth> depth(@NonNull String pair); @NonNull @WorkerThread CallResult<AccountInfo> getAccountInfo(); @NonNull @WorkerThread CallResult<List<Transaction>> getTransactionsHistory(
            @NonNull Map<String, String> parameters); @NonNull @WorkerThread CallResult<List<TradeHistoryEntry>> getTradeHistory(
            @NonNull Map<String, String> parameters); @NonNull @WorkerThread CallResult<List<ActiveOrder>> getActiveOrders(); @NonNull @WorkerThread CallResult<TradeResponse> trade(@NonNull String pair, @TradeType @NonNull String type,
                                           @NonNull String rate, @NonNull String amount); @NonNull @WorkerThread CallResult<CancelOrderResponse> cancelOrder(long orderId); @NonNull @WorkerThread CallResult<WithdrawResponse> withdraw(@NonNull String coinName,
                                                 double amount, @NonNull String address);  }### Answer:
@Test public void depth_success() throws Exception { when(mockGuestApi.call(anyString())) .thenReturn(JSON_PARSER.parse("{\"btc_usd\":{\"asks\":[[2377,1],[2377.45,0.15]" + ",[2377.7,0.2]],\"bids\":[[2369.801,0.1],[2369.551,0.15]]}}") .getAsJsonObject()); CallResult<Depth> depthCallResult = testable.depth("BTC/USD"); assertTrue(depthCallResult.isSuccess()); assertNull(depthCallResult.getError()); Depth depth = depthCallResult.getPayload(); assertNotNull(depth); assertEquals("BTC/USD", depth.getPair()); assertEquals(3, depth.getAsks().size()); assertEquals(2, depth.getBids().size()); }
@Test public void depth_error() throws Exception { when(mockGuestApi.call(anyString())) .thenReturn(JSON_PARSER.parse("{\"success\":0," + " \"error\":\"Invalid pair name: btc_us\"}").getAsJsonObject()); CallResult<Depth> depthCallResult = testable.depth("BTC/US"); assertFalse(depthCallResult.isSuccess()); assertNotNull(depthCallResult.getError()); assertNull(depthCallResult.getPayload()); }