@Test
 public void testGetParent() {
   System.out.println("testGetParent");
   for (Category root : serviceStub.getRootCategories()) {
     assertNull(container.getParent(root.getId()));
     for (Category child : serviceStub.getChildren(root)) {
       assertEquals(root.getId(), container.getParent(child.getId()));
     }
   }
 }
 @Test
 public void testHasChildren() {
   System.out.println("testHasChildren");
   for (Category root : serviceStub.getRootCategories()) {
     assertTrue(container.hasChildren(root.getId()));
     for (Category c : serviceStub.getChildren(root)) {
       assertFalse(container.hasChildren(c.getId()));
     }
   }
 }
 private void createTestData(CategoryService service) {
   for (int i = 1; i <= 5; ++i) {
     Category r = new Category();
     r.setName("Root" + i);
     service.saveCategory(r);
     for (int j = 1; j <= 5; ++j) {
       Category c = new Category();
       c.setName("Child" + i + "_" + j);
       c.setParent(r);
       service.saveCategory(c);
     }
   }
 }
 @Test
 public void testGetChildren() {
   System.out.println("testGetChildren");
   for (Category root : serviceStub.getRootCategories()) {
     Collection<?> childrenIds = container.getChildren(root.getId());
     List<Category> children = serviceStub.getChildren(root);
     assertEquals(children.size(), childrenIds.size());
     Iterator<?> idIterator = childrenIds.iterator();
     Iterator<Category> childIterator = children.iterator();
     while (idIterator.hasNext() && childIterator.hasNext()) {
       assertEquals(idIterator.next(), childIterator.next().getId());
     }
   }
 }
 @Test
 public void testGetContainerProperty_NonexistentProperty() {
   System.out.println("testGetContainerProperty_NonexistentItem");
   assertNull(
       container.getContainerProperty(
           serviceStub.getRootCategories().get(0).getId(), "nonexistent"));
 }
 @Test
 public void testAreChildrenAllowed() {
   System.out.println("testAreChildrenAllowed");
   for (Category root : serviceStub.getRootCategories()) {
     assertTrue(container.areChildrenAllowed(root.getId()));
     for (Category c : serviceStub.getChildren(root)) {
       /*
        * Even though it is legal to add children to any category,
        * this method should return false for categories without children
        * to make sure they show up as leaves.
        */
       assertFalse(container.areChildrenAllowed(c.getId()));
     }
   }
   assertFalse(container.areChildrenAllowed(-123l));
 }
 @Test
 public void testIsRoot() {
   System.out.println("testIsRoot");
   for (Category c : serviceStub.getRootCategories()) {
     assertTrue(container.isRoot(c.getId()));
   }
 }
 @Before
 public void setUp() {
   serviceStub = new CategoryServiceStub();
   createTestData(serviceStub);
   container = new CategoryContainer(serviceStub);
   container.refresh();
   assertFalse(serviceStub.getRootCategories().isEmpty());
 }
 @Test
 public void testSetChildrenAllowed() {
   System.out.println("testSetChildrenAllowed");
   for (Category root : serviceStub.getRootCategories()) {
     // The method is not implemented, should always return false
     assertFalse(container.setChildrenAllowed(root, true));
   }
 }
 @Test
 public void testGetItem() {
   System.out.println("testGetItem");
   for (Category root : serviceStub.getRootCategories()) {
     Item item = container.getItem(root.getId());
     assertEquals(root.getId(), item.getItemProperty("id").getValue());
     assertEquals(root.getVersion(), item.getItemProperty("version").getValue());
     assertEquals(root.getName(), item.getItemProperty("name").getValue());
     assertEquals(root.getDescription(), item.getItemProperty("description").getValue());
     assertNull(item.getItemProperty("parent").getValue());
     for (Category c : serviceStub.getChildren(root)) {
       Item childItem = container.getItem(c.getId());
       // Assume the rest of the properties are working
       assertEquals(c.getParent(), childItem.getItemProperty("parent").getValue());
     }
   }
 }
 @Test
 public void testRootItemIds() {
   System.out.println("testRootItemIds");
   Collection<Long> rootItemIds = container.rootItemIds();
   assertFalse(rootItemIds.isEmpty());
   for (Category c : serviceStub.getRootCategories()) {
     assertTrue(rootItemIds.contains(c.getId()));
   }
 }