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:
Steven Barclay 2024-03-09 01:26:36 +08:00
parent e1a8424f12
commit c94fa98417
No known key found for this signature in database
GPG Key ID: 9FED6BF1176D500B
7 changed files with 39 additions and 32 deletions

View File

@ -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")

View File

@ -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);

View File

@ -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

View File

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

View File

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

View File

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

View File

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