* Tests the {@link TreeNodeChildren#add(TreeTable.Node)} method.
*/
@Test
@DependsOnMethod("testReadOnlyWithMultiOccurrences")
public void testAdd() {
final DefaultCitation citation = metadataWithMultiOccurrences();
final TreeNodeChildren children = create(citation, ValueExistencePolicy.NON_EMPTY);
final DefaultTreeTable.Node toAdd = new DefaultTreeTable.Node(new DefaultTreeTable(
TableColumn.IDENTIFIER,
TableColumn.VALUE));
final String[] expected = {
"Some title",
"First alternate title",
"Second alternate title",
"Third alternate title", // After addition
"New edition", // After "addition" (actually change).
"PresentationForm[IMAGE_DIGITAL]", // After addition
"PresentationForm[MAP_DIGITAL]",
"PresentationForm[MAP_HARDCOPY]",
"Some other details"
};
toAdd.setValue(TableColumn.IDENTIFIER, "edition");
toAdd.setValue(TableColumn.VALUE, citation.getEdition());
assertFalse("Adding the same value shall be a no-op.", children.add(toAdd));
toAdd.setValue(TableColumn.VALUE, "New edition");
try {
children.add(toAdd);
fail("Setting a different value shall be refused.");
} catch (IllegalStateException e) {
assertTrue(e.getMessage().contains("edition"));
}
citation.setEdition(null); // Clears so we are allowed to add.
assertTrue("Setting a new value shall be a change.", children.add(toAdd));
toAdd.setValue(TableColumn.IDENTIFIER, "presentationForm");
toAdd.setValue(TableColumn.VALUE, PresentationForm.MAP_DIGITAL);
assertFalse("Adding the same value shall be a no-op.", children.add(toAdd));