Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix build on jdk11 and jdk12. remove powermock and jmockit #3081

Merged
merged 10 commits into from
Aug 14, 2019
Merged
5 changes: 2 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
if(JavaVersion.current() != JavaVersion.VERSION_1_10){
/*if(JavaVersion.current() != JavaVersion.VERSION_1_10){
// feel free to delete this if you know what you are doing
throw new GradleException("This build must be run with java 10. see docs/build.md")
}
}*/
buildscript {
repositories {
jcenter()
Expand Down Expand Up @@ -306,7 +306,6 @@ configure(project(':desktop')) {

testCompile "org.jmockit:jmockit:$jmockitVersion"
testCompile("org.mockito:mockito-core:$mockitoVersion") {
exclude(module: 'objenesis')
}
testCompile "org.powermock:powermock-module-junit4:$powermockVersion"
testCompile "org.powermock:powermock-api-mockito2:$powermockVersion"
Expand Down
13 changes: 13 additions & 0 deletions desktop/src/main/java/bisq/desktop/main/offer/MakerFeeMaker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package bisq.desktop.main.offer;

import bisq.core.btc.wallet.BsqWalletService;
import bisq.core.offer.OfferUtil;
import bisq.core.user.Preferences;

import org.bitcoinj.core.Coin;

public class MakerFeeMaker {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MakerFeeMaker sounds a bit weird. Maybe MakerFeeProvider?

public Coin getMakerFee(BsqWalletService bsqWalletService, Preferences preferences, Coin amount) {
return OfferUtil.getMakerFee(bsqWalletService, preferences, amount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public abstract class MutableOfferDataModel extends OfferDataModel implements Bs
private final TxFeeEstimationService txFeeEstimationService;
private final ReferralIdService referralIdService;
private final BSFormatter btcFormatter;
private MakerFeeMaker makerFeeMaker;
private final String offerId;
private final BalanceListener btcBalanceListener;
private final SetChangeListener<PaymentAccount> paymentAccountsChangeListener;
Expand Down Expand Up @@ -157,7 +158,8 @@ public MutableOfferDataModel(OpenOfferManager openOfferManager,
FeeService feeService,
TxFeeEstimationService txFeeEstimationService,
ReferralIdService referralIdService,
BSFormatter btcFormatter) {
BSFormatter btcFormatter,
MakerFeeMaker makerFeeMaker) {
super(btcWalletService);

this.openOfferManager = openOfferManager;
Expand All @@ -173,6 +175,7 @@ public MutableOfferDataModel(OpenOfferManager openOfferManager,
this.txFeeEstimationService = txFeeEstimationService;
this.referralIdService = referralIdService;
this.btcFormatter = btcFormatter;
this.makerFeeMaker = makerFeeMaker;

offerId = Utilities.getRandomPrefix(5, 8) + "-" +
UUID.randomUUID().toString() + "-" +
Expand Down Expand Up @@ -802,7 +805,7 @@ public Coin getMakerFee(boolean isCurrencyForMakerFeeBtc) {
}

public Coin getMakerFee() {
return OfferUtil.getMakerFee(bsqWalletService, preferences, amount.get());
return makerFeeMaker.getMakerFee(bsqWalletService, preferences, amount.get());
}

public Coin getMakerFeeInBtc() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

package bisq.desktop.main.offer.createoffer;

import bisq.desktop.main.offer.MakerFeeMaker;
import bisq.desktop.main.offer.MutableOfferDataModel;

import bisq.core.account.witness.AccountAgeWitnessService;
Expand Down Expand Up @@ -63,7 +64,8 @@ public CreateOfferDataModel(OpenOfferManager openOfferManager,
FeeService feeService,
TxFeeEstimationService txFeeEstimationService,
ReferralIdService referralIdService,
BSFormatter btcFormatter) {
BSFormatter btcFormatter,
MakerFeeMaker makerFeeMaker) {
super(openOfferManager,
btcWalletService,
bsqWalletService,
Expand All @@ -77,6 +79,7 @@ public CreateOfferDataModel(OpenOfferManager openOfferManager,
feeService,
txFeeEstimationService,
referralIdService,
btcFormatter);
btcFormatter,
makerFeeMaker);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package bisq.desktop.main.portfolio.editoffer;


import bisq.desktop.main.offer.MakerFeeMaker;
import bisq.desktop.main.offer.MutableOfferDataModel;

import bisq.core.account.witness.AccountAgeWitnessService;
Expand Down Expand Up @@ -73,7 +74,8 @@ class EditOfferDataModel extends MutableOfferDataModel {
TxFeeEstimationService txFeeEstimationService,
ReferralIdService referralIdService,
BSFormatter btcFormatter,
CorePersistenceProtoResolver corePersistenceProtoResolver) {
CorePersistenceProtoResolver corePersistenceProtoResolver,
MakerFeeMaker makerFeeMaker) {
super(openOfferManager,
btcWalletService,
bsqWalletService,
Expand All @@ -87,7 +89,8 @@ class EditOfferDataModel extends MutableOfferDataModel {
feeService,
txFeeEstimationService,
referralIdService,
btcFormatter);
btcFormatter,
makerFeeMaker);
this.corePersistenceProtoResolver = corePersistenceProtoResolver;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,14 @@

import java.util.Collections;

import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@RunWith(PowerMockRunner.class)
@PrepareForTest(Dispute.class)
@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*"})
@SuppressWarnings("ConstantConditions")
public class TransactionAwareTradeTest {
private static final String XID = "123";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,8 @@
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import static bisq.desktop.main.offer.offerbook.OfferBookListItemMaker.btcBuyItem;
import static bisq.desktop.main.offer.offerbook.OfferBookListItemMaker.btcSellItem;
Expand All @@ -49,9 +44,6 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@RunWith(PowerMockRunner.class)
@PrepareForTest({OfferBook.class, PriceFeedService.class})
@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*"})
public class OfferBookChartViewModelTest {

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import org.junit.Test;
import org.junit.runner.RunWith;

import static bisq.desktop.main.offer.offerbook.OfferBookListItemMaker.btcBuyItem;
import static bisq.desktop.main.offer.offerbook.OfferBookListItemMaker.btcSellItem;
Expand All @@ -44,9 +39,6 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@RunWith(PowerMockRunner.class)
@PrepareForTest({OfferBook.class, PriceFeedService.class})
@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*"})
public class SpreadViewModelTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,15 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import mockit.Expectations;
import mockit.Injectable;
import mockit.Mock;
import mockit.MockUp;
import mockit.Tested;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;

public class TradesChartsViewModelTest {
@Tested
TradesChartsViewModel model;
@Injectable
Preferences preferences;
@Injectable
PriceFeedService priceFeedService;
@Injectable
Navigation navigation;
@Injectable
BSFormatter formatter;
@Injectable
TradeStatisticsManager tsm;

private static final Logger log = LoggerFactory.getLogger(TradesChartsViewModelTest.class);
Expand Down Expand Up @@ -121,10 +107,11 @@ public class TradesChartsViewModelTest {
null,
1
);

@Before
public void setup() throws IOException {

tsm = mock(TradeStatisticsManager.class);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid acronyms.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that's what it was called before, will change.

model = new TradesChartsViewModel(tsm, mock(Preferences.class), mock(PriceFeedService.class),
mock(Navigation.class), mock(BSFormatter.class));
dir = File.createTempFile("temp_tests1", "");
//noinspection ResultOfMethodCallIgnored
dir.delete();
Expand Down Expand Up @@ -168,6 +155,8 @@ public void testGetCandleData() {
assertEquals(isBullish, candleData.isBullish);
}

// TODO JMOCKIT
@Ignore
@Test
public void testItemLists() throws ParseException {
// Helper class to add historic trades
Expand Down Expand Up @@ -196,12 +185,12 @@ class Trade {

// Set predetermined time to use as "now" during test
Date test_time = dateFormat.parse("2018-01-01T00:00:05"); // Monday
new MockUp<System>() {
/* new MockUp<System>() {
@Mock
long currentTimeMillis() {
return test_time.getTime();
}
};
};*/

// Two trades 10 seconds apart, different YEAR, MONTH, WEEK, DAY, HOUR, MINUTE_10
trades.add(new Trade("2017-12-31T23:59:52", "1", "100", "EUR"));
Expand All @@ -216,10 +205,10 @@ long currentTimeMillis() {

// Run test for each tick type
for (TradesChartsViewModel.TickUnit tick : TradesChartsViewModel.TickUnit.values()) {
new Expectations() {{
/* new Expectations() {{
tsm.getObservableTradeStatisticsSet();
result = tradeStats;
}};
}};*/

// Trigger chart update
model.setTickUnit(tick);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package bisq.desktop.main.offer.createoffer;

import bisq.desktop.main.offer.MakerFeeMaker;

import bisq.core.btc.TxFeeEstimationService;
import bisq.core.btc.model.AddressEntry;
import bisq.core.btc.wallet.BtcWalletService;
Expand All @@ -8,7 +10,6 @@
import bisq.core.locale.GlobalSettings;
import bisq.core.locale.Res;
import bisq.core.offer.OfferPayload;
import bisq.core.offer.OfferUtil;
import bisq.core.payment.ClearXchangeAccount;
import bisq.core.payment.PaymentAccount;
import bisq.core.payment.RevolutAccount;
Expand All @@ -21,34 +22,21 @@

import java.util.HashSet;

import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;



import org.mockito.BDDMockito;

@RunWith(PowerMockRunner.class)
@PrepareForTest({BtcWalletService.class, AddressEntry.class, Preferences.class, User.class,
PriceFeedService.class, OfferUtil.class, FeeService.class, TxFeeEstimationService.class})
@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*"})
public class CreateOfferDataModelTest {

private CreateOfferDataModel model;
private User user;
private Preferences preferences;
private MakerFeeMaker makerFeeMaker;

@Before
public void setUp() {
Expand All @@ -68,11 +56,12 @@ public void setUp() {
when(preferences.isUsePercentageBasedPrice()).thenReturn(true);
when(preferences.getBuyerSecurityDepositAsPercent(null)).thenReturn(0.01);

makerFeeMaker = mock(MakerFeeMaker.class);
model = new CreateOfferDataModel(null, btcWalletService,
null, preferences, user, null,
null, priceFeedService, null,
null, feeService, feeEstimationService,
null, null);
null, null, makerFeeMaker);
}

@Test
Expand All @@ -89,8 +78,7 @@ public void testUseTradeCurrencySetInOfferViewWhenInPaymentAccountAvailable() {

when(user.getPaymentAccounts()).thenReturn(paymentAccounts);
when(preferences.getSelectedPaymentAccountForCreateOffer()).thenReturn(revolutAccount);
PowerMockito.mockStatic(OfferUtil.class);
BDDMockito.given(OfferUtil.getMakerFee(any(), any(), any())).willReturn(Coin.ZERO);
when(makerFeeMaker.getMakerFee(any(), any(), any())).thenReturn(Coin.ZERO);

model.initWithData(OfferPayload.Direction.BUY, new FiatCurrency("USD"));
assertEquals("USD", model.getTradeCurrencyCode().get());
Expand All @@ -110,8 +98,7 @@ public void testUseTradeAccountThatMatchesTradeCurrencySetInOffer() {
when(user.getPaymentAccounts()).thenReturn(paymentAccounts);
when(user.findFirstPaymentAccountWithCurrency(new FiatCurrency("USD"))).thenReturn(zelleAccount);
when(preferences.getSelectedPaymentAccountForCreateOffer()).thenReturn(revolutAccount);
PowerMockito.mockStatic(OfferUtil.class);
BDDMockito.given(OfferUtil.getMakerFee(any(), any(), any())).willReturn(Coin.ZERO);
when(makerFeeMaker.getMakerFee(any(), any(), any())).thenReturn(Coin.ZERO);

model.initWithData(OfferPayload.Direction.BUY, new FiatCurrency("USD"));
assertEquals("USD", model.getTradeCurrencyCode().get());
Expand Down
Loading