From e6bee19e2affac147be8d9a1aebeab1bf5f0c293 Mon Sep 17 00:00:00 2001 From: Anton Kurako Date: Mon, 15 May 2023 20:58:07 +0300 Subject: [PATCH] [2.0.0] BasicProvider simplified StatisticPriceApiTests assert fixed --- .../api/etherscan/BasicProvider.java | 28 ++----------------- .../statistic/StatisticPriceApiTests.java | 4 +-- 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/src/main/java/io/goodforgod/api/etherscan/BasicProvider.java b/src/main/java/io/goodforgod/api/etherscan/BasicProvider.java index 3c88f3b..5c61aad 100644 --- a/src/main/java/io/goodforgod/api/etherscan/BasicProvider.java +++ b/src/main/java/io/goodforgod/api/etherscan/BasicProvider.java @@ -1,6 +1,5 @@ package io.goodforgod.api.etherscan; -import io.goodforgod.api.etherscan.error.EtherScanException; import io.goodforgod.api.etherscan.error.EtherScanParseException; import io.goodforgod.api.etherscan.error.EtherScanRateLimitException; import io.goodforgod.api.etherscan.error.EtherScanResponseException; @@ -9,7 +8,6 @@ import io.goodforgod.api.etherscan.model.response.StringResponseTO; import java.net.URI; import java.nio.charset.StandardCharsets; -import java.util.Map; /** * Base provider for API Implementations @@ -64,36 +62,14 @@ T convert(byte[] json, Class tClass) { } final String jsonAsString = new String(json, StandardCharsets.UTF_8); - try { - final Map map = converter.fromJson(json, Map.class); - final Object result = map.get("result"); - if (result instanceof String && ((String) result).startsWith(MAX_RATE_LIMIT_REACHED)) - throw new EtherScanRateLimitException(((String) result)); - - throw new EtherScanParseException(e.getMessage() + ", for response: " + jsonAsString, e.getCause(), jsonAsString); - } catch (EtherScanException ex) { - throw ex; - } catch (Exception ex) { - throw new EtherScanParseException(e.getMessage() + ", for response: " + jsonAsString, e.getCause(), jsonAsString); - } + throw new EtherScanParseException(e.getMessage() + ", for response: " + jsonAsString, e.getCause(), jsonAsString); } } byte[] getRequest(String urlParameters) { queue.takeTurn(); final URI uri = URI.create(baseUrl + module + urlParameters); - final byte[] result = executor.get(uri); - if (result.length == 0) { - final StringResponseTO emptyResponse = StringResponseTO.builder() - .withStatus("0") - .withMessage("Server returned null value for GET request at URL - " + uri) - .withResult("") - .build(); - - throw new EtherScanResponseException(emptyResponse, "Server returned null value for GET request at URL - " + uri); - } - - return result; + return executor.get(uri); } byte[] postRequest(String urlParameters, String dataToPost) { diff --git a/src/test/java/io/goodforgod/api/etherscan/statistic/StatisticPriceApiTests.java b/src/test/java/io/goodforgod/api/etherscan/statistic/StatisticPriceApiTests.java index 0dd89c2..ffc37a9 100644 --- a/src/test/java/io/goodforgod/api/etherscan/statistic/StatisticPriceApiTests.java +++ b/src/test/java/io/goodforgod/api/etherscan/statistic/StatisticPriceApiTests.java @@ -16,8 +16,8 @@ void correct() { assertNotNull(price); assertNotNull(price.btcTimestamp()); assertNotNull(price.usdTimestamp()); - assertNotEquals(0.0, price.inBtc()); - assertNotEquals(0.0, price.inUsd()); + assertNotEquals(0.0, price.inBtc().doubleValue()); + assertNotEquals(0.0, price.inUsd().doubleValue()); assertNotNull(price.toString()); Price empty = Price.builder().build();