### Question:
SimpleReferenceTree implements IndexRuleTree { @Override public void addIndexRule(String indexRule) { if (indexRule == null) { throw new IllegalArgumentException("Pattern must not be null"); } StringBuilder rule = new StringBuilder(indexRule); TreeNode parentNode = null, childNode = null; TreeNode lockNode = findLastMatchingNode(root, rule); synchronized (lockNode) { parentNode = childNode = findLastMatchingNode(lockNode, rule); for (int index = 0; index < rule.length(); index++) { childNode = factory.getTreeNode(rule.charAt(index)); childNode.setParent(parentNode); childNode.setSibling(parentNode.getChild()); parentNode.setChild(childNode); parentNode = childNode; } } childNode.markEndPoint(); } SimpleReferenceTree();  SimpleReferenceTree(TreeNodeFactory factory); @Override void addIndexRule(String indexRule); @Override void addIndexRules(Collection<String> indexRules); @Override void removeIndexRule(String indexRule); @Override Set<String> searchTree(String resource); @Override String toString();  }### Answer:
@Test public void verifyUsageOfCustomFactory() { String path = "abcdefghijklmnopqrstuvwxyz"; TreeNodeFactory factory = mock(TreeNodeFactory.class); when(factory.getRootNode()).thenReturn(mock(TreeNode.class)); for (char pathChar : path.toCharArray()) { when(factory.getTreeNode(pathChar)).thenReturn(mock(TreeNode.class)); } tree = new SimpleReferenceTree(factory); tree.addIndexRule(path); verify(factory).getRootNode(); for (char pathChar : path.toCharArray()) { verify(factory).getTreeNode(pathChar); } }