01: package test.net.sourceforge.pmd.dfa;
02:
03: import static org.junit.Assert.assertEquals;
04: import static org.junit.Assert.assertFalse;
05: import static org.junit.Assert.assertTrue;
06: import net.sourceforge.pmd.dfa.DataFlowNode;
07: import net.sourceforge.pmd.dfa.IDataFlowNode;
08: import net.sourceforge.pmd.dfa.NodeType;
09: import net.sourceforge.pmd.dfa.StartOrEndDataFlowNode;
10:
11: import org.junit.Test;
12:
13: import java.util.LinkedList;
14:
15: public class DataFlowNodeTest {
16:
17: @Test
18: public void testAddPathToChild() {
19: DataFlowNode parent = new StartOrEndDataFlowNode(
20: new LinkedList<DataFlowNode>(), 10, false);
21: IDataFlowNode child = new StartOrEndDataFlowNode(
22: new LinkedList<DataFlowNode>(), 12, false);
23: parent.addPathToChild(child);
24: assertEquals(parent.getChildren().size(), 1);
25: assertTrue(child.getParents().contains(parent));
26: assertTrue(parent.getChildren().contains(child));
27: }
28:
29: @Test
30: public void testRemovePathToChild() {
31: DataFlowNode parent = new StartOrEndDataFlowNode(
32: new LinkedList<DataFlowNode>(), 10, false);
33: IDataFlowNode child = new StartOrEndDataFlowNode(
34: new LinkedList<DataFlowNode>(), 12, false);
35: parent.addPathToChild(child);
36:
37: assertTrue(parent.removePathToChild(child));
38: assertFalse(child.getParents().contains(parent));
39: assertFalse(parent.getChildren().contains(child));
40: }
41:
42: @Test
43: public void testRemovePathWithNonChild() {
44: DataFlowNode parent = new StartOrEndDataFlowNode(
45: new LinkedList<DataFlowNode>(), 10, false);
46: IDataFlowNode child = new StartOrEndDataFlowNode(
47: new LinkedList<DataFlowNode>(), 12, false);
48: assertFalse(parent.removePathToChild(child));
49: }
50:
51: @Test
52: public void testReverseParentPathsTo() {
53: DataFlowNode parent1 = new StartOrEndDataFlowNode(
54: new LinkedList<DataFlowNode>(), 10, false);
55: DataFlowNode parent2 = new StartOrEndDataFlowNode(
56: new LinkedList<DataFlowNode>(), 12, false);
57: IDataFlowNode child1 = new StartOrEndDataFlowNode(
58: new LinkedList<DataFlowNode>(), 13, false);
59: IDataFlowNode child2 = new StartOrEndDataFlowNode(
60: new LinkedList<DataFlowNode>(), 13, false);
61: parent1.addPathToChild(child1);
62: parent2.addPathToChild(child1);
63: assertTrue(parent1.getChildren().contains(child1));
64:
65: child1.reverseParentPathsTo(child2);
66: assertTrue(parent1.getChildren().contains(child2));
67: assertFalse(parent1.getChildren().contains(child1));
68: assertTrue(parent2.getChildren().contains(child2));
69: assertFalse(parent2.getChildren().contains(child1));
70:
71: assertEquals(0, child1.getParents().size());
72: assertEquals(2, child2.getParents().size());
73: }
74:
75: @Test
76: public void testSetType() {
77: DataFlowNode node = new StartOrEndDataFlowNode(
78: new LinkedList<DataFlowNode>(), 10, false);
79: node.setType(NodeType.BREAK_STATEMENT);
80: assertTrue(node.isType(NodeType.BREAK_STATEMENT));
81: assertFalse(node.isType(NodeType.CASE_LAST_STATEMENT));
82: }
83:
84: public static junit.framework.Test suite() {
85: return new junit.framework.JUnit4TestAdapter(
86: DataFlowNodeTest.class);
87: }
88: }
|