public void setupSuggestionsForKeyboard(
      @NonNull List<DictionaryAddOnAndBuilder> dictionaryBuilders,
      @NonNull DictionaryBackgroundLoader.Listener cb) {
    if (BuildConfig.TESTING_BUILD) {
      Logger.d(TAG, "setupSuggestionsFor %d dictionaries", dictionaryBuilders.size());
      for (DictionaryAddOnAndBuilder dictionaryBuilder : dictionaryBuilders) {
        Logger.d(
            TAG,
            " * dictionary %s (%s)",
            dictionaryBuilder.getId(),
            dictionaryBuilder.getLanguage());
      }
    }
    final int newSetupHashCode = calculateHashCodeForBuilders(dictionaryBuilders);
    if (newSetupHashCode == mCurrentSetupHashCode) {
      // no need to load, since we have all the same dictionaries,
      // but, we do need to notify the dictionary loaded listeners.
      final List<Dictionary> dictionariesToSimulateLoad =
          new ArrayList<>(mMainDictionary.size() + mUserDictionary.size() + 1 /*for contacts*/);
      dictionariesToSimulateLoad.addAll(mMainDictionary);
      dictionariesToSimulateLoad.addAll(mUserDictionary);
      if (mContactsDictionaryEnabled) dictionariesToSimulateLoad.add(mContactsDictionary);

      for (Dictionary dictionary : dictionariesToSimulateLoad) {
        cb.onDictionaryLoadingStarted(dictionary);
      }
      for (Dictionary dictionary : dictionariesToSimulateLoad) {
        cb.onDictionaryLoadingDone(dictionary);
      }
      return;
    }

    close();

    mCurrentSetupHashCode = newSetupHashCode;
    final CompositeDisposable disposablesHolder = mDictionaryDisposables;

    for (int i = 0; i < dictionaryBuilders.size(); i++) {
      DictionaryAddOnAndBuilder dictionaryBuilder = dictionaryBuilders.get(i);
      try {
        Logger.d(
            TAG,
            " Creating dictionary %s (%s)...",
            dictionaryBuilder.getId(),
            dictionaryBuilder.getLanguage());
        final Dictionary dictionary = dictionaryBuilder.createDictionary();
        mMainDictionary.add(dictionary);
        Logger.d(
            TAG,
            " Loading dictionary %s (%s)...",
            dictionaryBuilder.getId(),
            dictionaryBuilder.getLanguage());
        disposablesHolder.add(
            DictionaryBackgroundLoader.loadDictionaryInBackground(cb, dictionary));
      } catch (Exception e) {
        Logger.e(TAG, e, "Failed to create dictionary %s", dictionaryBuilder.getId());
      }

      if (mUserDictionaryEnabled) {
        final UserDictionary userDictionary =
            createUserDictionaryForLocale(dictionaryBuilder.getLanguage());
        mUserDictionary.add(userDictionary);
        Logger.d(TAG, " Loading user dictionary for %s...", dictionaryBuilder.getLanguage());
        disposablesHolder.add(
            DictionaryBackgroundLoader.loadDictionaryInBackground(cb, userDictionary));
        mUserNextWordDictionary.add(userDictionary.getUserNextWordGetter());
      } else {
        Logger.d(TAG, " User does not want user dictionary, skipping...");
      }
      // if mQuickFixesEnabled and mQuickFixesSecondDisabled are true
      // it  activates autotext only to the current keyboard layout language
      if (mQuickFixesEnabled && (i == 0 || !mQuickFixesSecondDisabled)) {
        final AutoText autoText = dictionaryBuilder.createAutoText();
        if (autoText != null) {
          mQuickFixesAutoText.add(autoText);
        }
        final AbbreviationsDictionary abbreviationsDictionary =
            new AbbreviationsDictionary(mContext, dictionaryBuilder.getLanguage());
        mAbbreviationDictionary.add(abbreviationsDictionary);
        Logger.d(TAG, " Loading abbr dictionary for %s...", dictionaryBuilder.getLanguage());
        disposablesHolder.add(
            DictionaryBackgroundLoader.loadDictionaryInBackground(abbreviationsDictionary));
      }

      mInitialSuggestionsList.addAll(dictionaryBuilder.createInitialSuggestions());

      // only one auto-dictionary. There is no way to know to which language the typed word
      // belongs.
      mAutoDictionary = new AutoDictionary(mContext, dictionaryBuilder.getLanguage());
      Logger.d(TAG, " Loading auto dictionary for %s...", dictionaryBuilder.getLanguage());
      disposablesHolder.add(DictionaryBackgroundLoader.loadDictionaryInBackground(mAutoDictionary));
    }

    if (mContactsDictionaryEnabled && mContactsDictionary == NullDictionary) {
      mContactsDictionaryListener.mDelegate = cb;
      final ContactsDictionary realContactsDictionary = createRealContactsDictionary();
      mContactsDictionary = realContactsDictionary;
      mContactsNextWordDictionary = realContactsDictionary;
      disposablesHolder.add(
          DictionaryBackgroundLoader.loadDictionaryInBackground(
              mContactsDictionaryListener, mContactsDictionary));
    }
  }
@Test
  public void testDoesCreateAutoTextForSecondaries() throws Exception {
    SharedPrefsHelper.setPrefsValue(R.string.settings_key_quick_fix, true);
    SharedPrefsHelper.setPrefsValue(R.string.settings_key_quick_fix_second_disabled, false);
    mFakeBuilders.add(Mockito.spy(new FakeBuilder("hell", "hello", "say", "said", "drink")));
    mFakeBuilders.add(Mockito.spy(new FakeBuilder("salt", "helll")));
    mFakeBuilders.add(Mockito.spy(new FakeBuilder("ciao", "come")));
    mFakeBuilders.add(Mockito.spy(new FakeBuilder("hola", "como")));
    mSuggestionsProvider.setupSuggestionsForKeyboard(mFakeBuilders, mMockListener);

    for (int i = 0; i < mFakeBuilders.size(); i++) {
      DictionaryAddOnAndBuilder fakeB = mFakeBuilders.get(i);
      if (i != 0) {
        Mockito.verify(fakeB).createDictionary();
        Mockito.verify(fakeB).createAutoText();
        Mockito.verify(fakeB).createInitialSuggestions();
        Mockito.verify(fakeB, Mockito.atLeastOnce()).getLanguage();
      }
    }
  }