Skip to content

Commit

Permalink
chore: Fix Sonar URL whines (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
gazbert committed Nov 14, 2024
1 parent aee6ce3 commit 1e718bd
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import com.google.gson.GsonBuilder;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URI;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
Expand All @@ -70,13 +71,13 @@
*/
@RunWith(PowerMockRunner.class)
@PowerMockIgnore({
"javax.crypto.*",
"javax.management.*",
"com.sun.org.apache.xerces.*",
"javax.xml.parsers.*",
"org.xml.sax.*",
"org.w3c.dom.*",
"javax.xml.datatype.*"
"javax.crypto.*",
"javax.management.*",
"com.sun.org.apache.xerces.*",
"javax.xml.parsers.*",
"org.xml.sax.*",
"org.w3c.dom.*",
"javax.xml.datatype.*"
})
@PrepareForTest(BitfinexExchangeAdapter.class)
public class TestBitfinexExchangeAdapter extends AbstractExchangeAdapterTest {
Expand Down Expand Up @@ -1053,7 +1054,7 @@ public void testSendingPublicRequestToExchangeSuccessfully() throws Exception {
MOCKED_MAKE_NETWORK_REQUEST_METHOD,
MOCKED_CREATE_REQUEST_PARAM_MAP_METHOD);

final URL url = new URL(PUBLIC_API_BASE_URL + PUB_TICKER + "/" + MARKET_ID);
final URL url = new URI(PUBLIC_API_BASE_URL + PUB_TICKER + "/" + MARKET_ID).toURL();
PowerMock.expectPrivate(
exchangeAdapter,
MOCKED_MAKE_NETWORK_REQUEST_METHOD,
Expand All @@ -1080,7 +1081,7 @@ public void testSendingPublicRequestToExchangeHandlesExchangeNetworkException()
MOCKED_MAKE_NETWORK_REQUEST_METHOD,
MOCKED_CREATE_REQUEST_PARAM_MAP_METHOD);

final URL url = new URL(PUBLIC_API_BASE_URL + PUB_TICKER + "/" + MARKET_ID);
final URL url = new URI(PUBLIC_API_BASE_URL + PUB_TICKER + "/" + MARKET_ID).toURL();
PowerMock.expectPrivate(
exchangeAdapter,
MOCKED_MAKE_NETWORK_REQUEST_METHOD,
Expand Down Expand Up @@ -1116,7 +1117,7 @@ public void testSendingPublicRequestToExchangeHandlesTradingApiException() throw
MOCKED_MAKE_NETWORK_REQUEST_METHOD,
MOCKED_CREATE_REQUEST_PARAM_MAP_METHOD);

final URL url = new URL(PUBLIC_API_BASE_URL + PUB_TICKER + "/" + MARKET_ID);
final URL url = new URI(PUBLIC_API_BASE_URL + PUB_TICKER + "/" + MARKET_ID).toURL();
PowerMock.expectPrivate(
exchangeAdapter,
MOCKED_MAKE_NETWORK_REQUEST_METHOD,
Expand Down Expand Up @@ -1183,7 +1184,7 @@ public void testSendingAuthenticatedRequestToExchangeSuccessfully() throws Excep
PowerMock.expectPrivate(exchangeAdapter, MOCKED_CREATE_REQUEST_HEADER_MAP_METHOD)
.andReturn(requestHeaderMap);

final URL url = new URL(AUTHENTICATED_API_URL + ORDER_NEW);
final URL url = new URI(AUTHENTICATED_API_URL + ORDER_NEW).toURL();
PowerMock.expectPrivate(
exchangeAdapter,
MOCKED_MAKE_NETWORK_REQUEST_METHOD,
Expand Down Expand Up @@ -1246,7 +1247,7 @@ public void testSendingAuthenticatedRequestToExchangeHandlesExchangeNetworkExcep
PowerMock.expectPrivate(exchangeAdapter, MOCKED_CREATE_REQUEST_HEADER_MAP_METHOD)
.andReturn(requestHeaderMap);

final URL url = new URL(AUTHENTICATED_API_URL + ORDER_NEW);
final URL url = new URI(AUTHENTICATED_API_URL + ORDER_NEW).toURL();
PowerMock.expectPrivate(
exchangeAdapter,
MOCKED_MAKE_NETWORK_REQUEST_METHOD,
Expand Down Expand Up @@ -1306,7 +1307,7 @@ public void testSendingAuthenticatedRequestToExchangeHandlesTradingApiException(
PowerMock.expectPrivate(exchangeAdapter, MOCKED_CREATE_REQUEST_HEADER_MAP_METHOD)
.andReturn(requestHeaderMap);

final URL url = new URL(AUTHENTICATED_API_URL + ORDER_NEW);
final URL url = new URI(AUTHENTICATED_API_URL + ORDER_NEW).toURL();
PowerMock.expectPrivate(
exchangeAdapter,
MOCKED_MAKE_NETWORK_REQUEST_METHOD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import com.gazbert.bxbot.trading.api.TradingApiException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URI;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
Expand All @@ -71,12 +72,12 @@
*/
@RunWith(PowerMockRunner.class)
@PowerMockIgnore({
"javax.crypto.*",
"javax.management.*",
"com.sun.org.apache.xerces.*",
"javax.xml.parsers.*",
"org.xml.sax.*",
"org.w3c.dom.*"
"javax.crypto.*",
"javax.management.*",
"com.sun.org.apache.xerces.*",
"javax.xml.parsers.*",
"org.xml.sax.*",
"org.w3c.dom.*"
})
@PrepareForTest(BitstampExchangeAdapter.class)
public class TestBitstampExchangeAdapter extends AbstractExchangeAdapter {
Expand Down Expand Up @@ -1033,7 +1034,7 @@ public void testSendingPublicRequestToExchangeSuccessfully() throws Exception {
PowerMock.createPartialMockAndInvokeDefaultConstructor(
BitstampExchangeAdapter.class, MOCKED_MAKE_NETWORK_REQUEST_METHOD);

final URL url = new URL(API_BASE_URL + TICKER + MARKET_ID);
final URL url = new URI(API_BASE_URL + TICKER + MARKET_ID).toURL();
PowerMock.expectPrivate(
exchangeAdapter,
MOCKED_MAKE_NETWORK_REQUEST_METHOD,
Expand All @@ -1058,7 +1059,7 @@ public void testSendingPublicRequestToExchangeHandlesExchangeNetworkException()
PowerMock.createPartialMockAndInvokeDefaultConstructor(
BitstampExchangeAdapter.class, MOCKED_MAKE_NETWORK_REQUEST_METHOD);

final URL url = new URL(API_BASE_URL + TICKER + MARKET_ID);
final URL url = new URI(API_BASE_URL + TICKER + MARKET_ID).toURL();
PowerMock.expectPrivate(
exchangeAdapter,
MOCKED_MAKE_NETWORK_REQUEST_METHOD,
Expand All @@ -1084,7 +1085,7 @@ public void testSendingPublicRequestToExchangeHandlesTradingApiException() throw
PowerMock.createPartialMockAndInvokeDefaultConstructor(
BitstampExchangeAdapter.class, MOCKED_MAKE_NETWORK_REQUEST_METHOD);

final URL url = new URL(API_BASE_URL + TICKER + MARKET_ID);
final URL url = new URI(API_BASE_URL + TICKER + MARKET_ID).toURL();
PowerMock.expectPrivate(
exchangeAdapter,
MOCKED_MAKE_NETWORK_REQUEST_METHOD,
Expand Down Expand Up @@ -1143,7 +1144,7 @@ public void testSendingAuthenticatedRequestToExchangeSuccessfully() throws Excep
PowerMock.expectPrivate(exchangeAdapter, MOCKED_CREATE_REQUEST_PARAM_MAP_METHOD)
.andReturn(requestParamMap);

final URL url = new URL(API_BASE_URL + SELL + MARKET_ID + "/");
final URL url = new URI(API_BASE_URL + SELL + MARKET_ID + "/").toURL();
PowerMock.expectPrivate(
exchangeAdapter,
MOCKED_MAKE_NETWORK_REQUEST_METHOD,
Expand Down Expand Up @@ -1201,7 +1202,7 @@ public void testSendingAuthenticatedRequestToExchangeHandlesExchangeNetworkExcep
PowerMock.expectPrivate(exchangeAdapter, MOCKED_CREATE_REQUEST_PARAM_MAP_METHOD)
.andReturn(requestParamMap);

final URL url = new URL(API_BASE_URL + SELL + MARKET_ID + "/");
final URL url = new URI(API_BASE_URL + SELL + MARKET_ID + "/").toURL();
PowerMock.expectPrivate(
exchangeAdapter,
MOCKED_MAKE_NETWORK_REQUEST_METHOD,
Expand Down Expand Up @@ -1256,7 +1257,7 @@ public void testSendingAuthenticatedRequestToExchangeHandlesTradingApiException(
PowerMock.expectPrivate(exchangeAdapter, MOCKED_CREATE_REQUEST_PARAM_MAP_METHOD)
.andReturn(requestParamMap);

final URL url = new URL(API_BASE_URL + SELL + MARKET_ID + "/");
final URL url = new URI(API_BASE_URL + SELL + MARKET_ID + "/").toURL();
PowerMock.expectPrivate(
exchangeAdapter,
MOCKED_MAKE_NETWORK_REQUEST_METHOD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import com.gazbert.bxbot.trading.api.TradingApiException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URI;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
Expand Down Expand Up @@ -831,7 +832,7 @@ public void testSendingPublicRequestToExchangeSuccessfully() throws Exception {
PowerMock.expectPrivate(exchangeAdapter, MOCKED_CREATE_REQUEST_PARAM_MAP_METHOD)
.andReturn(requestParamMap);

final URL url = new URL(PUBLIC_API_BASE_URL + PUBTICKER + "/" + ETH_BTC_MARKET_ID);
final URL url = new URI(PUBLIC_API_BASE_URL + PUBTICKER + "/" + ETH_BTC_MARKET_ID).toURL();
PowerMock.expectPrivate(
exchangeAdapter,
MOCKED_MAKE_NETWORK_REQUEST_METHOD,
Expand Down Expand Up @@ -863,7 +864,7 @@ public void testSendingPublicRequestToExchangeHandlesExchangeNetworkException()
PowerMock.expectPrivate(exchangeAdapter, MOCKED_CREATE_REQUEST_PARAM_MAP_METHOD)
.andReturn(requestParamMap);

final URL url = new URL(PUBLIC_API_BASE_URL + PUBTICKER + "/" + ETH_BTC_MARKET_ID);
final URL url = new URI(PUBLIC_API_BASE_URL + PUBTICKER + "/" + ETH_BTC_MARKET_ID).toURL();
PowerMock.expectPrivate(
exchangeAdapter,
MOCKED_MAKE_NETWORK_REQUEST_METHOD,
Expand Down Expand Up @@ -899,7 +900,7 @@ public void testSendingPublicRequestToExchangeHandlesTradingApiException() throw
PowerMock.expectPrivate(exchangeAdapter, MOCKED_CREATE_REQUEST_PARAM_MAP_METHOD)
.andReturn(requestParamMap);

final URL url = new URL(PUBLIC_API_BASE_URL + PUBTICKER + "/" + ETH_BTC_MARKET_ID);
final URL url = new URI(PUBLIC_API_BASE_URL + PUBTICKER + "/" + ETH_BTC_MARKET_ID).toURL();
PowerMock.expectPrivate(
exchangeAdapter,
MOCKED_MAKE_NETWORK_REQUEST_METHOD,
Expand Down Expand Up @@ -963,7 +964,7 @@ public void testSendingAuthenticatedRequestToExchangeSuccessfully() throws Excep
PowerMock.expectPrivate(exchangeAdapter, MOCKED_CREATE_REQUEST_PARAM_MAP_METHOD)
.andReturn(requestParamMap);

final URL url = new URL(AUTHENTICATED_API_URL + ORDER_NEW);
final URL url = new URI(AUTHENTICATED_API_URL + ORDER_NEW).toURL();
PowerMock.expectPrivate(
exchangeAdapter,
MOCKED_MAKE_NETWORK_REQUEST_METHOD,
Expand Down Expand Up @@ -1026,7 +1027,7 @@ public void testSendingAuthenticatedRequestToExchangeHandlesExchangeNetworkExcep
PowerMock.expectPrivate(exchangeAdapter, MOCKED_CREATE_REQUEST_PARAM_MAP_METHOD)
.andReturn(requestParamMap);

final URL url = new URL(AUTHENTICATED_API_URL + ORDER_NEW);
final URL url = new URI(AUTHENTICATED_API_URL + ORDER_NEW).toURL();
PowerMock.expectPrivate(
exchangeAdapter,
MOCKED_MAKE_NETWORK_REQUEST_METHOD,
Expand Down Expand Up @@ -1090,7 +1091,7 @@ public void testSendingAuthenticatedRequestToExchangeHandlesTradingApiException(
PowerMock.expectPrivate(exchangeAdapter, MOCKED_CREATE_REQUEST_PARAM_MAP_METHOD)
.andReturn(requestParamMap);

final URL url = new URL(AUTHENTICATED_API_URL + ORDER_NEW);
final URL url = new URI(AUTHENTICATED_API_URL + ORDER_NEW).toURL();
PowerMock.expectPrivate(
exchangeAdapter,
MOCKED_MAKE_NETWORK_REQUEST_METHOD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URI;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
Expand All @@ -75,12 +76,12 @@
*/
@RunWith(PowerMockRunner.class)
@PowerMockIgnore({
"javax.crypto.*",
"javax.management.*",
"com.sun.org.apache.xerces.*",
"javax.xml.parsers.*",
"org.xml.sax.*",
"org.w3c.dom.*"
"javax.crypto.*",
"javax.management.*",
"com.sun.org.apache.xerces.*",
"javax.xml.parsers.*",
"org.xml.sax.*",
"org.w3c.dom.*"
})
@PrepareForTest(KrakenExchangeAdapter.class)
public class TestKrakenExchangeAdapter extends AbstractExchangeAdapterTest {
Expand Down Expand Up @@ -223,7 +224,7 @@ public void testGettingMarketOrdersSuccessfully() throws Exception {
final MarketOrderBook marketOrderBook = exchangeAdapter.getMarketOrders(MARKET_ID);

// assert some key stuff; we're not testing GSON here.
// assertTrue(marketOrderBook.getMarketId().equals(MARKET_ID));
assertEquals(MARKET_ID, marketOrderBook.getMarketId());

final BigDecimal buyPrice = new BigDecimal("662.55000");
final BigDecimal buyQuantity = new BigDecimal("5.851");
Expand Down Expand Up @@ -1195,7 +1196,7 @@ public void testSendingPublicRequestToExchangeSuccessfully() throws Exception {
PowerMock.expectPrivate(exchangeAdapter, MOCKED_CREATE_REQUEST_PARAM_MAP_METHOD)
.andReturn(requestParamMap);

final URL url = new URL(PUBLIC_API_BASE_URL + TICKER);
final URL url = new URI(PUBLIC_API_BASE_URL + TICKER).toURL();
PowerMock.expectPrivate(
exchangeAdapter,
MOCKED_MAKE_NETWORK_REQUEST_METHOD,
Expand Down Expand Up @@ -1229,7 +1230,7 @@ public void testSendingPublicRequestToExchangeHandlesExchangeNetworkException()
PowerMock.expectPrivate(exchangeAdapter, MOCKED_CREATE_REQUEST_PARAM_MAP_METHOD)
.andReturn(requestParamMap);

final URL url = new URL(PUBLIC_API_BASE_URL + TICKER);
final URL url = new URI(PUBLIC_API_BASE_URL + TICKER).toURL();
PowerMock.expectPrivate(
exchangeAdapter,
MOCKED_MAKE_NETWORK_REQUEST_METHOD,
Expand Down Expand Up @@ -1266,7 +1267,7 @@ public void testSendingPublicRequestToExchangeHandlesTradingApiException() throw
PowerMock.expectPrivate(exchangeAdapter, MOCKED_CREATE_REQUEST_PARAM_MAP_METHOD)
.andReturn(requestParamMap);

final URL url = new URL(PUBLIC_API_BASE_URL + TICKER);
final URL url = new URI(PUBLIC_API_BASE_URL + TICKER).toURL();
PowerMock.expectPrivate(
exchangeAdapter,
MOCKED_MAKE_NETWORK_REQUEST_METHOD,
Expand Down Expand Up @@ -1335,7 +1336,7 @@ public void testSendingAuthenticatedRequestToExchangeSuccessfully() throws Excep
PowerMock.expectPrivate(exchangeAdapter, MOCKED_CREATE_REQUEST_PARAM_MAP_METHOD)
.andReturn(requestParamMap);

final URL url = new URL(AUTHENTICATED_API_URL + ADD_ORDER);
final URL url = new URI(AUTHENTICATED_API_URL + ADD_ORDER).toURL();
PowerMock.expectPrivate(
exchangeAdapter,
MOCKED_MAKE_NETWORK_REQUEST_METHOD,
Expand Down Expand Up @@ -1397,7 +1398,7 @@ public void testSendingAuthenticatedRequestToExchangeHandlesExchangeNetworkExcep
PowerMock.expectPrivate(exchangeAdapter, MOCKED_CREATE_REQUEST_PARAM_MAP_METHOD)
.andReturn(requestParamMap);

final URL url = new URL(AUTHENTICATED_API_URL + ADD_ORDER);
final URL url = new URI(AUTHENTICATED_API_URL + ADD_ORDER).toURL();
PowerMock.expectPrivate(
exchangeAdapter,
MOCKED_MAKE_NETWORK_REQUEST_METHOD,
Expand Down Expand Up @@ -1456,7 +1457,7 @@ public void testSendingAuthenticatedRequestToExchangeHandlesTradingApiException(
PowerMock.expectPrivate(exchangeAdapter, MOCKED_CREATE_REQUEST_PARAM_MAP_METHOD)
.andReturn(requestParamMap);

final URL url = new URL(AUTHENTICATED_API_URL + ADD_ORDER);
final URL url = new URI(AUTHENTICATED_API_URL + ADD_ORDER).toURL();
PowerMock.expectPrivate(
exchangeAdapter,
MOCKED_MAKE_NETWORK_REQUEST_METHOD,
Expand All @@ -1466,11 +1467,12 @@ public void testSendingAuthenticatedRequestToExchangeHandlesTradingApiException(
eq(requestHeaderMap))
.andThrow(
new TradingApiException(
"Below the thunders of the upper deep;\n"
+ "Far far beneath in the abysmal sea,\n"
+ "His ancient, dreamless, uninvaded sleep\n"
+ "The Kraken sleepeth: faintest sunlights flee\n"
+ "About his shadowy sides; above him swell..."));
"""
Below the thunders of the upper deep;
Far far beneath in the abysmal sea,
His ancient, dreamless, uninvaded sleep
The Kraken sleepeth: faintest sunlights flee
About his shadowy sides; above him swell..."""));

PowerMock.replayAll();
exchangeAdapter.init(exchangeConfig);
Expand All @@ -1492,7 +1494,7 @@ private void mockAssetPairsPublicRequest(Object exchangeAdapter) throws Exceptio

private void mockAssetPairsNetworkRequest(Object exchangeAdapter) throws Exception {
final ExchangeHttpResponse assetsResponse = createMockAssetPairs();
final URL url = new URL(PUBLIC_API_BASE_URL + ASSET_PAIRS);
final URL url = new URI(PUBLIC_API_BASE_URL + ASSET_PAIRS).toURL();
PowerMock.expectPrivate(
exchangeAdapter,
MOCKED_MAKE_NETWORK_REQUEST_METHOD,
Expand Down

0 comments on commit 1e718bd

Please sign in to comment.