### Question:
WikiTreeNode extends AbstractEntityTreeNode { @Override public int getChildCount(String nodeId) { EntityReference wikiReference = resolve(nodeId); if (wikiReference != null && wikiReference.getType() == EntityType.WIKI) { try { return getChildCount(new WikiReference(wikiReference)); } catch (QueryException e) { this.logger.warn("Failed to count the children of [{}]. Root cause [{}].", nodeId, ExceptionUtils.getRootCauseMessage(e)); } } return 0; }  @Override List<String> getChildren(String nodeId, int offset, int limit); @Override int getChildCount(String nodeId); @Override String getParent(String nodeId);  }### Answer:
@Test public void getChildCount() throws Exception { this.wikiTreeNode.getProperties().put("filterHiddenDocuments", true); UserProperties userProperties = mock(UserProperties.class); when(userProperties.displayHiddenDocuments()).thenReturn(false); when(this.userPropertiesResolver.resolve(CurrentUserReference.INSTANCE)).thenReturn(userProperties); assertEquals(0, this.wikiTreeNode.getChildCount("something")); assertEquals(0, this.wikiTreeNode.getChildCount("some:thing")); when(this.queryManager.createQuery("select count(*) from XWikiSpace where parent is null and hidden <> true", Query.HQL)).thenReturn(this.query); when(query.execute()).thenReturn(Collections.singletonList(2L)); assertEquals(2L, this.wikiTreeNode.getChildCount("wiki:foo")); verify(this.query).setWiki("foo"); verify(this.query, never()).bindValue(anyString(), any()); }
@Test public void getChildCountWithExclusions() throws Exception { this.wikiTreeNode.getProperties().put("exclusions", new HashSet<>( Arrays.asList("document:bar:A.WebHome", "document:foo:B.WebHome", "document:foo:C.D", "space:foo:C"))); DocumentReference denis = new DocumentReference("foo", "C", "D"); when(this.entityTreeNodeIdConverter.convert(EntityReference.class, "document:foo:C.D")).thenReturn(denis); SpaceReference carol = new SpaceReference("foo", "C"); when(this.entityTreeNodeIdConverter.convert(EntityReference.class, "space:foo:C")).thenReturn(carol); when(this.localEntityReferenceSerializer.serialize(carol)).thenReturn("C"); this.wikiTreeNode.getProperties().put("filters", Collections.singletonList("test")); when(this.entityTreeNodeIdConverter.convert(String.class, new WikiReference("foo"))).thenReturn("wiki:foo"); when(this.filter.getChildExclusions("wiki:foo")).thenReturn(Collections.singleton("document:foo:J.WebHome")); DocumentReference john = new DocumentReference("foo", "J", "WebHome"); when(this.entityTreeNodeIdConverter.convert(EntityReference.class, "document:foo:J.WebHome")).thenReturn(john); when(this.localEntityReferenceSerializer.serialize(john.getLastSpaceReference())).thenReturn("J"); when(this.queryManager.createQuery( "select count(*) from XWikiSpace where parent is null " + "and reference not in (:excludedSpaces)", Query.HQL)).thenReturn(this.query); when(query.execute()).thenReturn(Collections.singletonList(2L)); assertEquals(2L, this.wikiTreeNode.getChildCount("wiki:foo")); verify(this.query).setWiki("foo"); verify(this.query).bindValue("excludedSpaces", new HashSet<String>(Arrays.asList("B", "C", "J"))); }