Ejemplo n.º 1
0
  @Test
  public void get_children_respects_predicate() {
    CLTreeNode<String> parentNode = new CLTreeNodeImpl<>("parent");
    parentNode.addChild(new CLTreeNodeImpl<>("child1"));
    parentNode.addChild(new CLTreeNodeImpl<>("child2"));
    parentNode.addChild(new CLTreeNodeImpl<>("child3"));
    parentNode.addChild(new CLTreeNodeImpl<>("not_a_child"));
    parentNode.addChild(new CLTreeNodeImpl<>("again, not a child"));

    List<CLTreeNode<String>> children = parentNode.getChildren(s -> s.startsWith("child"));
    assertThat(children.size(), is(3));
    List<String> objectsInside =
        children.stream().map(CLTreeNode::lookInside).collect(Collectors.toList());
    assertTrue(objectsInside.contains("child1"));
    assertTrue(objectsInside.contains("child2"));
    assertTrue(objectsInside.contains("child3"));
  }
Ejemplo n.º 2
0
  @Test
  public void remove_child() {
    CLTreeNode<String> parentNode = new CLTreeNodeImpl<>("parent");
    parentNode.addChild(new CLTreeNodeImpl<>("child1"));
    parentNode.addChild(new CLTreeNodeImpl<>("child2"));
    parentNode.addChild(new CLTreeNodeImpl<>("child3"));
    parentNode.addChild(new CLTreeNodeImpl<>("not_a_child"));
    parentNode.addChild(new CLTreeNodeImpl<>("again, not a child"));

    assertThat(parentNode.getChildren(c -> true).size(), is(5));
    parentNode.removeChild("child1"::equals);
    parentNode.removeChild("not_a_child"::equals);
    assertThat(parentNode.getChildren(c -> true).size(), is(3));
    List<String> objectsInside =
        parentNode
            .getChildren(c -> true)
            .stream()
            .map(CLTreeNode::lookInside)
            .collect(Collectors.toList());
    assertTrue(objectsInside.contains("child2"));
    assertTrue(objectsInside.contains("child3"));
    assertTrue(objectsInside.contains("again, not a child"));
  }
Ejemplo n.º 3
0
 @Test(expected = NullPointerException.class)
 public void does_not_allow_null_predicate() {
   CLTreeNode<String> parentNode = new CLTreeNodeImpl<>("node");
   parentNode.addChild(new CLTreeNodeImpl<>("child"));
   parentNode.getChildren(null);
 }