@Override
  public boolean addWord(String word, int frequency) {
    synchronized (mResourceMonitor) {
      if (isClosed()) {
        Logger.d(
            TAG,
            "Dictionary (type "
                + this.getClass().getName()
                + ") "
                + this.getDictionaryName()
                + " is closed! Can not add word.");
        return false;
      }
      // Safeguard against adding long words. Can cause stack overflow.
      if (word.length() >= getMaxWordLength()) return false;

      Logger.i(
          TAG,
          "Adding word '"
              + word
              + "' to dictionary (in "
              + getClass().getSimpleName()
              + ") with frequency "
              + frequency);
      // first deleting the word, so it wont conflict in the adding (_ID is unique).
      deleteWord(word);
      // add word to in-memory structure
      addWordRec(mRoots, word, 0, frequency);
      // add word to storage
      addWordToStorage(word, frequency);
    }
    return true;
  }
@Test
  public void testAddWord() throws Exception {
    mDictionaryUnderTest.loadDictionary();

    assertTrue(mDictionaryUnderTest.addWord("new", 23));
    Assert.assertEquals("new", mDictionaryUnderTest.wordRequestedToAddedToStorage);
    Assert.assertEquals(23, mDictionaryUnderTest.wordFrequencyRequestedToAddedToStorage);
    assertTrue(mDictionaryUnderTest.isValidWord("new"));
    Assert.assertEquals(mDictionaryUnderTest.getWordFrequency("new"), 23);
    // checking validity of the internal structure
    assetNodeArrayIsValid(mDictionaryUnderTest.getRoot());

    assertTrue(mDictionaryUnderTest.addWord("new", 34));
    Assert.assertEquals("new", mDictionaryUnderTest.wordRequestedToAddedToStorage);
    Assert.assertEquals(34, mDictionaryUnderTest.wordFrequencyRequestedToAddedToStorage);
    assertTrue(mDictionaryUnderTest.isValidWord("new"));
    Assert.assertEquals(34, mDictionaryUnderTest.getWordFrequency("new"));
    // checking validity of the internal structure
    assetNodeArrayIsValid(mDictionaryUnderTest.getRoot());

    assertTrue(mDictionaryUnderTest.addWord("newa", 45));
    assertTrue(mDictionaryUnderTest.isValidWord("newa"));
    Assert.assertEquals(34, mDictionaryUnderTest.getWordFrequency("new"));
    Assert.assertEquals(45, mDictionaryUnderTest.getWordFrequency("newa"));
    // checking validity of the internal structure
    assetNodeArrayIsValid(mDictionaryUnderTest.getRoot());

    assertTrue(mDictionaryUnderTest.addWord("nea", 47));
    Assert.assertEquals("nea", mDictionaryUnderTest.wordRequestedToAddedToStorage);
    Assert.assertEquals(47, mDictionaryUnderTest.wordFrequencyRequestedToAddedToStorage);
    assertTrue(mDictionaryUnderTest.isValidWord("nea"));
    Assert.assertEquals(34, mDictionaryUnderTest.getWordFrequency("new"));
    Assert.assertEquals(45, mDictionaryUnderTest.getWordFrequency("newa"));
    Assert.assertEquals(47, mDictionaryUnderTest.getWordFrequency("nea"));
    // checking validity of the internal structure
    assetNodeArrayIsValid(mDictionaryUnderTest.getRoot());

    assertTrue(mDictionaryUnderTest.addWord("neabb", 50));
    Assert.assertEquals("neabb", mDictionaryUnderTest.wordRequestedToAddedToStorage);
    Assert.assertEquals(50, mDictionaryUnderTest.wordFrequencyRequestedToAddedToStorage);
    assertTrue(mDictionaryUnderTest.isValidWord("neabb"));
    Assert.assertFalse(mDictionaryUnderTest.isValidWord("neab"));
    Assert.assertEquals(34, mDictionaryUnderTest.getWordFrequency("new"));
    Assert.assertEquals(45, mDictionaryUnderTest.getWordFrequency("newa"));
    Assert.assertEquals(47, mDictionaryUnderTest.getWordFrequency("nea"));
    Assert.assertEquals(50, mDictionaryUnderTest.getWordFrequency("neabb"));
    Assert.assertEquals(0, mDictionaryUnderTest.getWordFrequency("neab"));
    // checking validity of the internal structure
    assetNodeArrayIsValid(mDictionaryUnderTest.getRoot());
  }