1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.scxml.env;
18
19 import java.net.URL;
20
21 import junit.framework.Test;
22 import junit.framework.TestCase;
23 import junit.framework.TestSuite;
24 import junit.textui.TestRunner;
25
26 /***
27 * Unit tests {@link org.apache.commons.scxml.env.AbstractStateMachine}.
28 */
29 public class AbstractStateMachineTest extends TestCase {
30
31 /***
32 * Construct a new instance of AbstractStateMachineTest with the specified name
33 */
34 public AbstractStateMachineTest(String name) {
35 super(name);
36 }
37
38 public void testMoreThanOneScxmlDocument() throws Exception {
39 URL fooScxmlDocument = getClass().getResource("foo.xml");
40 URL barScxmlDocument = getClass().getResource("bar.xml");
41
42 Foo f = new Foo(fooScxmlDocument);
43 Bar b = new Bar(barScxmlDocument);
44
45 assertTrue(f.fooCalled());
46 assertTrue(b.barCalled());
47 }
48
49 private class Foo extends AbstractStateMachine {
50
51 private boolean fooCalled;
52
53 public Foo(final URL scxmlDocument) {
54 super(scxmlDocument);
55 }
56
57 public void foo() {
58 fooCalled = true;
59 }
60
61 public boolean fooCalled() {
62 return fooCalled;
63 }
64 }
65
66 private class Bar extends AbstractStateMachine {
67
68 private boolean barCalled;
69
70 public Bar(final URL scxmlDocument) {
71 super(scxmlDocument);
72 }
73
74 public void bar() {
75 barCalled = true;
76 }
77
78 public boolean barCalled() {
79 return barCalled;
80 }
81 }
82
83 public static Test suite() {
84 TestSuite suite = new TestSuite(AbstractStateMachineTest.class);
85 suite.setName("AbstractStateMachine Tests");
86 return suite;
87 }
88
89 public static void main(String args[]) {
90 TestRunner.run(suite());
91 }
92 }