fix junit test failures for subprojects

Co-authored-by: woodser <woodser@protonmail.com>
This commit is contained in:
napoly 2023-08-11 16:21:53 +02:00 committed by woodser
parent 4ca5974493
commit 3b89212c6f
9 changed files with 37 additions and 53 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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