@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()); }
@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 @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 @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); }
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); }
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);  }