diff --git a/xchange-simulated/src/main/java/org/knowm/xchange/simulated/RandomExceptionThrower.java b/xchange-simulated/src/main/java/org/knowm/xchange/simulated/RandomExceptionThrower.java index f150f0fdfe0..2299d60e3d4 100644 --- a/xchange-simulated/src/main/java/org/knowm/xchange/simulated/RandomExceptionThrower.java +++ b/xchange-simulated/src/main/java/org/knowm/xchange/simulated/RandomExceptionThrower.java @@ -4,7 +4,7 @@ import java.io.IOException; import java.net.SocketTimeoutException; import java.util.Random; -import org.apache.commons.lang3.RandomUtils; +import java.util.concurrent.ThreadLocalRandom; import org.knowm.xchange.ExchangeSpecification; import org.knowm.xchange.exceptions.FrequencyLimitExceededException; import org.knowm.xchange.exceptions.NonceException; @@ -63,7 +63,7 @@ public void onSimulatedExchangeOperation() throws IOException { "System overloads are a common error on some exchanges. " + GENERIC_GUIDE); } if (!rateLimiter.tryAcquire()) { - if (RandomUtils.nextBoolean()) { + if (ThreadLocalRandom.current().nextBoolean()) { throw new RateLimitExceededException(RATE_LIMIT_EXCEEDED); } else { throw new FrequencyLimitExceededException(RATE_LIMIT_EXCEEDED); diff --git a/xchange-simulated/src/test/java/org/knowm/xchange/simulated/AbstractFillAssert.java b/xchange-simulated/src/test/java/org/knowm/xchange/simulated/AbstractFillAssert.java index 0a5ebf0074d..c15a25f9606 100644 --- a/xchange-simulated/src/test/java/org/knowm/xchange/simulated/AbstractFillAssert.java +++ b/xchange-simulated/src/test/java/org/knowm/xchange/simulated/AbstractFillAssert.java @@ -1,7 +1,7 @@ package org.knowm.xchange.simulated; +import java.util.Objects; import org.assertj.core.api.AbstractObjectAssert; -import org.assertj.core.util.Objects; /** * Abstract base class for {@link Fill} specific assertions - Generated by CustomAssertionGenerator. @@ -35,7 +35,7 @@ public S hasApiKey(String apiKey) { // null safe check String actualApiKey = actual.getApiKey(); - if (!Objects.areEqual(actualApiKey, apiKey)) { + if (!Objects.deepEquals(actualApiKey, apiKey)) { failWithMessage(assertjErrorMessage, actual, apiKey, actualApiKey); } @@ -97,7 +97,7 @@ public S hasTrade(org.knowm.xchange.dto.trade.UserTrade trade) { // null safe check org.knowm.xchange.dto.trade.UserTrade actualTrade = actual.getTrade(); - if (!Objects.areEqual(actualTrade, trade)) { + if (!Objects.deepEquals(actualTrade, trade)) { failWithMessage(assertjErrorMessage, actual, trade, actualTrade); } diff --git a/xchange-simulated/src/test/java/org/knowm/xchange/simulated/AbstractTradeAssert.java b/xchange-simulated/src/test/java/org/knowm/xchange/simulated/AbstractTradeAssert.java index c65de64e99d..e7819ba3d95 100644 --- a/xchange-simulated/src/test/java/org/knowm/xchange/simulated/AbstractTradeAssert.java +++ b/xchange-simulated/src/test/java/org/knowm/xchange/simulated/AbstractTradeAssert.java @@ -1,7 +1,7 @@ package org.knowm.xchange.simulated; +import java.util.Objects; import org.assertj.core.api.AbstractObjectAssert; -import org.assertj.core.util.Objects; import org.knowm.xchange.dto.marketdata.Trade; /** @@ -38,7 +38,7 @@ public S hasCurrencyPair(org.knowm.xchange.currency.CurrencyPair currencyPair) { // null safe check org.knowm.xchange.currency.CurrencyPair actualCurrencyPair = actual.getCurrencyPair(); - if (!Objects.areEqual(actualCurrencyPair, currencyPair)) { + if (!Objects.deepEquals(actualCurrencyPair, currencyPair)) { failWithMessage(assertjErrorMessage, actual, currencyPair, actualCurrencyPair); } @@ -62,7 +62,7 @@ public S hasId(String id) { // null safe check String actualId = actual.getId(); - if (!Objects.areEqual(actualId, id)) { + if (!Objects.deepEquals(actualId, id)) { failWithMessage(assertjErrorMessage, actual, id, actualId); } @@ -102,7 +102,7 @@ public S hasMakerOrderId(String makerOrderId) { // null safe check String actualMakerOrderId = actual.getMakerOrderId(); - if (!Objects.areEqual(actualMakerOrderId, makerOrderId)) { + if (!Objects.deepEquals(actualMakerOrderId, makerOrderId)) { failWithMessage(assertjErrorMessage, actual, makerOrderId, actualMakerOrderId); } @@ -127,7 +127,7 @@ public S hasOriginalAmount(java.math.BigDecimal originalAmount) { // null safe check java.math.BigDecimal actualOriginalAmount = actual.getOriginalAmount(); - if (!Objects.areEqual(actualOriginalAmount, originalAmount)) { + if (!Objects.deepEquals(actualOriginalAmount, originalAmount)) { failWithMessage(assertjErrorMessage, actual, originalAmount, actualOriginalAmount); } @@ -151,7 +151,7 @@ public S hasPrice(java.math.BigDecimal price) { // null safe check java.math.BigDecimal actualPrice = actual.getPrice(); - if (!Objects.areEqual(actualPrice, price)) { + if (!Objects.deepEquals(actualPrice, price)) { failWithMessage(assertjErrorMessage, actual, price, actualPrice); } @@ -176,7 +176,7 @@ public S hasTakerOrderId(String takerOrderId) { // null safe check String actualTakerOrderId = actual.getTakerOrderId(); - if (!Objects.areEqual(actualTakerOrderId, takerOrderId)) { + if (!Objects.deepEquals(actualTakerOrderId, takerOrderId)) { failWithMessage(assertjErrorMessage, actual, takerOrderId, actualTakerOrderId); } @@ -201,7 +201,7 @@ public S hasTimestamp(java.util.Date timestamp) { // null safe check java.util.Date actualTimestamp = actual.getTimestamp(); - if (!Objects.areEqual(actualTimestamp, timestamp)) { + if (!Objects.deepEquals(actualTimestamp, timestamp)) { failWithMessage(assertjErrorMessage, actual, timestamp, actualTimestamp); } @@ -225,7 +225,7 @@ public S hasType(org.knowm.xchange.dto.Order.OrderType type) { // null safe check org.knowm.xchange.dto.Order.OrderType actualType = actual.getType(); - if (!Objects.areEqual(actualType, type)) { + if (!Objects.deepEquals(actualType, type)) { failWithMessage(assertjErrorMessage, actual, type, actualType); } diff --git a/xchange-simulated/src/test/java/org/knowm/xchange/simulated/AbstractUserTradeAssert.java b/xchange-simulated/src/test/java/org/knowm/xchange/simulated/AbstractUserTradeAssert.java index e3fa4feb362..226d443502f 100644 --- a/xchange-simulated/src/test/java/org/knowm/xchange/simulated/AbstractUserTradeAssert.java +++ b/xchange-simulated/src/test/java/org/knowm/xchange/simulated/AbstractUserTradeAssert.java @@ -1,6 +1,6 @@ package org.knowm.xchange.simulated; -import org.assertj.core.util.Objects; +import java.util.Objects; import org.knowm.xchange.dto.trade.UserTrade; /** @@ -38,7 +38,7 @@ public S hasFeeAmount(java.math.BigDecimal feeAmount) { // null safe check java.math.BigDecimal actualFeeAmount = actual.getFeeAmount(); - if (!Objects.areEqual(actualFeeAmount, feeAmount)) { + if (!Objects.deepEquals(actualFeeAmount, feeAmount)) { failWithMessage(assertjErrorMessage, actual, feeAmount, actualFeeAmount); } @@ -63,7 +63,7 @@ public S hasFeeCurrency(org.knowm.xchange.currency.Currency feeCurrency) { // null safe check org.knowm.xchange.currency.Currency actualFeeCurrency = actual.getFeeCurrency(); - if (!Objects.areEqual(actualFeeCurrency, feeCurrency)) { + if (!Objects.deepEquals(actualFeeCurrency, feeCurrency)) { failWithMessage(assertjErrorMessage, actual, feeCurrency, actualFeeCurrency); } @@ -88,7 +88,7 @@ public S hasOrderId(String orderId) { // null safe check String actualOrderId = actual.getOrderId(); - if (!Objects.areEqual(actualOrderId, orderId)) { + if (!Objects.deepEquals(actualOrderId, orderId)) { failWithMessage(assertjErrorMessage, actual, orderId, actualOrderId); } diff --git a/xchange-simulated/src/test/java/org/knowm/xchange/simulated/TestMatchingEngine.java b/xchange-simulated/src/test/java/org/knowm/xchange/simulated/TestMatchingEngine.java index 41a59a8d5d9..20246363d6b 100644 --- a/xchange-simulated/src/test/java/org/knowm/xchange/simulated/TestMatchingEngine.java +++ b/xchange-simulated/src/test/java/org/knowm/xchange/simulated/TestMatchingEngine.java @@ -16,8 +16,8 @@ import static org.mockito.Mockito.reset; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.hamcrest.MockitoHamcrest.argThat; import java.math.BigDecimal; @@ -26,6 +26,7 @@ import org.assertj.core.matcher.AssertionMatcher; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.knowm.xchange.dto.marketdata.OrderBook; import org.knowm.xchange.dto.trade.LimitOrder; import org.knowm.xchange.dto.trade.MarketOrder; @@ -35,8 +36,9 @@ import org.mockito.Captor; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; +@RunWith(MockitoJUnitRunner.class) public class TestMatchingEngine { private static final String MAKER = "MAKER"; @@ -51,7 +53,6 @@ public class TestMatchingEngine { @Before public void setup() { - MockitoAnnotations.initMocks(this); Mockito.when(accountFactory.get(Mockito.anyString())).thenReturn(account); matchingEngine = new MatchingEngine(accountFactory, BTC_USD, 2, new BigDecimal("0.001"), onFill); @@ -131,7 +132,7 @@ public void testAskNoMatch() { // Then assertThat(result.getId()).isNotNull(); assertThat(result.getStatus()).isEqualTo(NEW); - verifyZeroInteractions(onFill); + verifyNoInteractions(onFill); verify(account, never()).fill(any(UserTrade.class), any(Boolean.class)); verify(account, times(1)).reserve(any(LimitOrder.class)); verify(account, never()).release(any(LimitOrder.class)); @@ -155,7 +156,7 @@ public void testBidNoMatch() { // Then assertThat(result.getId()).isNotNull(); assertThat(result.getStatus()).isEqualTo(NEW); - verifyZeroInteractions(onFill); + verifyNoInteractions(onFill); verify(account, never()).fill(any(UserTrade.class), any(Boolean.class)); verify(account, times(1)).reserve(any(LimitOrder.class)); verify(account, never()).release(any(LimitOrder.class)); diff --git a/xchange-stream-bitfinex/src/test/java/info/bitrich/xchangestream/bitfinex/BitfinexStreamingServiceTest.java b/xchange-stream-bitfinex/src/test/java/info/bitrich/xchangestream/bitfinex/BitfinexStreamingServiceTest.java index 9be00430d6e..76766f024bc 100644 --- a/xchange-stream-bitfinex/src/test/java/info/bitrich/xchangestream/bitfinex/BitfinexStreamingServiceTest.java +++ b/xchange-stream-bitfinex/src/test/java/info/bitrich/xchangestream/bitfinex/BitfinexStreamingServiceTest.java @@ -13,21 +13,15 @@ import java.math.BigDecimal; import org.junit.Before; import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import si.mazi.rescu.SynchronizedValueFactory; public class BitfinexStreamingServiceTest { private BitfinexStreamingService service; private final ObjectMapper objectMapper = new ObjectMapper(); - @Mock SynchronizedValueFactory nonceFactory; - @Before public void setUp() { - MockitoAnnotations.initMocks(this); - service = new BitfinexStreamingService(BitfinexStreamingExchange.API_URI, nonceFactory); + service = new BitfinexStreamingService(BitfinexStreamingExchange.API_URI, null); } @Test @@ -132,8 +126,8 @@ public void testGetBalances() throws Exception { "exchange", "USD", new BigDecimal("69.4747619"), BigDecimal.ZERO, null); test.assertNoErrors(); test.assertValueCount(2); - assertThat(test.values().contains(expected)); - assertThat(test.values().contains(expected1)); + assertThat(test.values()).contains(expected); + assertThat(test.values()).contains(expected1); } @Test diff --git a/xchange-stream-bitstamp/src/test/java/info/bitrich/xchangestream/bitstamp/BitstampStreamingMarketDataServiceV2Test.java b/xchange-stream-bitstamp/src/test/java/info/bitrich/xchangestream/bitstamp/BitstampStreamingMarketDataServiceV2Test.java index 7317c5841df..eea37c6f291 100644 --- a/xchange-stream-bitstamp/src/test/java/info/bitrich/xchangestream/bitstamp/BitstampStreamingMarketDataServiceV2Test.java +++ b/xchange-stream-bitstamp/src/test/java/info/bitrich/xchangestream/bitstamp/BitstampStreamingMarketDataServiceV2Test.java @@ -15,6 +15,7 @@ import java.util.function.Supplier; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.knowm.xchange.currency.CurrencyPair; import org.knowm.xchange.dto.Order; import org.knowm.xchange.dto.marketdata.OrderBook; @@ -22,16 +23,18 @@ import org.knowm.xchange.dto.marketdata.Trade; import org.knowm.xchange.dto.trade.LimitOrder; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public class BitstampStreamingMarketDataServiceV2Test extends BitstampStreamingMarketDataServiceBaseTest { + + @Mock + private BitstampStreamingService streamingService; -public class BitstampStreamingMarketDataServiceV2Test - extends BitstampStreamingMarketDataServiceBaseTest { - @Mock private BitstampStreamingService streamingService; private BitstampStreamingMarketDataService marketDataService; @Before public void setUp() { - MockitoAnnotations.initMocks(this); marketDataService = new BitstampStreamingMarketDataService(streamingService); } diff --git a/xchange-stream-coinmate/src/test/java/info/bitrich/xchangestream/coinmate/v2/CoinmateStreamingMarketDataServiceTest.java b/xchange-stream-coinmate/src/test/java/info/bitrich/xchangestream/coinmate/v2/CoinmateStreamingMarketDataServiceTest.java index 994d5f50940..b56771095c5 100644 --- a/xchange-stream-coinmate/src/test/java/info/bitrich/xchangestream/coinmate/v2/CoinmateStreamingMarketDataServiceTest.java +++ b/xchange-stream-coinmate/src/test/java/info/bitrich/xchangestream/coinmate/v2/CoinmateStreamingMarketDataServiceTest.java @@ -14,24 +14,15 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; -import org.junit.Before; import org.junit.Test; import org.knowm.xchange.currency.CurrencyPair; import org.knowm.xchange.dto.Order; import org.knowm.xchange.dto.marketdata.OrderBook; import org.knowm.xchange.dto.marketdata.Trade; import org.knowm.xchange.dto.trade.LimitOrder; -import org.mockito.MockitoAnnotations; public class CoinmateStreamingMarketDataServiceTest { - private CoinmateStreamingMarketDataService marketDataService; - - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - } - @Test public void testGetOrderBook() throws Exception { ObjectMapper mapper = new ObjectMapper();