1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.scxml.semantics;
17
18 import org.apache.commons.scxml.model.State;
19 import org.apache.commons.scxml.model.TransitionTarget;
20
21 import junit.framework.Test;
22 import junit.framework.TestCase;
23 import junit.framework.TestSuite;
24
25 public class TransitionTargetComparatorTest extends TestCase {
26
27 public TransitionTargetComparatorTest(String testName) {
28 super(testName);
29 }
30
31 public static Test suite() {
32 return new TestSuite(TransitionTargetComparatorTest.class);
33 }
34
35 public static void main(String args[]) {
36 String[] testCaseName = { TransitionTargetComparatorTest.class.getName()};
37 junit.textui.TestRunner.main(testCaseName);
38 }
39
40 private TransitionTargetComparator comparator;
41
42 public void setUp() {
43 comparator = new TransitionTargetComparator();
44 }
45
46 public void testComparatorEquals() {
47 TransitionTarget target = new State();
48
49 assertEquals(0, comparator.compare(target, target));
50 }
51
52 public void testComparatorNegative() {
53 TransitionTarget target1 = new State();
54 TransitionTarget target2 = new State();
55
56 target1.setParent(target2);
57
58 assertEquals(-1, comparator.compare(target1, target2));
59 }
60
61 public void testComparatorPositive() {
62 TransitionTarget target1 = new State();
63 TransitionTarget target2 = new State();
64
65 target2.setParent(target1);
66
67 assertEquals(1, comparator.compare(target1, target2));
68 }
69
70 public void testComparatorFirstMoreParents() {
71 TransitionTarget target1 = new State();
72 TransitionTarget parent1 = new State();
73 TransitionTarget parent2 = new State();
74
75 parent1.setParent(parent2);
76 target1.setParent(parent1);
77
78 TransitionTarget target2 = new State();
79 TransitionTarget parent3 = new State();
80
81 target2.setParent(parent3);
82
83 assertEquals(-1, comparator.compare(target1, target2));
84 }
85
86 public void testComparatorSecondMoreParents() {
87 TransitionTarget target1 = new State();
88 TransitionTarget parent1 = new State();
89 TransitionTarget parent2 = new State();
90
91 parent1.setParent(parent2);
92 target1.setParent(parent1);
93
94 TransitionTarget target2 = new State();
95 TransitionTarget parent3 = new State();
96
97 target2.setParent(parent3);
98
99 assertEquals(1, comparator.compare(target2, target1));
100 }
101
102 public void testComparatorSameParents() {
103 TransitionTarget target1 = new State();
104 TransitionTarget parent1 = new State();
105
106 target1.setParent(parent1);
107
108 TransitionTarget target2 = new State();
109 TransitionTarget parent2 = new State();
110
111 target2.setParent(parent2);
112
113 assertEquals(0, comparator.compare(target1, target2));
114 }
115 }