From 3b89212c6fb6f42bdc55c282541a90fcf1aed84d Mon Sep 17 00:00:00 2001 From: napoly Date: Fri, 11 Aug 2023 16:21:53 +0200 Subject: [PATCH] fix junit test failures for subprojects Co-authored-by: woodser --- build.gradle | 16 +++-------- .../java/haveno/core/monetary/PriceTest.java | 27 +++++++------------ .../core/offer/OpenOfferManagerTest.java | 2 ++ .../TransactionAwareTradeTest.java | 6 ++--- .../OfferBookChartViewModelTest.java | 8 +++--- .../trades/TradesChartsViewModelTest.java | 11 ++++---- .../createoffer/CreateOfferViewModelTest.java | 2 +- .../offerbook/OfferBookListItemMaker.java | 9 +++---- .../offerbook/OfferBookViewModelTest.java | 9 +++---- 9 files changed, 37 insertions(+), 53 deletions(-) diff --git a/build.gradle b/build.gradle index 91a44e875a..cf5c47a339 100644 --- a/build.gradle +++ b/build.gradle @@ -118,6 +118,10 @@ configure(subprojects) { } } } + + test { + useJUnitPlatform() + } } configure([project(':cli'), @@ -570,10 +574,6 @@ configure(project(':cli')) { testRuntimeOnly "javax.annotation:javax.annotation-api:$javaxAnnotationVersion" testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$jupiterVersion" } - - test { - useJUnitPlatform() - } } configure(project(':desktop')) { @@ -664,13 +664,6 @@ configure(project(':desktop')) { configure(project(':monitor')) { mainClassName = 'haveno.monitor.Monitor' - test { - useJUnitPlatform() - testLogging { - events "passed", "skipped", "failed" - } - } - dependencies { implementation project(':assets') implementation project(':common') @@ -856,7 +849,6 @@ configure(project(':apitest')) { test.enabled = System.getProperty("runApiTests") == "true" test { - useJUnitPlatform() outputs.upToDateWhen { false } // Don't use previously cached test outputs. testLogging { showStackTraces = true // Show full stack traces in the console. diff --git a/core/src/test/java/haveno/core/monetary/PriceTest.java b/core/src/test/java/haveno/core/monetary/PriceTest.java index ffa65c6e2d..efaf995396 100644 --- a/core/src/test/java/haveno/core/monetary/PriceTest.java +++ b/core/src/test/java/haveno/core/monetary/PriceTest.java @@ -28,30 +28,23 @@ public class PriceTest { @Test public void testParse() { - Price result = parse("USD", "0.1"); assertEquals( "0.10 XMR/USD", - result.toFriendlyString(), + parse("USD", "0.1").toFriendlyString(), "Fiat value should be formatted with two decimals." ); - result = parse("EUR", "0.1234"); assertEquals( "0.1234 XMR/EUR", - result.toFriendlyString(), + parse("EUR", "0.1234").toFriendlyString(), "Fiat value should be given two decimals" ); - try { - parse("EUR", "0.12345"); - fail("Expected IllegalArgumentException to be thrown when too many decimals are used."); - } catch (IllegalArgumentException iae) { - assertEquals( - "java.lang.ArithmeticException: Rounding necessary", - iae.getMessage(), - "Unexpected exception message." - ); - } + assertEquals( + "0.1235 XMR/EUR", + parse("EUR", "0.12345").toFriendlyString(), + "Too many decimals of fiat value should get rounded up properly." + ); assertEquals( -100000000L, @@ -96,17 +89,15 @@ public class PriceTest { } @Test public void testValueOf() { - Price result = valueOf("USD", 1); assertEquals( "0.0001 XMR/USD", - result.toFriendlyString(), + valueOf("USD", 10000).toFriendlyString(), "Fiat value should have four decimals." ); - result = valueOf("EUR", 1234); assertEquals( "0.1234 XMR/EUR", - result.toFriendlyString(), + valueOf("EUR", 12340000).toFriendlyString(), "Fiat value should be given two decimals" ); diff --git a/core/src/test/java/haveno/core/offer/OpenOfferManagerTest.java b/core/src/test/java/haveno/core/offer/OpenOfferManagerTest.java index 26b85d93e3..16cce99cf8 100644 --- a/core/src/test/java/haveno/core/offer/OpenOfferManagerTest.java +++ b/core/src/test/java/haveno/core/offer/OpenOfferManagerTest.java @@ -13,6 +13,7 @@ import haveno.network.p2p.P2PService; import haveno.network.p2p.peers.PeerManager; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import java.nio.file.Files; @@ -50,6 +51,7 @@ public class OpenOfferManagerTest { } @Test + @Disabled // TODO: re-enable when editing offers supported public void testStartEditOfferForActiveOffer() { P2PService p2PService = mock(P2PService.class); OfferBookService offerBookService = mock(OfferBookService.class); diff --git a/desktop/src/test/java/haveno/desktop/main/funds/transactions/TransactionAwareTradeTest.java b/desktop/src/test/java/haveno/desktop/main/funds/transactions/TransactionAwareTradeTest.java index 2189399904..c5fe439f91 100644 --- a/desktop/src/test/java/haveno/desktop/main/funds/transactions/TransactionAwareTradeTest.java +++ b/desktop/src/test/java/haveno/desktop/main/funds/transactions/TransactionAwareTradeTest.java @@ -59,19 +59,19 @@ public class TransactionAwareTradeTest { @Test public void testIsRelatedToTransactionWhenPayoutTx() { - when(delegate.getPayoutTx().getHash()).thenReturn(XID.toString()); + when(delegate.getPayoutTxId()).thenReturn(XID.toString()); assertTrue(trade.isRelatedToTransaction(transaction)); } @Test public void testIsRelatedToTransactionWhenMakerDepositTx() { - when(delegate.getMakerDepositTx().getHash()).thenReturn(XID.toString()); + when(delegate.getMaker().getDepositTxHash()).thenReturn(XID.toString()); assertTrue(trade.isRelatedToTransaction(transaction)); } @Test public void testIsRelatedToTransactionWhenTakerDepositTx() { - when(delegate.getTakerDepositTx().getHash()).thenReturn(XID.toString()); + when(delegate.getTaker().getDepositTxHash()).thenReturn(XID.toString()); assertTrue(trade.isRelatedToTransaction(transaction)); } diff --git a/desktop/src/test/java/haveno/desktop/main/market/offerbook/OfferBookChartViewModelTest.java b/desktop/src/test/java/haveno/desktop/main/market/offerbook/OfferBookChartViewModelTest.java index ef7fbfb6a6..3d3411d168 100644 --- a/desktop/src/test/java/haveno/desktop/main/market/offerbook/OfferBookChartViewModelTest.java +++ b/desktop/src/test/java/haveno/desktop/main/market/offerbook/OfferBookChartViewModelTest.java @@ -89,9 +89,9 @@ public class OfferBookChartViewModelTest { final OfferBookChartViewModel model = new OfferBookChartViewModel(offerBook, null, empty, service, null, null); model.activate(); assertEquals(7, model.maxPlacesForBuyPrice.intValue()); - offerBookListItems.addAll(make(xmrBuyItem.but(with(OfferBookListItemMaker.price, 94016475L)))); + offerBookListItems.addAll(make(xmrBuyItem.but(with(OfferBookListItemMaker.price, 940164750000L)))); assertEquals(9, model.maxPlacesForBuyPrice.intValue()); // 9401.6475 - offerBookListItems.addAll(make(xmrBuyItem.but(with(OfferBookListItemMaker.price, 101016475L)))); + offerBookListItems.addAll(make(xmrBuyItem.but(with(OfferBookListItemMaker.price, 1010164750000L)))); assertEquals(10, model.maxPlacesForBuyPrice.intValue()); //10101.6475 } @@ -167,9 +167,9 @@ public class OfferBookChartViewModelTest { final OfferBookChartViewModel model = new OfferBookChartViewModel(offerBook, null, empty, service, null, null); model.activate(); assertEquals(7, model.maxPlacesForSellPrice.intValue()); // 10.0000 default price - offerBookListItems.addAll(make(xmrSellItem.but(with(OfferBookListItemMaker.price, 94016475L)))); + offerBookListItems.addAll(make(xmrSellItem.but(with(OfferBookListItemMaker.price, 940164750000L)))); assertEquals(9, model.maxPlacesForSellPrice.intValue()); // 9401.6475 - offerBookListItems.addAll(make(xmrSellItem.but(with(OfferBookListItemMaker.price, 101016475L)))); + offerBookListItems.addAll(make(xmrSellItem.but(with(OfferBookListItemMaker.price, 1010164750000L)))); assertEquals(10, model.maxPlacesForSellPrice.intValue()); // 10101.6475 } diff --git a/desktop/src/test/java/haveno/desktop/main/market/trades/TradesChartsViewModelTest.java b/desktop/src/test/java/haveno/desktop/main/market/trades/TradesChartsViewModelTest.java index fc9e7fcfbb..84bfd2dfa4 100644 --- a/desktop/src/test/java/haveno/desktop/main/market/trades/TradesChartsViewModelTest.java +++ b/desktop/src/test/java/haveno/desktop/main/market/trades/TradesChartsViewModelTest.java @@ -23,6 +23,7 @@ import haveno.core.monetary.TraditionalMoney; import haveno.core.offer.OfferPayload; import haveno.core.payment.payload.PaymentMethod; import haveno.core.provider.price.PriceFeedService; +import haveno.core.trade.HavenoUtils; import haveno.core.trade.statistics.TradeStatistics3; import haveno.core.trade.statistics.TradeStatisticsManager; import haveno.core.user.Preferences; @@ -118,7 +119,7 @@ public class TradesChartsViewModelTest { long high = TraditionalMoney.parseTraditionalMoney("EUR", "600").value; long average = TraditionalMoney.parseTraditionalMoney("EUR", "550").value; long median = TraditionalMoney.parseTraditionalMoney("EUR", "550").value; - long amount = Coin.parseCoin("4").value; + long amount = HavenoUtils.xmrToAtomicUnits(4).longValue(); long volume = TraditionalMoney.parseTraditionalMoney("EUR", "2200").value; boolean isBullish = true; @@ -127,7 +128,7 @@ public class TradesChartsViewModelTest { set.add(new TradeStatistics3(offer.getCurrencyCode(), Price.parse("EUR", "520").getValue(), - Coin.parseCoin("1").getValue(), + HavenoUtils.xmrToAtomicUnits(1).longValue(), PaymentMethod.BLOCK_CHAINS_ID, now.getTime(), null, @@ -135,7 +136,7 @@ public class TradesChartsViewModelTest { null)); set.add(new TradeStatistics3(offer.getCurrencyCode(), Price.parse("EUR", "500").getValue(), - Coin.parseCoin("1").getValue(), + HavenoUtils.xmrToAtomicUnits(1).longValue(), PaymentMethod.BLOCK_CHAINS_ID, now.getTime() + 100, null, @@ -143,7 +144,7 @@ public class TradesChartsViewModelTest { null)); set.add(new TradeStatistics3(offer.getCurrencyCode(), Price.parse("EUR", "600").getValue(), - Coin.parseCoin("1").getValue(), + HavenoUtils.xmrToAtomicUnits(1).longValue(), PaymentMethod.BLOCK_CHAINS_ID, now.getTime() + 200, null, @@ -151,7 +152,7 @@ public class TradesChartsViewModelTest { null)); set.add(new TradeStatistics3(offer.getCurrencyCode(), Price.parse("EUR", "580").getValue(), - Coin.parseCoin("1").getValue(), + HavenoUtils.xmrToAtomicUnits(1).longValue(), PaymentMethod.BLOCK_CHAINS_ID, now.getTime() + 300, null, diff --git a/desktop/src/test/java/haveno/desktop/main/offer/createoffer/CreateOfferViewModelTest.java b/desktop/src/test/java/haveno/desktop/main/offer/createoffer/CreateOfferViewModelTest.java index 784b2faaa5..afca58298f 100644 --- a/desktop/src/test/java/haveno/desktop/main/offer/createoffer/CreateOfferViewModelTest.java +++ b/desktop/src/test/java/haveno/desktop/main/offer/createoffer/CreateOfferViewModelTest.java @@ -96,7 +96,7 @@ public class CreateOfferViewModelTest { Instant.now().getEpochSecond(), true)); when(user.findFirstPaymentAccountWithCurrency(any())).thenReturn(paymentAccount); - when(paymentAccount.getPaymentMethod()).thenReturn(mock(PaymentMethod.class)); + when(paymentAccount.getPaymentMethod()).thenReturn(PaymentMethod.ZELLE); when(user.getPaymentAccountsAsObservable()).thenReturn(FXCollections.observableSet()); when(securityDepositValidator.validate(any())).thenReturn(new InputValidator.ValidationResult(false)); when(accountAgeWitnessService.getMyTradeLimit(any(), any(), any())).thenReturn(100000000L); diff --git a/desktop/src/test/java/haveno/desktop/main/offer/offerbook/OfferBookListItemMaker.java b/desktop/src/test/java/haveno/desktop/main/offer/offerbook/OfferBookListItemMaker.java index 60b565da58..0c59a1d78e 100644 --- a/desktop/src/test/java/haveno/desktop/main/offer/offerbook/OfferBookListItemMaker.java +++ b/desktop/src/test/java/haveno/desktop/main/offer/offerbook/OfferBookListItemMaker.java @@ -19,14 +19,13 @@ package haveno.desktop.main.offer.offerbook; import com.natpryce.makeiteasy.Instantiator; import com.natpryce.makeiteasy.MakeItEasy; +import static com.natpryce.makeiteasy.MakeItEasy.a; +import static com.natpryce.makeiteasy.MakeItEasy.make; +import static com.natpryce.makeiteasy.MakeItEasy.with; import com.natpryce.makeiteasy.Maker; import com.natpryce.makeiteasy.Property; import haveno.core.offer.OfferDirection; import haveno.desktop.maker.OfferMaker; - -import static com.natpryce.makeiteasy.MakeItEasy.a; -import static com.natpryce.makeiteasy.MakeItEasy.make; -import static com.natpryce.makeiteasy.MakeItEasy.with; import static haveno.desktop.maker.OfferMaker.xmrUsdOffer; public class OfferBookListItemMaker { @@ -43,7 +42,7 @@ public class OfferBookListItemMaker { public static final Instantiator OfferBookListItem = lookup -> new OfferBookListItem(make(xmrUsdOffer.but( - MakeItEasy.with(OfferMaker.price, lookup.valueOf(price, 100000L)), + with(OfferMaker.price, lookup.valueOf(price, 1000000000L)), with(OfferMaker.amount, lookup.valueOf(amount, 1000000000L)), with(OfferMaker.minAmount, lookup.valueOf(amount, 1000000000L)), with(OfferMaker.direction, lookup.valueOf(direction, OfferDirection.BUY)), diff --git a/desktop/src/test/java/haveno/desktop/main/offer/offerbook/OfferBookViewModelTest.java b/desktop/src/test/java/haveno/desktop/main/offer/offerbook/OfferBookViewModelTest.java index 21ef3b2fde..05b0887ace 100644 --- a/desktop/src/test/java/haveno/desktop/main/offer/offerbook/OfferBookViewModelTest.java +++ b/desktop/src/test/java/haveno/desktop/main/offer/offerbook/OfferBookViewModelTest.java @@ -329,10 +329,9 @@ public class OfferBookViewModelTest { model.activate(); assertEquals(9, model.maxPlacesForVolume.intValue()); - offerBookListItems.addAll(make(xmrItemWithRange.but(with(amount, 20000000000000L)))); + offerBookListItems.addAll(make(xmrItemWithRange.but(with(amount, 200000000000000000L)))); assertEquals(11, model.maxPlacesForVolume.intValue()); - offerBookListItems.addAll(make(xmrItemWithRange.but(with(minAmount, 300000000000000L), - with(amount, 300000000000000L)))); + offerBookListItems.addAll(make(xmrItemWithRange.but(with(minAmount, 3000000000000000000L), with(amount, 3000000000000000000L)))); assertEquals(19, model.maxPlacesForVolume.intValue()); } @@ -362,9 +361,9 @@ public class OfferBookViewModelTest { model.activate(); assertEquals(7, model.maxPlacesForPrice.intValue()); - offerBookListItems.addAll(make(xmrBuyItem.but(with(price, 149558240L)))); //14955.8240 + offerBookListItems.addAll(make(xmrBuyItem.but(with(price, 1495582400000L)))); //149558240 assertEquals(10, model.maxPlacesForPrice.intValue()); - offerBookListItems.addAll(make(xmrBuyItem.but(with(price, 14955824L)))); //1495.58240 + offerBookListItems.addAll(make(xmrBuyItem.but(with(price, 149558240000L)))); //149558240 assertEquals(10, model.maxPlacesForPrice.intValue()); }