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.sdedit;
24
25 import java.io.StringWriter;
26 import java.util.regex.Matcher;
27 import java.util.regex.Pattern;
28
29 import th.co.edge.jseq.ActivationList;
30 import th.co.edge.jseq.ActivationListTest;
31 import junit.framework.TestCase;
32
33 public class SdeditTextDiagramTest extends TestCase {
34 public void testWriteDiagram() throws Exception {
35 ActivationList rootActivations = ActivationListTest.buildActivationList();
36 SdeditTextDiagram diagram = new SdeditTextDiagram(rootActivations);
37 StringWriter writer = new StringWriter();
38 diagram.writeDiagram(writer);
39 String sdedit = writer.toString();
40 assertEquals(1, numOccurrences("Scenarios", sdedit));
41 assertEquals(1, numOccurrences("Foo", sdedit));
42 assertEquals(1, numOccurrences("Bar", sdedit));
43 assertEquals(1, numOccurrences("\\.testWithdrawal", sdedit));
44 assertEquals(2, numOccurrences("\\.<init>", sdedit));
45 assertEquals(5, numOccurrences("\\.frotz", sdedit));
46 assertEquals(1, numOccurrences("\\.bar", sdedit));
47 assertEquals(1, numOccurrences("\\.baz", sdedit));
48 }
49
50 private int numOccurrences(String regex, String s) {
51 Pattern pattern = Pattern.compile(regex);
52 Matcher matcher = pattern.matcher(s);
53 int numOccurrences = 0;
54 int start = 0;
55 while (matcher.find(start)) {
56 numOccurrences++;
57 start = matcher.start() + 1;
58 }
59 return numOccurrences;
60 }
61 }