From 20e011178e77f0ff85e6e7853a574ae6b3aea685 Mon Sep 17 00:00:00 2001 From: Christoph Sturm Date: Mon, 5 Aug 2019 11:03:10 +0200 Subject: [PATCH 1/4] bump guice version and start testing desktop guice setup --- build.gradle | 2 +- .../java/bisq/desktop/GuiceSetupTest.java | 24 +++++++++++++++++++ gradle/witness/gradle-witness.gradle | 1 - 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 desktop/src/test/java/bisq/desktop/GuiceSetupTest.java diff --git a/build.gradle b/build.gradle index 87fdf82e6e7..f73d232b33a 100644 --- a/build.gradle +++ b/build.gradle @@ -176,7 +176,7 @@ configure(project(':common')) { compile "ch.qos.logback:logback-classic:$logbackVersion" compile 'com.google.code.findbugs:jsr305:3.0.2' compile 'com.google.guava:guava:20.0' - compile('com.google.inject:guice:4.1.0') { + compile('com.google.inject:guice:4.2.2') { exclude(module: 'guava') } compile("com.github.bisq-network.bitcoinj:bitcoinj-core:$bitcoinjVersion") { diff --git a/desktop/src/test/java/bisq/desktop/GuiceSetupTest.java b/desktop/src/test/java/bisq/desktop/GuiceSetupTest.java new file mode 100644 index 00000000000..492ba3bdc2c --- /dev/null +++ b/desktop/src/test/java/bisq/desktop/GuiceSetupTest.java @@ -0,0 +1,24 @@ +package bisq.desktop; + +import bisq.desktop.app.BisqAppModule; +import bisq.desktop.common.view.CachingViewLoader; + +import bisq.core.app.AvoidStandbyModeService; +import bisq.core.app.BisqEnvironment; + +import org.springframework.mock.env.MockPropertySource; + +import com.google.inject.Guice; +import com.google.inject.Injector; + +import org.junit.Test; + +public class GuiceSetupTest { + @Test + public void testGuiceSetup() { + BisqAppModule module = new BisqAppModule(new BisqEnvironment(new MockPropertySource())); + Injector injector = Guice.createInjector(module); + injector.getInstance(CachingViewLoader.class); + injector.getInstance(AvoidStandbyModeService.class); + } +} diff --git a/gradle/witness/gradle-witness.gradle b/gradle/witness/gradle-witness.gradle index 29746adde8b..c94a094b289 100644 --- a/gradle/witness/gradle-witness.gradle +++ b/gradle/witness/gradle-witness.gradle @@ -42,7 +42,6 @@ dependencyVerification { 'ch.qos.logback:logback-core:4cd46fa17d77057b39160058df2f21ebbc2aded51d0edcc25d2c1cecc042a005', 'com.google.code.findbugs:jsr305:766ad2a0783f2687962c8ad74ceecc38a28b9f72a2d085ee438b7813e928d0c7', 'com.google.guava:guava:36a666e3b71ae7f0f0dca23654b67e086e6c93d192f60ba5dfd5519db6c288c8', - 'com.google.inject:guice:9b9df27a5b8c7864112b4137fd92b36c3f1395bfe57be42fedf2f520ead1a93e', 'com.github.bisq-network.bitcoinj:bitcoinj-core:f979c2187e61ee3b08dd4cbfc49a149734cff64c045d29ed112f2e12f34068a3', 'com.github.JesusMcCloud.netlayer:tor:35cf892e6ce3a8d942cfd2b589cfbde5aed31d49777aee873d6614e134df0b42', 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:193ab7813e4d249f2ea4fc1b968fea8c2126bcbeeb5d6127050ce1b93dbaa7c2', From aa4813d7b1e8a33626ac026b507c9fd58c3c2d9d Mon Sep 17 00:00:00 2001 From: Christoph Sturm Date: Tue, 6 Aug 2019 17:20:59 +0200 Subject: [PATCH 2/4] don't fail if there is no shutdown hook. --- desktop/src/main/java/bisq/desktop/main/overlays/Overlay.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/overlays/Overlay.java b/desktop/src/main/java/bisq/desktop/main/overlays/Overlay.java index 66f8548409b..2955e7c3b5c 100644 --- a/desktop/src/main/java/bisq/desktop/main/overlays/Overlay.java +++ b/desktop/src/main/java/bisq/desktop/main/overlays/Overlay.java @@ -173,7 +173,7 @@ protected enum Type { private HPos buttonAlignment = HPos.RIGHT; protected Optional closeHandlerOptional = Optional.empty(); - protected Optional actionHandlerOptional = Optional.empty(); + protected Optional actionHandlerOptional = Optional.empty(); protected Optional secondaryActionHandlerOptional = Optional.empty(); protected ChangeListener positionListener; @@ -438,7 +438,7 @@ public T secondaryActionButtonText(String secondaryActionButtonText) { public T useShutDownButton() { this.actionButtonText = Res.get("shared.shutDown"); - this.actionHandlerOptional = Optional.of(BisqApp.getShutDownHandler()); + this.actionHandlerOptional = Optional.ofNullable(BisqApp.getShutDownHandler()); //noinspection unchecked return (T) this; } From 643c0daef0f718e617c1fd090da0227129551f90 Mon Sep 17 00:00:00 2001 From: Christoph Sturm Date: Tue, 6 Aug 2019 17:24:36 +0200 Subject: [PATCH 3/4] use singleton annotation instead of binding as singleton. this is the correct way to do it. the way it is currently done means that if a component is not declared in a module, guice still finds it but does not use the singleton lifecycle binding as singleton in the module is meant to be used for classes that we don't have the sourcecode for (i.e. jdk classes) --- .../main/java/bisq/core/util/BSFormatter.java | 2 + .../java/bisq/core/util/BsqFormatter.java | 2 + .../main/java/bisq/desktop/DesktopModule.java | 36 ------------ .../main/java/bisq/desktop/Navigation.java | 3 + .../desktop/common/fxml/FxmlViewLoader.java | 2 + .../common/view/CachingViewLoader.java | 2 + .../view/guice/InjectorViewFactory.java | 3 + .../main/dao/bonding/BondingViewUtils.java | 2 + .../DisplayedTransactionsFactory.java | 2 + .../transactions/TradableRepository.java | 2 + .../TransactionAwareTradableFactory.java | 2 + .../TransactionListItemFactory.java | 2 + .../main/offer/offerbook/OfferBook.java | 2 + .../notifications/NotificationCenter.java | 3 + .../windows/TorNetworkSettingsWindow.java | 2 + .../main/presentation/DaoPresentation.java | 2 + .../presentation/MarketPricePresentation.java | 2 + .../java/bisq/desktop/util/Transitions.java | 2 + .../java/bisq/desktop/GuiceSetupTest.java | 55 ++++++++++++++++++- 19 files changed, 89 insertions(+), 39 deletions(-) diff --git a/core/src/main/java/bisq/core/util/BSFormatter.java b/core/src/main/java/bisq/core/util/BSFormatter.java index 9c49d7aaab5..ffe731b639d 100644 --- a/core/src/main/java/bisq/core/util/BSFormatter.java +++ b/core/src/main/java/bisq/core/util/BSFormatter.java @@ -38,6 +38,7 @@ import org.bitcoinj.utils.MonetaryFormat; import javax.inject.Inject; +import javax.inject.Singleton; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.time.DateUtils; @@ -59,6 +60,7 @@ import org.jetbrains.annotations.NotNull; @Slf4j +@Singleton public class BSFormatter { public final static String RANGE_SEPARATOR = " - "; diff --git a/core/src/main/java/bisq/core/util/BsqFormatter.java b/core/src/main/java/bisq/core/util/BsqFormatter.java index cba0117212e..7f2524598e0 100644 --- a/core/src/main/java/bisq/core/util/BsqFormatter.java +++ b/core/src/main/java/bisq/core/util/BsqFormatter.java @@ -35,6 +35,7 @@ import org.bitcoinj.utils.MonetaryFormat; import javax.inject.Inject; +import javax.inject.Singleton; import java.text.DecimalFormat; import java.text.NumberFormat; @@ -44,6 +45,7 @@ import lombok.extern.slf4j.Slf4j; @Slf4j +@Singleton public class BsqFormatter extends BSFormatter { @SuppressWarnings("PointlessBooleanExpression") private static final boolean useBsqAddressFormat = true || !DevEnv.isDevMode(); diff --git a/desktop/src/main/java/bisq/desktop/DesktopModule.java b/desktop/src/main/java/bisq/desktop/DesktopModule.java index 3d7b601c166..ce4124f3840 100644 --- a/desktop/src/main/java/bisq/desktop/DesktopModule.java +++ b/desktop/src/main/java/bisq/desktop/DesktopModule.java @@ -18,26 +18,12 @@ package bisq.desktop; import bisq.desktop.common.fxml.FxmlViewLoader; -import bisq.desktop.common.view.CachingViewLoader; import bisq.desktop.common.view.ViewFactory; import bisq.desktop.common.view.ViewLoader; import bisq.desktop.common.view.guice.InjectorViewFactory; -import bisq.desktop.main.dao.bonding.BondingViewUtils; -import bisq.desktop.main.funds.transactions.DisplayedTransactionsFactory; -import bisq.desktop.main.funds.transactions.TradableRepository; -import bisq.desktop.main.funds.transactions.TransactionAwareTradableFactory; -import bisq.desktop.main.funds.transactions.TransactionListItemFactory; -import bisq.desktop.main.offer.offerbook.OfferBook; -import bisq.desktop.main.overlays.notifications.NotificationCenter; -import bisq.desktop.main.overlays.windows.TorNetworkSettingsWindow; -import bisq.desktop.main.presentation.DaoPresentation; -import bisq.desktop.main.presentation.MarketPricePresentation; -import bisq.desktop.util.Transitions; import bisq.core.app.AppOptionKeys; import bisq.core.locale.Res; -import bisq.core.util.BSFormatter; -import bisq.core.util.BsqFormatter; import bisq.common.app.AppModule; @@ -57,32 +43,10 @@ public DesktopModule(Environment environment) { @Override protected void configure() { - bind(InjectorViewFactory.class).in(Singleton.class); bind(ViewFactory.class).to(InjectorViewFactory.class); - bind(CachingViewLoader.class).in(Singleton.class); bind(ResourceBundle.class).toInstance(Res.getResourceBundle()); bind(ViewLoader.class).to(FxmlViewLoader.class).in(Singleton.class); - bind(CachingViewLoader.class).in(Singleton.class); - - bind(Navigation.class).in(Singleton.class); - bind(NotificationCenter.class).in(Singleton.class); - - bind(OfferBook.class).in(Singleton.class); - bind(BSFormatter.class).in(Singleton.class); - bind(BsqFormatter.class).in(Singleton.class); - bind(TorNetworkSettingsWindow.class).in(Singleton.class); - bind(MarketPricePresentation.class).in(Singleton.class); - bind(DaoPresentation.class).in(Singleton.class); - - bind(Transitions.class).in(Singleton.class); - - bind(TradableRepository.class).in(Singleton.class); - bind(TransactionListItemFactory.class).in(Singleton.class); - bind(TransactionAwareTradableFactory.class).in(Singleton.class); - bind(DisplayedTransactionsFactory.class).in(Singleton.class); - - bind(BondingViewUtils.class).in(Singleton.class); bindConstant().annotatedWith(Names.named(AppOptionKeys.APP_NAME_KEY)).to(environment.getRequiredProperty(AppOptionKeys.APP_NAME_KEY)); } diff --git a/desktop/src/main/java/bisq/desktop/Navigation.java b/desktop/src/main/java/bisq/desktop/Navigation.java index 4fb4a7c3221..a5f82fc52d2 100644 --- a/desktop/src/main/java/bisq/desktop/Navigation.java +++ b/desktop/src/main/java/bisq/desktop/Navigation.java @@ -28,6 +28,8 @@ import com.google.inject.Inject; +import javax.inject.Singleton; + import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -41,6 +43,7 @@ import javax.annotation.Nullable; @Slf4j +@Singleton public final class Navigation implements PersistedDataHost { private static final ViewPath DEFAULT_VIEW_PATH = ViewPath.to(MainView.class, MarketView.class); diff --git a/desktop/src/main/java/bisq/desktop/common/fxml/FxmlViewLoader.java b/desktop/src/main/java/bisq/desktop/common/fxml/FxmlViewLoader.java index 77b07e69780..62820fe4f85 100644 --- a/desktop/src/main/java/bisq/desktop/common/fxml/FxmlViewLoader.java +++ b/desktop/src/main/java/bisq/desktop/common/fxml/FxmlViewLoader.java @@ -26,6 +26,7 @@ import org.springframework.core.annotation.AnnotationUtils; import javax.inject.Inject; +import javax.inject.Singleton; import javafx.fxml.FXMLLoader; @@ -38,6 +39,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import static org.springframework.core.annotation.AnnotationUtils.getDefaultValue; +@Singleton public class FxmlViewLoader implements ViewLoader { private final ViewFactory viewFactory; diff --git a/desktop/src/main/java/bisq/desktop/common/view/CachingViewLoader.java b/desktop/src/main/java/bisq/desktop/common/view/CachingViewLoader.java index f86df63cee1..cab1bc9d70b 100644 --- a/desktop/src/main/java/bisq/desktop/common/view/CachingViewLoader.java +++ b/desktop/src/main/java/bisq/desktop/common/view/CachingViewLoader.java @@ -18,9 +18,11 @@ package bisq.desktop.common.view; import javax.inject.Inject; +import javax.inject.Singleton; import java.util.HashMap; +@Singleton public class CachingViewLoader implements ViewLoader { private final HashMap cache = new HashMap<>(); diff --git a/desktop/src/main/java/bisq/desktop/common/view/guice/InjectorViewFactory.java b/desktop/src/main/java/bisq/desktop/common/view/guice/InjectorViewFactory.java index 4b41b56cf07..b85de8fb755 100644 --- a/desktop/src/main/java/bisq/desktop/common/view/guice/InjectorViewFactory.java +++ b/desktop/src/main/java/bisq/desktop/common/view/guice/InjectorViewFactory.java @@ -21,8 +21,11 @@ import com.google.inject.Injector; +import javax.inject.Singleton; + import com.google.common.base.Preconditions; +@Singleton public class InjectorViewFactory implements ViewFactory { private Injector injector; diff --git a/desktop/src/main/java/bisq/desktop/main/dao/bonding/BondingViewUtils.java b/desktop/src/main/java/bisq/desktop/main/dao/bonding/BondingViewUtils.java index 4eba2b37e11..bd0a998099e 100644 --- a/desktop/src/main/java/bisq/desktop/main/dao/bonding/BondingViewUtils.java +++ b/desktop/src/main/java/bisq/desktop/main/dao/bonding/BondingViewUtils.java @@ -47,6 +47,7 @@ import org.bitcoinj.core.InsufficientMoneyException; import javax.inject.Inject; +import javax.inject.Singleton; import java.util.Optional; import java.util.function.Consumer; @@ -56,6 +57,7 @@ import static com.google.common.base.Preconditions.checkArgument; @Slf4j +@Singleton public class BondingViewUtils { private final P2PService p2PService; private final MyReputationListService myReputationListService; diff --git a/desktop/src/main/java/bisq/desktop/main/funds/transactions/DisplayedTransactionsFactory.java b/desktop/src/main/java/bisq/desktop/main/funds/transactions/DisplayedTransactionsFactory.java index 63a08bfebef..4f2e44fc9a4 100644 --- a/desktop/src/main/java/bisq/desktop/main/funds/transactions/DisplayedTransactionsFactory.java +++ b/desktop/src/main/java/bisq/desktop/main/funds/transactions/DisplayedTransactionsFactory.java @@ -20,7 +20,9 @@ import bisq.core.btc.wallet.BtcWalletService; import javax.inject.Inject; +import javax.inject.Singleton; +@Singleton public class DisplayedTransactionsFactory { private final BtcWalletService btcWalletService; private final TradableRepository tradableRepository; diff --git a/desktop/src/main/java/bisq/desktop/main/funds/transactions/TradableRepository.java b/desktop/src/main/java/bisq/desktop/main/funds/transactions/TradableRepository.java index 0cabbe1438f..691901fc1b1 100644 --- a/desktop/src/main/java/bisq/desktop/main/funds/transactions/TradableRepository.java +++ b/desktop/src/main/java/bisq/desktop/main/funds/transactions/TradableRepository.java @@ -24,11 +24,13 @@ import bisq.core.trade.failed.FailedTradesManager; import javax.inject.Inject; +import javax.inject.Singleton; import com.google.common.collect.ImmutableSet; import java.util.Set; +@Singleton public class TradableRepository { private final OpenOfferManager openOfferManager; private final TradeManager tradeManager; diff --git a/desktop/src/main/java/bisq/desktop/main/funds/transactions/TransactionAwareTradableFactory.java b/desktop/src/main/java/bisq/desktop/main/funds/transactions/TransactionAwareTradableFactory.java index 0a6992d6846..234d96c6b3e 100644 --- a/desktop/src/main/java/bisq/desktop/main/funds/transactions/TransactionAwareTradableFactory.java +++ b/desktop/src/main/java/bisq/desktop/main/funds/transactions/TransactionAwareTradableFactory.java @@ -23,7 +23,9 @@ import bisq.core.trade.Trade; import javax.inject.Inject; +import javax.inject.Singleton; +@Singleton public class TransactionAwareTradableFactory { private final DisputeManager disputeManager; diff --git a/desktop/src/main/java/bisq/desktop/main/funds/transactions/TransactionListItemFactory.java b/desktop/src/main/java/bisq/desktop/main/funds/transactions/TransactionListItemFactory.java index 752ca17e9e4..e95974989d1 100644 --- a/desktop/src/main/java/bisq/desktop/main/funds/transactions/TransactionListItemFactory.java +++ b/desktop/src/main/java/bisq/desktop/main/funds/transactions/TransactionListItemFactory.java @@ -27,11 +27,13 @@ import org.bitcoinj.core.Transaction; import javax.inject.Inject; +import javax.inject.Singleton; import java.util.Optional; import javax.annotation.Nullable; +@Singleton public class TransactionListItemFactory { private final BtcWalletService btcWalletService; private final BsqWalletService bsqWalletService; diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBook.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBook.java index 53556eb9481..99670bac962 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBook.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBook.java @@ -22,6 +22,7 @@ import bisq.core.trade.TradeManager; import javax.inject.Inject; +import javax.inject.Singleton; import javafx.collections.FXCollections; import javafx.collections.ObservableList; @@ -42,6 +43,7 @@ * It also use OfferRepository.Listener as the lists items class and we don't want to get any dependency out of the * package for that. */ +@Singleton @Slf4j public class OfferBook { private final OfferBookService offerBookService; diff --git a/desktop/src/main/java/bisq/desktop/main/overlays/notifications/NotificationCenter.java b/desktop/src/main/java/bisq/desktop/main/overlays/notifications/NotificationCenter.java index ed732eb7180..04e9bfdf465 100644 --- a/desktop/src/main/java/bisq/desktop/main/overlays/notifications/NotificationCenter.java +++ b/desktop/src/main/java/bisq/desktop/main/overlays/notifications/NotificationCenter.java @@ -38,6 +38,8 @@ import com.google.inject.Inject; +import javax.inject.Singleton; + import org.fxmisc.easybind.EasyBind; import org.fxmisc.easybind.Subscription; @@ -54,6 +56,7 @@ import javax.annotation.Nullable; @Slf4j +@Singleton public class NotificationCenter { /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/desktop/src/main/java/bisq/desktop/main/overlays/windows/TorNetworkSettingsWindow.java b/desktop/src/main/java/bisq/desktop/main/overlays/windows/TorNetworkSettingsWindow.java index 5fd771c9248..d6a4be79afd 100644 --- a/desktop/src/main/java/bisq/desktop/main/overlays/windows/TorNetworkSettingsWindow.java +++ b/desktop/src/main/java/bisq/desktop/main/overlays/windows/TorNetworkSettingsWindow.java @@ -38,6 +38,7 @@ import bisq.common.util.Utilities; import javax.inject.Inject; +import javax.inject.Singleton; import javafx.scene.Scene; import javafx.scene.control.Button; @@ -72,6 +73,7 @@ import static bisq.desktop.util.FormBuilder.*; @Slf4j +@Singleton public class TorNetworkSettingsWindow extends Overlay { public enum BridgeOption { diff --git a/desktop/src/main/java/bisq/desktop/main/presentation/DaoPresentation.java b/desktop/src/main/java/bisq/desktop/main/presentation/DaoPresentation.java index a13579cb082..27a7eab5d08 100644 --- a/desktop/src/main/java/bisq/desktop/main/presentation/DaoPresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/presentation/DaoPresentation.java @@ -12,6 +12,7 @@ import bisq.common.app.DevEnv; import javax.inject.Inject; +import javax.inject.Singleton; import javafx.beans.property.BooleanProperty; import javafx.beans.property.DoubleProperty; @@ -25,6 +26,7 @@ import lombok.Getter; +@Singleton public class DaoPresentation implements DaoStateListener { public static final String DAO_NEWS = "daoNewsVersion1.0.0"; diff --git a/desktop/src/main/java/bisq/desktop/main/presentation/MarketPricePresentation.java b/desktop/src/main/java/bisq/desktop/main/presentation/MarketPricePresentation.java index ef6f46dc26f..870304ecf60 100644 --- a/desktop/src/main/java/bisq/desktop/main/presentation/MarketPricePresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/presentation/MarketPricePresentation.java @@ -35,6 +35,7 @@ import bisq.common.UserThread; import javax.inject.Inject; +import javax.inject.Singleton; import org.fxmisc.easybind.EasyBind; import org.fxmisc.easybind.Subscription; @@ -60,6 +61,7 @@ import lombok.Getter; +@Singleton public class MarketPricePresentation { private final Preferences preferences; private final BSFormatter formatter; diff --git a/desktop/src/main/java/bisq/desktop/util/Transitions.java b/desktop/src/main/java/bisq/desktop/util/Transitions.java index 3892968adb3..572f0fbe690 100644 --- a/desktop/src/main/java/bisq/desktop/util/Transitions.java +++ b/desktop/src/main/java/bisq/desktop/util/Transitions.java @@ -22,6 +22,7 @@ import bisq.common.UserThread; import javax.inject.Inject; +import javax.inject.Singleton; import javafx.animation.FadeTransition; import javafx.animation.Interpolator; @@ -39,6 +40,7 @@ import javafx.util.Duration; +@Singleton public class Transitions { public final static int DEFAULT_DURATION = 600; diff --git a/desktop/src/test/java/bisq/desktop/GuiceSetupTest.java b/desktop/src/test/java/bisq/desktop/GuiceSetupTest.java index 492ba3bdc2c..109df3e37be 100644 --- a/desktop/src/test/java/bisq/desktop/GuiceSetupTest.java +++ b/desktop/src/test/java/bisq/desktop/GuiceSetupTest.java @@ -2,23 +2,72 @@ import bisq.desktop.app.BisqAppModule; import bisq.desktop.common.view.CachingViewLoader; +import bisq.desktop.common.view.ViewLoader; +import bisq.desktop.common.view.guice.InjectorViewFactory; +import bisq.desktop.main.dao.bonding.BondingViewUtils; +import bisq.desktop.main.funds.transactions.DisplayedTransactionsFactory; +import bisq.desktop.main.funds.transactions.TradableRepository; +import bisq.desktop.main.funds.transactions.TransactionAwareTradableFactory; +import bisq.desktop.main.funds.transactions.TransactionListItemFactory; +import bisq.desktop.main.offer.offerbook.OfferBook; +import bisq.desktop.main.overlays.notifications.NotificationCenter; +import bisq.desktop.main.overlays.windows.TorNetworkSettingsWindow; +import bisq.desktop.main.presentation.DaoPresentation; +import bisq.desktop.main.presentation.MarketPricePresentation; +import bisq.desktop.util.Transitions; import bisq.core.app.AvoidStandbyModeService; import bisq.core.app.BisqEnvironment; +import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.Res; +import bisq.core.util.BSFormatter; +import bisq.core.util.BsqFormatter; import org.springframework.mock.env.MockPropertySource; import com.google.inject.Guice; import com.google.inject.Injector; +import org.junit.Before; import org.junit.Test; +import static org.junit.Assert.assertSame; + public class GuiceSetupTest { + + private Injector injector; + + @Before + public void setUp() { + Res.setup(); + CurrencyUtil.setup(); + + injector = Guice.createInjector(new BisqAppModule(new BisqEnvironment(new MockPropertySource()))); + } + @Test public void testGuiceSetup() { - BisqAppModule module = new BisqAppModule(new BisqEnvironment(new MockPropertySource())); - Injector injector = Guice.createInjector(module); - injector.getInstance(CachingViewLoader.class); injector.getInstance(AvoidStandbyModeService.class); + assertSingleton(OfferBook.class); + assertSingleton(CachingViewLoader.class); + assertSingleton(Navigation.class); + assertSingleton(InjectorViewFactory.class); + assertSingleton(NotificationCenter.class); + assertSingleton(BSFormatter.class); + assertSingleton(BsqFormatter.class); + assertSingleton(TorNetworkSettingsWindow.class); + assertSingleton(MarketPricePresentation.class); + assertSingleton(ViewLoader.class); + assertSingleton(DaoPresentation.class); + assertSingleton(Transitions.class); + assertSingleton(TradableRepository.class); + assertSingleton(TransactionListItemFactory.class); + assertSingleton(TransactionAwareTradableFactory.class); + assertSingleton(DisplayedTransactionsFactory.class); + assertSingleton(BondingViewUtils.class); + } + + private void assertSingleton(Class type) { + assertSame(injector.getInstance(type), injector.getInstance(type)); } } From e418d5bb09f3d89f1ee892029d1a973c348c5105 Mon Sep 17 00:00:00 2001 From: Christoph Sturm Date: Tue, 6 Aug 2019 17:46:35 +0200 Subject: [PATCH 4/4] update witness file for new guice version --- gradle/witness/gradle-witness.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/witness/gradle-witness.gradle b/gradle/witness/gradle-witness.gradle index c94a094b289..fd2b85e0a31 100644 --- a/gradle/witness/gradle-witness.gradle +++ b/gradle/witness/gradle-witness.gradle @@ -42,6 +42,7 @@ dependencyVerification { 'ch.qos.logback:logback-core:4cd46fa17d77057b39160058df2f21ebbc2aded51d0edcc25d2c1cecc042a005', 'com.google.code.findbugs:jsr305:766ad2a0783f2687962c8ad74ceecc38a28b9f72a2d085ee438b7813e928d0c7', 'com.google.guava:guava:36a666e3b71ae7f0f0dca23654b67e086e6c93d192f60ba5dfd5519db6c288c8', + 'com.google.inject:guice:d258ff1bd9b8b527872f8402648226658ad3149f1f40e74b0566d69e7e042fbc', 'com.github.bisq-network.bitcoinj:bitcoinj-core:f979c2187e61ee3b08dd4cbfc49a149734cff64c045d29ed112f2e12f34068a3', 'com.github.JesusMcCloud.netlayer:tor:35cf892e6ce3a8d942cfd2b589cfbde5aed31d49777aee873d6614e134df0b42', 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:193ab7813e4d249f2ea4fc1b968fea8c2126bcbeeb5d6127050ce1b93dbaa7c2', @@ -79,4 +80,3 @@ dependencyVerification { 'org.jetbrains.kotlin:kotlin-stdlib-common:4b161ef619eee0d1a49b1c4f0c4a8e46f4e342573efd8e0106a765f47475fe39', ] } -