Class ServiceProvider


  • public class ServiceProvider
    extends Object
    Inner service provider that implements dependency injection (DI) of some SDK classes which are needed to be tested properly. This class creates objects as they are used in normal environment giving opportunity to mock them for testing before they are actually created.
    • Constructor Detail

      • ServiceProvider

        public ServiceProvider()
    • Method Detail

      • setHistoryFileManagerMock

        public static void setHistoryFileManagerMock​(HistoryFileManager mock)
        Sets history file manager mock that will be created by this provider. If null is set, the mock is removed and the object will be created as normal.
        Parameters:
        mock - mocked history file manager or null
      • createMetaApiConnection

        public static MetaApiConnection createMetaApiConnection​(MetaApiWebsocketClient websocketClient,
                                                                MetatraderAccount account,
                                                                HistoryStorage historyStorage,
                                                                ConnectionRegistry connectionRegistry)
        Constructs metaapi connection with its corresponding constructor or returns a mock if it is set.
        Parameters:
        websocketClient - MetaApi websocket client
        account - MetaTrader account to connect to
        historyStorage - optional local terminal history storage. Use for accounts in user synchronization mode. By default an instance of MemoryHistoryStorage will be used.
        connectionRegistry - metatrader account connection registry
        See Also:
        setHistoryFileManagerMock(HistoryFileManager)
      • setMetApiConnectionMock

        public static void setMetApiConnectionMock​(MetaApiConnection mock)
        Sets metaapi connection mock that will be created by this provider. If null is set, the mock is removed and the object will be created as normal.
        Parameters:
        mock - mocked metaapi connection or null
      • setMetApiConnectionMock

        public static void setMetApiConnectionMock​(ServiceProvider.MetaApiConnectionProvider mockProvider)
        Sets metaapi connection provider that will be used for creating the mock. If null is set, the mock provider is removed and the object will be created as normal.
        Parameters:
        mockProvider - mocked metaapi connection or null