Skip to content

Commit

Permalink
Merge pull request #4856 from bigscoop/remove-deprecated-calls
Browse files Browse the repository at this point in the history
[general] Remove calls to deprecated code
  • Loading branch information
timmolter authored Apr 29, 2024
2 parents d234f55 + 941347d commit 83b8e38
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand Down Expand Up @@ -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);
}

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

Expand Down Expand Up @@ -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);
}

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

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

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

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand Down Expand Up @@ -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);
}

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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";
Expand All @@ -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);
Expand Down Expand Up @@ -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));
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Long> nonceFactory;

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
service = new BitfinexStreamingService(BitfinexStreamingExchange.API_URI, nonceFactory);
service = new BitfinexStreamingService(BitfinexStreamingExchange.API_URI, null);
}

@Test
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,26 @@
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;
import org.knowm.xchange.dto.marketdata.Ticker;
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 83b8e38

Please sign in to comment.