private void setUpMockitoRules() throws Exception {

    when(mockDatabase.getDatabaseFactory()).thenReturn(mockDatabaseFactory);
    when(mockDatabaseTable.getEmptyRecord()).thenReturn(mockDatabaseTableRecord);
    when(mockDatabase.getTable(AssetIssuingDatabaseConstants.ASSET_ISSUING_TABLE_NAME))
        .thenReturn(mockDatabaseTable);
    when(pluginDatabaseSystem.openDatabase(
            pluginId, AssetIssuingDatabaseConstants.ASSET_ISSUING_DATABASE))
        .thenReturn(mockDatabase);

    //        when(mockExtraUserActorDatabaseFactory.createDatabase(pluginId,
    // pluginId.toString())).thenReturn(mockDatabase);
    when(deviceUser.getPublicKey()).thenReturn("myPublicKey");
    when(deviceUserManager.getLoggedInDeviceUser()).thenReturn(deviceUser);
    when(eventManager.getNewListener(
            EventType.INCOMING_ASSET_ON_CRYPTO_NETWORK_WAITING_TRANSFERENCE_ASSET_ISSUER))
        .thenReturn(fermatEventListener1);
    when(eventManager.getNewListener(
            EventType.INCOMING_ASSET_ON_BLOCKCHAIN_WAITING_TRANSFERENCE_ASSET_ISSUER))
        .thenReturn(fermatEventListener2);
    when(eventManager.getNewListener(
            EventType.INCOMING_ASSET_REVERSED_ON_BLOCKCHAIN_WAITING_TRANSFERENCE_ASSET_ISSUER))
        .thenReturn(fermatEventListener3);
    when(eventManager.getNewListener(
            EventType.INCOMING_ASSET_REVERSED_ON_CRYPTO_NETWORK_WAITING_TRANSFERENCE_ASSET_ISSUER))
        .thenReturn(fermatEventListener4);
    when(eventManager.getNewListener(EventType.RECEIVED_NEW_DIGITAL_ASSET_METADATA_NOTIFICATION))
        .thenReturn(fermatEventListener5);

    when(actorAssetIssuerManager.getActorAssetIssuer()).thenReturn(actorAssetIssuer);
  }
  private void setUpMockitoRules() throws Exception {

    when(mockDatabase.getDatabaseFactory()).thenReturn(mockDatabaseFactory);
    when(mockDatabaseTable.getEmptyRecord()).thenReturn(mockDatabaseTableRecord);
    when(mockDatabase.getTable(AssetIssuingDatabaseConstants.ASSET_ISSUING_TABLE_NAME))
        .thenReturn(mockDatabaseTable);
    when(mockDatabase.getTable(AssetIssuingDatabaseConstants.ASSET_ISSUING_METADATA_TABLE))
        .thenReturn(mockDatabaseTable2);
    when(mockDatabaseTable2.getEmptyRecord()).thenReturn(mockDatabaseTableRecord);
    when(mockDatabaseTable2.getRecords()).thenReturn(records);
    when(pluginDatabaseSystem.openDatabase(
            pluginId, AssetIssuingDatabaseConstants.ASSET_ISSUING_DATABASE))
        .thenReturn(mockDatabase);

    when(deviceUser.getPublicKey()).thenReturn("myPublicKey");
    when(deviceUserManager.getLoggedInDeviceUser()).thenReturn(deviceUser);

    when(actorAssetIssuerManager.getActorAssetIssuer()).thenReturn(actorAssetIssuer);

    when(eventManager.getNewListener(
            EventType.INCOMING_ASSET_ON_CRYPTO_NETWORK_WAITING_TRANSFERENCE_ASSET_ISSUER))
        .thenReturn(fermatEventListener1);
    when(eventManager.getNewListener(
            EventType.INCOMING_ASSET_ON_BLOCKCHAIN_WAITING_TRANSFERENCE_ASSET_ISSUER))
        .thenReturn(fermatEventListener2);
    when(eventManager.getNewListener(
            EventType.INCOMING_ASSET_REVERSED_ON_BLOCKCHAIN_WAITING_TRANSFERENCE_ASSET_ISSUER))
        .thenReturn(fermatEventListener3);
    when(eventManager.getNewListener(
            EventType.INCOMING_ASSET_REVERSED_ON_CRYPTO_NETWORK_WAITING_TRANSFERENCE_ASSET_ISSUER))
        .thenReturn(fermatEventListener4);

    when(pluginFileSystem.createTextFile(
            this.pluginId,
            "digital-asset-issuing/publicKey",
            "name.xml",
            FilePrivacy.PUBLIC,
            FileLifeSpan.PERMANENT))
        .thenReturn(pluginTextFile);
    when(cryptoWalletManager.loadWallet(this.walletPublicKey)).thenReturn(cryptoWalletWallet);
    when(cryptoWalletWallet.getBalance(BalanceType.AVAILABLE)).thenReturn(cryptoWalletBalance);
    when(cryptoWalletBalance.getBalance()).thenReturn(bitcoinWalletAvailableBalance);
    when(assetVaultManager.getNewAssetVaultCryptoAddress(this.blockchainNetworkType))
        .thenReturn(cryptoAddress);
    //        doNothing().when(assetIssuingPluginRoot).issueAssets(digitalAsset, 1, walletPublicKey,
    // blockchainNetworkType);
  }
  /** Initialize all event listener and configure */
  private void initializeListener() {

    /*
     * 1. Listen and handle Client Connection Close Notification Event
     */
    FermatEventListener fermatEventListener =
        eventManager.getNewListener(P2pEventType.CLIENT_CONNECTION_CLOSE);
    fermatEventListener.setEventHandler(new ClientConnectionCloseNotificationEventHandler(this));
    eventManager.addListener(fermatEventListener);
    listenersAdded.add(fermatEventListener);

    /*
     * 2 Listen and handle Client Connection Loose Notification Event
     */
    fermatEventListener = eventManager.getNewListener(P2pEventType.CLIENT_CONNECTION_LOOSE);
    fermatEventListener.setEventHandler(new ClientConnectionLooseNotificationEventHandler(this));
    eventManager.addListener(fermatEventListener);
    listenersAdded.add(fermatEventListener);

    /*
     * 3 Listen and handle Client Connection Success Reconnect Notification Event
     */
    fermatEventListener = eventManager.getNewListener(P2pEventType.CLIENT_SUCCESS_RECONNECT);
    fermatEventListener.setEventHandler(
        new ClientSuccessfulReconnectNotificationEventHandler(this));
    eventManager.addListener(fermatEventListener);
    listenersAdded.add(fermatEventListener);

    /*
     * 4 Listen and handle Complete Request List Component Registered Notification Event
     */
    fermatEventListener =
        eventManager.getNewListener(
            P2pEventType.COMPLETE_COMPONENT_CONNECTION_REQUEST_NOTIFICATION);
    fermatEventListener.setEventHandler(
        new CompleteComponentConnectionRequestNotificationEventHandler(this));
    eventManager.addListener(fermatEventListener);
    listenersAdded.add(fermatEventListener);

    /*
     * 5 Listen and handle Complete Component Registration Notification Event
     */
    fermatEventListener =
        eventManager.getNewListener(P2pEventType.COMPLETE_COMPONENT_REGISTRATION_NOTIFICATION);
    fermatEventListener.setEventHandler(
        new CompleteComponentRegistrationNotificationEventHandler(this));
    eventManager.addListener(fermatEventListener);
    listenersAdded.add(fermatEventListener);

    /*
     * 6 Listen and handle Complete Request list
     */
    fermatEventListener =
        eventManager.getNewListener(
            P2pEventType.COMPLETE_REQUEST_LIST_COMPONENT_REGISTERED_NOTIFICATION);
    fermatEventListener.setEventHandler(
        new CompleteRequestListComponentRegisteredNotificationEventHandler(this));
    eventManager.addListener(fermatEventListener);
    listenersAdded.add(fermatEventListener);

    /*
     * 7 Listen and handle Complete Update Actor Profile Notification Event
     */
    fermatEventListener =
        eventManager.getNewListener(P2pEventType.COMPLETE_UPDATE_ACTOR_NOTIFICATION);
    fermatEventListener.setEventHandler(new CompleteUpdateActorNotificationEventHandler(this));
    eventManager.addListener(fermatEventListener);
    listenersAdded.add(fermatEventListener);

    /*
     * 8 Listen and handle failure component connection
     */
    fermatEventListener =
        eventManager.getNewListener(P2pEventType.FAILURE_COMPONENT_CONNECTION_REQUEST_NOTIFICATION);
    fermatEventListener.setEventHandler(
        new FailureComponentConnectionRequestNotificationEventHandler(this));
    eventManager.addListener(fermatEventListener);
    listenersAdded.add(fermatEventListener);

    /*
     * 9 Listen and handle VPN Connection Close Notification Event
     */
    fermatEventListener = eventManager.getNewListener(P2pEventType.VPN_CONNECTION_CLOSE);
    fermatEventListener.setEventHandler(new VPNConnectionCloseNotificationEventHandler(this));
    eventManager.addListener(fermatEventListener);
    listenersAdded.add(fermatEventListener);

    /*
     * 10 Listen and handle VPN Connection Loose Notification Event
     */
    fermatEventListener = eventManager.getNewListener(P2pEventType.VPN_CONNECTION_LOOSE);
    fermatEventListener.setEventHandler(new VPNConnectionLooseNotificationEventHandler(this));
    eventManager.addListener(fermatEventListener);
    listenersAdded.add(fermatEventListener);

    /*
     * 11 Listen and handle Register Server Request Notification Event
     */
    fermatEventListener =
        eventManager.getNewListener(P2pEventType.REGISTER_SERVER_REQUEST_NOTIFICATION);
    fermatEventListener.setEventHandler(new RegisterServerRequestNotificationEventHandler(this));
    eventManager.addListener(fermatEventListener);
    listenersAdded.add(fermatEventListener);
  }