mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 01:41:11 +01:00
Generify remaining raw types used by the DAO packages
Fix raw usage of the following types, all of which (apart from Comparator) touch the DAO packages somewhere: Comparable, Comparator, GetStateHashesResponse, NewStateHashMessage, RequestStateHashesHandler, PersistenceManager (Also replace 'Integer.valueOf' with the non-boxing but otherwise identical method 'Integer.parseInt', in the class 'TxOutputKey'.)
This commit is contained in:
parent
e1a8424f12
commit
c94fa98417
@ -45,7 +45,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@Slf4j
|
||||
abstract class RequestStateHashesHandler<Req extends GetStateHashesRequest, Res extends GetStateHashesResponse> implements MessageListener {
|
||||
abstract class RequestStateHashesHandler<Req extends GetStateHashesRequest, Res extends GetStateHashesResponse<?>> implements MessageListener {
|
||||
private static final long TIMEOUT = 180;
|
||||
|
||||
|
||||
@ -53,7 +53,7 @@ abstract class RequestStateHashesHandler<Req extends GetStateHashesRequest, Res
|
||||
// Listener
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public interface Listener<Res extends GetStateHashesResponse> {
|
||||
public interface Listener<Res extends GetStateHashesResponse<?>> {
|
||||
void onComplete(Res getStateHashesResponse, Optional<NodeAddress> peersNodeAddress);
|
||||
|
||||
@SuppressWarnings("UnusedParameters")
|
||||
|
@ -53,13 +53,13 @@ import org.jetbrains.annotations.NotNull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@Slf4j
|
||||
public abstract class StateNetworkService<Msg extends NewStateHashMessage,
|
||||
public abstract class StateNetworkService<Msg extends NewStateHashMessage<StH>,
|
||||
Req extends GetStateHashesRequest,
|
||||
Res extends GetStateHashesResponse<StH>,
|
||||
Han extends RequestStateHashesHandler,
|
||||
Han extends RequestStateHashesHandler<Req, Res>,
|
||||
StH extends StateHash> implements MessageListener {
|
||||
|
||||
public interface Listener<Msg extends NewStateHashMessage, Req extends GetStateHashesRequest, StH extends StateHash> {
|
||||
public interface Listener<Msg extends NewStateHashMessage<StH>, Req extends GetStateHashesRequest, StH extends StateHash> {
|
||||
void onNewStateHashMessage(Msg newStateHashMessage, Connection connection);
|
||||
|
||||
void onGetStateHashRequest(Connection connection, Req getStateHashRequest);
|
||||
|
@ -31,7 +31,7 @@ import javax.annotation.concurrent.Immutable;
|
||||
*/
|
||||
@Immutable
|
||||
@Value
|
||||
public final class TxOutputKey implements ImmutableDaoStateModel, Comparable {
|
||||
public final class TxOutputKey implements ImmutableDaoStateModel, Comparable<Object> {
|
||||
private final String txId;
|
||||
private final int index;
|
||||
|
||||
@ -47,7 +47,7 @@ public final class TxOutputKey implements ImmutableDaoStateModel, Comparable {
|
||||
|
||||
public static TxOutputKey getKeyFromString(String keyAsString) {
|
||||
final String[] tokens = keyAsString.split(":");
|
||||
return new TxOutputKey(tokens[0], Integer.valueOf(tokens[1]));
|
||||
return new TxOutputKey(tokens[0], Integer.parseInt(tokens[1]));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -88,8 +88,8 @@ public class CurrencyUtil {
|
||||
return new ArrayList<>(fiatCurrencyMapSupplier.get().values());
|
||||
}
|
||||
|
||||
public static Collection<FiatCurrency> getAllSortedFiatCurrencies(Comparator comparator) {
|
||||
return (List<FiatCurrency>) getAllSortedFiatCurrencies().stream()
|
||||
public static Collection<FiatCurrency> getAllSortedFiatCurrencies(Comparator<? super FiatCurrency> comparator) {
|
||||
return getAllSortedFiatCurrencies().stream()
|
||||
.sorted(comparator) // sorted by comparator param
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
@ -11,20 +11,24 @@ import bisq.common.persistence.PersistenceManager;
|
||||
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class MyProposalListServiceTest {
|
||||
@Test
|
||||
public void canInstantiate() {
|
||||
public void canInstantiate(@Mock PersistenceManager<MyProposalList> persistenceManager) {
|
||||
P2PService p2PService = mock(P2PService.class);
|
||||
when(p2PService.getNumConnectedPeers()).thenReturn(new SimpleIntegerProperty(0));
|
||||
PersistenceManager persistenceManager = mock(PersistenceManager.class);
|
||||
MyProposalListService service = new MyProposalListService(p2PService,
|
||||
mock(DaoStateService.class),
|
||||
mock(PeriodService.class), mock(WalletsManager.class), persistenceManager, mock(PubKeyRing.class)
|
||||
|
||||
new MyProposalListService(p2PService, mock(DaoStateService.class), mock(PeriodService.class),
|
||||
mock(WalletsManager.class), persistenceManager, mock(PubKeyRing.class)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -35,8 +35,14 @@ import java.util.Currency;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
@ -44,10 +50,12 @@ import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT) // FIXME: Broken tests: stale persistenceManager stubbing
|
||||
public class PreferencesTest {
|
||||
|
||||
private Preferences preferences;
|
||||
private PersistenceManager persistenceManager;
|
||||
@Mock
|
||||
private PersistenceManager<PreferencesPayload> persistenceManager;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
@ -57,7 +65,6 @@ public class PreferencesTest {
|
||||
Res.setBaseCurrencyCode("BTC");
|
||||
Res.setBaseCurrencyName("Bitcoin");
|
||||
|
||||
persistenceManager = mock(PersistenceManager.class);
|
||||
Config config = new Config();
|
||||
LocalBitcoinNode localBitcoinNode = new LocalBitcoinNode(config);
|
||||
preferences = new Preferences(
|
||||
@ -114,9 +121,7 @@ public class PreferencesTest {
|
||||
when(payload.getPreferredTradeCurrency()).thenReturn(new FiatCurrency("USD"));
|
||||
when(payload.getCryptoCurrencies()).thenReturn(cryptoCurrencies);
|
||||
|
||||
preferences.readPersisted(() -> {
|
||||
assertTrue(preferences.getCryptoCurrenciesAsObservable().contains(dash));
|
||||
});
|
||||
preferences.readPersisted(() -> assertTrue(preferences.getCryptoCurrenciesAsObservable().contains(dash)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -135,8 +140,7 @@ public class PreferencesTest {
|
||||
when(payload.getPreferredTradeCurrency()).thenReturn(usd);
|
||||
when(payload.getFiatCurrencies()).thenReturn(fiatCurrencies);
|
||||
|
||||
preferences.readPersisted(() -> {
|
||||
assertEquals("US Dollar (USD)", preferences.getFiatCurrenciesAsObservable().get(0).getNameAndCode());
|
||||
});
|
||||
preferences.readPersisted(() ->
|
||||
assertEquals("US Dollar (USD)", preferences.getFiatCurrenciesAsObservable().get(0).getNameAndCode()));
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ package bisq.desktop.maker;
|
||||
import bisq.core.btc.nodes.LocalBitcoinNode;
|
||||
import bisq.core.provider.fee.FeeService;
|
||||
import bisq.core.user.Preferences;
|
||||
import bisq.core.user.PreferencesPayload;
|
||||
|
||||
import bisq.common.config.Config;
|
||||
import bisq.common.persistence.PersistenceManager;
|
||||
@ -32,8 +33,7 @@ import static com.natpryce.makeiteasy.MakeItEasy.a;
|
||||
import static com.natpryce.makeiteasy.MakeItEasy.make;
|
||||
|
||||
public class PreferenceMakers {
|
||||
|
||||
public static final Property<Preferences, PersistenceManager> storage = new Property<>();
|
||||
public static final Property<Preferences, PersistenceManager<PreferencesPayload>> storage = new Property<>();
|
||||
public static final Property<Preferences, Config> config = new Property<>();
|
||||
public static final Property<Preferences, FeeService> feeService = new Property<>();
|
||||
public static final Property<Preferences, LocalBitcoinNode> localBitcoinNode = new Property<>();
|
||||
@ -41,14 +41,13 @@ public class PreferenceMakers {
|
||||
public static final Property<Preferences, String> referralID = new Property<>();
|
||||
|
||||
public static final Instantiator<Preferences> Preferences = lookup -> new Preferences(
|
||||
lookup.valueOf(storage, new SameValueDonor<PersistenceManager>(null)),
|
||||
lookup.valueOf(config, new SameValueDonor<Config>(null)),
|
||||
lookup.valueOf(feeService, new SameValueDonor<FeeService>(null)),
|
||||
lookup.valueOf(localBitcoinNode, new SameValueDonor<LocalBitcoinNode>(null)),
|
||||
lookup.valueOf(useTorFlagFromOptions, new SameValueDonor<String>(null)),
|
||||
lookup.valueOf(referralID, new SameValueDonor<String>(null)),
|
||||
lookup.valueOf(storage, new SameValueDonor<>(null)),
|
||||
lookup.valueOf(config, new SameValueDonor<>(null)),
|
||||
lookup.valueOf(feeService, new SameValueDonor<>(null)),
|
||||
lookup.valueOf(localBitcoinNode, new SameValueDonor<>(null)),
|
||||
lookup.valueOf(useTorFlagFromOptions, new SameValueDonor<>(null)),
|
||||
lookup.valueOf(referralID, new SameValueDonor<>(null)),
|
||||
Config.DEFAULT_FULL_DAO_NODE, false, null, null, Config.UNSPECIFIED_PORT);
|
||||
|
||||
public static final Preferences empty = make(a(Preferences));
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user