/** * Tests the {@link Iterator#remove()} operation on the given collection of children. * Elements are removed randomly until the collection is empty. After each removal, * the remaining elements are compared with the content of a standard Java collection. * * @param random a random number generator. * @param children the collection from which to remove elements. */ private static void testRemove(final Random random, final TreeNodeChildren children) { final List<TreeTable.Node> reference = new ArrayList<>(children); assertFalse("The collection shall not be initially empty.", reference.isEmpty()); do { final Iterator<TreeTable.Node> rit = reference.iterator(); // The reference iterator. final Iterator<TreeTable.Node> cit = children .iterator(); // The children iterator to be tested. while (rit.hasNext()) { assertTrue(cit.hasNext()); assertSame(rit.next(), cit.next()); if (random.nextInt(3) == 0) { // Remove only 1/3 of entries on each pass. rit.remove(); cit.remove(); assertAllNextEqual(reference.iterator(), children.iterator()); } } } while (!reference.isEmpty()); assertTrue(children.isEmpty()); } }
/** * Tests read-only operations on a list of properties for a shallow metadata object without collections. */ @Test public void testReadOnlyWithoutCollections() { final DefaultCitation citation = metadataWithoutCollections(); final TreeNodeChildren children = create(citation, ValueExistencePolicy.NON_EMPTY); final String[] expected = { "Some title", "Some edition", "Some other details" }; assertEquals("titleProperty", -1, children.titleProperty); assertFalse ("isEmpty()", children.isEmpty()); assertEquals("size()", expected.length, children.size()); assertAllNextEqual(expected, children.iterator()); }
/** * Tests read-only operations on a list of properties for a shallow metadata object with singleton * values in collections. */ @Test @DependsOnMethod("testReadOnlyWithoutCollections") public void testReadOnlyWithSingletonInCollections() { final DefaultCitation citation = metadataWithSingletonInCollections(); final TreeNodeChildren children = create(citation, ValueExistencePolicy.NON_EMPTY); final String[] expected = { "Some title", "First alternate title", "Some edition", "PresentationForm[MAP_DIGITAL]", "Some other details" }; assertEquals("titleProperty", -1, children.titleProperty); assertFalse ("isEmpty()", children.isEmpty()); assertEquals("size()", expected.length, children.size()); assertAllNextEqual(expected, children.iterator()); }
/** * Tests a metadata than can be simplified by displaying a child property value directly as the parent value. */ @Test @DependsOnMethod("testReadOnlyWithoutCollections") public void testSimplifiable() { final DefaultCitation citation = metadataSimplifiable(); /* * DefaultCitation * └─Date * ├─Date………………… 2012-01-01 * └─Date type…… Creation * * We need to perform the tests on the "Date" node, not on the "DefaultCitation" node. */ final TreeTable.Node node = TestUtilities.getSingleton(create(citation, ValueExistencePolicy.COMPACT)); assertEquals("value", 1325376000000L, ((Date) node.getValue(TableColumn.VALUE)).getTime()); final TreeNodeChildren children = (TreeNodeChildren) node.getChildren(); final String[] expected = { // The "Date" node should be omitted because merged with the parent "Date" node. "DateType[CREATION]" }; assertEquals("titleProperty", 0, children.titleProperty); assertFalse ("isEmpty()", children.isEmpty()); assertEquals("size()", expected.length, children.size()); assertAllNextEqual(expected, children.iterator()); }
/** * Tests read-only operations on a list of properties for a shallow metadata object with more * than one values in collections. */ @Test @DependsOnMethod("testReadOnlyWithSingletonInCollections") public void testReadOnlyWithMultiOccurrences() { final DefaultCitation citation = metadataWithMultiOccurrences(); final TreeNodeChildren children = create(citation, ValueExistencePolicy.NON_EMPTY); final String[] expected = { "Some title", "First alternate title", "Second alternate title", "Some edition", "PresentationForm[MAP_DIGITAL]", "PresentationForm[MAP_HARDCOPY]", "Some other details" }; assertEquals("titleProperty", -1, children.titleProperty); assertFalse ("isEmpty()", children.isEmpty()); assertEquals("size()", expected.length, children.size()); assertAllNextEqual(expected, children.iterator()); }
assertFalse ("isEmpty()", children.isEmpty()); assertEquals("size()", expected.length, children.size()); assertAllNextEqual(expected, children.iterator());
/** * Tests the properties of the root node. */ @Test public void testRootNode() { final DefaultCitation citation = TreeNodeChildrenTest.metadataWithoutCollections(); final TreeNode node = create(citation, Citation.class); assertEquals("getName()", "Citation", node.getName()); assertEquals("getIdentifier()", "CI_Citation", node.getIdentifier()); assertEquals("baseType", Citation.class, node.baseType); assertSame ("getUserObject()", citation, node.getUserObject()); assertFalse ("isWritable()", node.isWritable()); assertNull ("getParent()", node.getParent()); assertFalse ("isLeaf()", node.isLeaf()); final TreeNodeChildren children = (TreeNodeChildren) node.getChildren(); assertEquals("children.titleProperty", -1, children.titleProperty); assertSame ("children.metadata", citation, children.metadata); assertFalse ("children.isEmpty()", node.getChildren().isEmpty()); assertSame ("children.parent", node, children.iterator().next().getParent()); }
assertAllNextEqual(expected, children.iterator());