### Question:
Api { @NonNull @WorkerThread public CallResult<WithdrawResponse> withdraw(@NonNull String coinName, double amount, @NonNull String address) { Map<String, String> parameters = new HashMap<>(); parameters.put("coinName", coinName); parameters.put("amount", String.valueOf(amount)); parameters.put("address", address); JsonObject response = authApi.makeRequest(AuthApi.TradeMethod.WITHDRAW, parameters); CallResult<WithdrawResponse> result = new CallResult<>(); if (response == null || (response.has(SUCCESS_KEY) && response.get(SUCCESS_KEY).getAsInt() == 0)) { result.isSuccess = false; result.error = response == null ? generalErrorText : response.get(ERROR_KEY).getAsString(); return result; } result.isSuccess = true; result.payload = WithdrawResponse.create(response.getAsJsonObject(RETURN_KEY)); 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 withdraw_success() throws Exception { when(mockAuthApi.makeRequest(eq(WITHDRAW), anyMapOf(String.class, String.class))) .thenReturn(JSON_PARSER.parse("{\n" + "\t\"success\":1,\n" + "\t\"return\":{\n" + "\t\t\"tId\":37832629,\n" + "\t\t\"amountSent\":0.009,\n" + "\t\t\"funds\":{\n" + "\t\t\t\"usd\":325,\n" + "\t\t\t\"btc\":24.998,\n" + "\t\t\t\"ltc\":0\n" + "\t\t}\n" + "\t}\n" + "}").getAsJsonObject()); CallResult<WithdrawResponse> callResult = testable.withdraw("BTC", 5, "1Az"); assertTrue(callResult.isSuccess()); assertNull(callResult.getError()); WithdrawResponse response = callResult.getPayload(); assertNotNull(response); assertEquals(37832629, response.getTransactionId()); assertEquals(new BigDecimal("0.009"), response.getAmountSent()); assertEquals(new BigDecimal("24.998"), response.getFunds().get("BTC")); }
@Test public void withdraw_error() throws Exception { when(mockAuthApi.makeRequest(eq(CANCEL_ORDER), anyMapOf(String.class, String.class))) .thenReturn(JSON_PARSER.parse("{\"success\":0,\"error\":\"error\"}") .getAsJsonObject()); CallResult<WithdrawResponse> callResult = testable.withdraw("BTC", 5, "1Az"); assertFalse(callResult.isSuccess()); assertNotNull(callResult.getError()); assertNull(callResult.getPayload()); }