@Override
  public final void deleteWord(String word) {
    synchronized (mResourceMonitor) {
      if (isClosed()) {
        Logger.d(
            TAG,
            "Dictionary (type "
                + this.getClass().getName()
                + ") "
                + this.getDictionaryName()
                + " is closed! Can not delete word.");
        return;
      }
      deleteWordRec(mRoots, word, 0, word.length());
      deleteWordFromStorage(word);
    }
  }
@Test
  public void testDeleteWord() throws Exception {
    mDictionaryUnderTest.loadDictionary();
    // from read storage
    String word = (String) TestableBTreeDictionary.STORAGE[0][1];
    int wordFreq = ((Integer) TestableBTreeDictionary.STORAGE[0][2]).intValue();
    assertTrue(mDictionaryUnderTest.isValidWord(word));
    mDictionaryUnderTest.deleteWord(word);
    Assert.assertFalse(mDictionaryUnderTest.isValidWord(word));
    Assert.assertEquals(mDictionaryUnderTest.wordRequestedToBeDeletedFromStorage, word);
    // checking validity of the internal structure
    assetNodeArrayIsValid(mDictionaryUnderTest.getRoot());

    // re-adding
    assertTrue(mDictionaryUnderTest.addWord(word, wordFreq + 1));
    assertTrue(mDictionaryUnderTest.isValidWord(word));
    Assert.assertEquals(wordFreq + 1, mDictionaryUnderTest.getWordFrequency(word));
    mDictionaryUnderTest.wordRequestedToBeDeletedFromStorage = null;
    mDictionaryUnderTest.deleteWord(word);
    Assert.assertFalse(mDictionaryUnderTest.isValidWord(word));
    Assert.assertEquals(mDictionaryUnderTest.wordRequestedToBeDeletedFromStorage, word);
    // checking validity of the internal structure
    assetNodeArrayIsValid(mDictionaryUnderTest.getRoot());

    // a new one
    word = "new";
    assertTrue(mDictionaryUnderTest.addWord(word, wordFreq));
    assertTrue(mDictionaryUnderTest.isValidWord(word));
    Assert.assertEquals(wordFreq, mDictionaryUnderTest.getWordFrequency(word));
    mDictionaryUnderTest.wordRequestedToBeDeletedFromStorage = null;
    mDictionaryUnderTest.deleteWord(word);
    Assert.assertFalse(mDictionaryUnderTest.isValidWord(word));
    Assert.assertEquals(mDictionaryUnderTest.wordRequestedToBeDeletedFromStorage, word);
    // checking validity of the internal structure
    assetNodeArrayIsValid(mDictionaryUnderTest.getRoot());

    // none existing
    Assert.assertFalse(mDictionaryUnderTest.isValidWord("fail"));
    mDictionaryUnderTest.deleteWord("fail");
    Assert.assertFalse(mDictionaryUnderTest.isValidWord("fail"));
    // checking validity of the internal structure
    assetNodeArrayIsValid(mDictionaryUnderTest.getRoot());

    // deleting part of the root
    mDictionaryUnderTest.addWord("root", 1);
    mDictionaryUnderTest.addWord("rooting", 2);
    mDictionaryUnderTest.addWord("rootina", 2);
    Assert.assertFalse(mDictionaryUnderTest.isValidWord("roo"));
    Assert.assertFalse(mDictionaryUnderTest.isValidWord("rooti"));
    // checking validity of the internal structure
    assetNodeArrayIsValid(mDictionaryUnderTest.getRoot());

    mDictionaryUnderTest.deleteWord("root");
    Assert.assertFalse(mDictionaryUnderTest.isValidWord("roo"));
    Assert.assertFalse(mDictionaryUnderTest.isValidWord("root"));
    Assert.assertFalse(mDictionaryUnderTest.isValidWord("rooti"));
    assertTrue(mDictionaryUnderTest.isValidWord("rooting"));
    assertTrue(mDictionaryUnderTest.isValidWord("rootina"));
    // checking validity of the internal structure
    assetNodeArrayIsValid(mDictionaryUnderTest.getRoot());

    mDictionaryUnderTest.deleteWord("rooting");
    Assert.assertFalse(mDictionaryUnderTest.isValidWord("root"));
    Assert.assertFalse(mDictionaryUnderTest.isValidWord("rooti"));
    Assert.assertFalse(mDictionaryUnderTest.isValidWord("rooting"));
    assertTrue(mDictionaryUnderTest.isValidWord("rootina"));
    // checking validity of the internal structure
    assetNodeArrayIsValid(mDictionaryUnderTest.getRoot());

    mDictionaryUnderTest.addWord("root", 1);
    assertTrue(mDictionaryUnderTest.isValidWord("root"));
    Assert.assertFalse(mDictionaryUnderTest.isValidWord("rooting"));
    Assert.assertFalse(mDictionaryUnderTest.isValidWord("rooti"));
    assertTrue(mDictionaryUnderTest.isValidWord("rootina"));
    // checking validity of the internal structure
    assetNodeArrayIsValid(mDictionaryUnderTest.getRoot());

    mDictionaryUnderTest.deleteWord("rootina");
    assertTrue(mDictionaryUnderTest.isValidWord("root"));
    Assert.assertFalse(mDictionaryUnderTest.isValidWord("rooting"));
    Assert.assertFalse(mDictionaryUnderTest.isValidWord("rooti"));
    Assert.assertFalse(mDictionaryUnderTest.isValidWord("rootina"));
    // checking validity of the internal structure
    assetNodeArrayIsValid(mDictionaryUnderTest.getRoot());
  }