1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package th.co.edge.jseq;
24
25 import junit.framework.Test;
26 import junit.framework.TestCase;
27 import junit.framework.TestSuite;
28
29 public class ActivationListTest extends TestCase {
30 public ActivationListTest(String name) {
31 super(name);
32 }
33
34 public static Test suite() {
35 TestSuite suite = new TestSuite(ActivationListTest.class);
36 return suite;
37 }
38
39
40
41
42
43 public void testFilter() {
44 ActivationList list = buildActivationList();
45 ActivationList filteredList = list.filter(new ClassExclusionFilter(
46 "Bar.*"));
47 assertEquals(1, filteredList.size());
48 Activation root = filteredList.get(0);
49 assertEquals(3, root.getNumCalls());
50 Activation fooInit = root.getNestedActivations().get(0);
51 assertEquals(0, fooInit.getNumCalls());
52 }
53
54 public void testFind() {
55 ActivationList list = buildActivationList();
56 ActivationList filteredList = list.find(new MethodFilter("Foo.<init>"));
57 assertEquals(1, filteredList.size());
58 Activation root = filteredList.get(0);
59 assertEquals(6, root.getNumCalls());
60 Activation fooInit = root.getNestedActivations().get(0);
61 assertEquals(0, fooInit.getNumCalls());
62 }
63
64 public void testCopy() {
65 ActivationList list = buildActivationList();
66 ActivationList copy = list.copy();
67 assertEquals(list, copy);
68 }
69
70 public void testCollapseRepetitions() {
71 ActivationList list = buildActivationList();
72
73 int numCallsByFooInit = list.get(0).getNestedActivations().get(0)
74 .getNumCalls();
75 assertEquals(6, numCallsByFooInit);
76 ActivationList noRepetitions = list.collapseRepetitions();
77
78 numCallsByFooInit = noRepetitions.get(0).getNestedActivations().get(0)
79 .getNumCalls();
80 assertEquals(2, numCallsByFooInit);
81 }
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106 public static ActivationList buildActivationList() {
107 Activation root = new Activation(null, "Scenarios", new TestMethodImpl(
108 "testWithdrawal"), -1);
109 Activation fooInit = new Activation(root, "Foo", new TestMethodImpl(
110 "<init>", true), -1);
111 new Activation(fooInit, "Bar", new TestMethodImpl("<init>", true), -1);
112 new Activation(fooInit, "Bar", new TestMethodImpl("frotz"), -1);
113 new Activation(fooInit, "Bar", new TestMethodImpl("frotz"), -1);
114 new Activation(fooInit, "Bar", new TestMethodImpl("frotz"), -1);
115 new Activation(fooInit, "Bar", new TestMethodImpl("frotz"), -1);
116 new Activation(fooInit, "Bar", new TestMethodImpl("frotz"), -1);
117
118 new Activation(root, "Foo", new TestMethodImpl("bar"), -1);
119 new Activation(root, "Foo", new TestMethodImpl("baz"), -1);
120 ActivationList list = new ActivationList();
121 list.add(root);
122 return list;
123 }
124 }