@@ -0,0 +1,2130 @@
+package uk.org.taverna.scufl2.api;%0A%0Aimport static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertTrue;%0Aimport static org.junit.Assert.fail;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.HashSet;%0Aimport java.util.List;%0A%0Aimport org.junit.Test;%0A%0Aimport uk.org.taverna.scufl2.api.common.Child;%0Aimport uk.org.taverna.scufl2.api.common.Visitor;%0Aimport uk.org.taverna.scufl2.api.common.WorkflowBean;%0Aimport uk.org.taverna.scufl2.api.container.WorkflowBundle;%0Aimport uk.org.taverna.scufl2.api.property.PropertyObject;%0A%0Apublic class VisitorTest %7B%0A%09@Test%0A%09public void visitAll() throws Exception %7B%0A%0A%09%09final List%3CWorkflowBean%3E enters = new ArrayList%3CWorkflowBean%3E();%0A%09%09final List%3CWorkflowBean%3E leaves = new ArrayList%3CWorkflowBean%3E();%0A%09%09final List%3CWorkflowBean%3E visits = new ArrayList%3CWorkflowBean%3E();%0A%0A%09%09WorkflowBundle example = new ExampleWorkflow().makeWorkflowBundle();%0A%0A%09%09example.accept(new Visitor() %7B%0A%09%09%09@Override%0A%09%09%09public boolean visit(WorkflowBean node) %7B%0A%09%09%09%09visits.add(node);%0A%09%09%09%09if (node instanceof Child) %7B%0A%09%09%09%09%09Child child = (Child) node;%0A%09%09%09%09%09assertTrue(enters.contains(child.getParent()));%0A%09%09%09%09%7D%0A%09%09%09%09return true;%0A%09%09%09%7D%0A%0A%09%09%09@Override%0A%09%09%09public boolean visitEnter(WorkflowBean node) %7B%0A%09%09%09%09if (enters.contains(node)) %7B%0A%09%09%09%09%09fail(%22Duplicate enter on %22 + node);%0A%09%09%09%09%7D%0A%09%09%09%09if (leaves.contains(node)) %7B%0A%09%09%09%09%09fail(%22Leave before enter on %22 + node);%0A%09%09%09%09%7D%0A%0A%09%09%09%09enters.add(node);%0A%09%09%09%09return true;%0A%09%09%09%7D%0A%0A%09%09%09@Override%0A%09%09%09public boolean visitLeave(WorkflowBean node) %7B%0A%09%09%09%09leaves.add(node);%0A%09%09%09%09assertTrue(enters.contains(node));%0A%09%09%09%09return true;%0A%09%09%09%7D%0A%09%09%7D);%0A%09%09assertEquals(enters.size(), leaves.size());%0A%09%09HashSet entersSet = new HashSet(enters);%0A%09%09HashSet leavesSet = new HashSet(leaves);%0A%09%09assertEquals(entersSet, leavesSet);%0A%09%09assertEquals(enters.size(), entersSet.size());%0A%0A%09%09for (WorkflowBean b : visits) %7B%0A%09%09%09if (b instanceof Child) %7B%0A%09%09%09%09@SuppressWarnings(%22rawtypes%22)%0A%09%09%09%09Child child = (Child) b;%0A%09%09%09%09WorkflowBean parent = child.getParent();%0A%09%09%09%09assertTrue(%22%22, enters.contains(parent));%0A%09%09%09%7D else %7B%0A%09%09%09%09assertTrue(%22Bean is not a PropertyObject or Child: %22 + b,%0A%09%09%09%09%09%09b instanceof PropertyObject);%0A%09%09%09%7D%0A%09%09%7D%0A%0A%09%7D%0A%7D%0A

Test visitor