예제 #1
0
  @Test
  public void buildChildren_WithNoDatabaseDataContainingChildren_DoesntAddDummyChildToTreeNode() {

    UUID parentId = randomUUID();
    ArrayList<TreeNode> children = new ArrayList<TreeNode>();

    ProductCategoryDAO prodCatDAO = mock(ProductCategoryDAO.class);
    Mockito.when(prodCatDAO.getChildCategories(parentId))
        .thenReturn(asList(new ProductCategoryAggregate(null, "One", 0L)));

    TreeNodeBuilderImpl builder = new TreeNodeBuilderImpl(prodCatDAO);
    builder.buildChildren(children, new TreeModel("ProdCat1", parentId));

    assertThat(children.size(), is(0));
  }
예제 #2
0
  @Test
  public void buildChildren_WithExistingDummyChild_RemovesDummyChildInTreeNode() {

    UUID parentId = randomUUID();
    List<TreeNode> children = new ArrayList<TreeNode>();
    children.add(new DefaultTreeNode(-1));

    ProductCategoryDAO prodCatDAO = mock(ProductCategoryDAO.class);
    Mockito.when(prodCatDAO.getChildCategories(parentId))
        .thenReturn(asList(new ProductCategoryAggregate(null, "One", 0L)));

    TreeNodeBuilderImpl builder = new TreeNodeBuilderImpl(prodCatDAO);
    builder.buildChildren(children, new TreeModel("ProdCat1", parentId));

    assertThat(children.size(), is(1));
    assertThat(children.get(0).getChildCount(), is(0));
  }