01: package test.pholser;
02:
03: import java.util.Arrays;
04: import java.util.Iterator;
05: import java.util.List;
06:
07: /**
08: * @author <a href="mailto:pholser@thoughtworks.com">Paul Holser</a>
09: * @version $Id: Demo.java,v 1.3 2006/06/23 10:11:04 cedric Exp $
10: */
11: public class Demo {
12: /**
13: * @testng.before-class
14: */
15: public void setUpFixture() {
16: Captor.reset();
17: Captor.instance().capture("Demo.setUpFixture");
18: }
19:
20: /**
21: * @testng.before-method
22: */
23: public void setUp() {
24: Captor.instance().capture("Demo.setUp");
25: }
26:
27: /**
28: * @testng.after-method
29: */
30: public void tearDown() {
31: Captor.instance().capture("Demo.tearDown");
32: }
33:
34: /**
35: * @testng.after-class
36: */
37: public void tearDownFixture() {
38: final List expected = Arrays.asList(new String[] {
39: "Demo.setUpFixture", "Demo.setUp", "Demo.tearDown" });
40: final List actual = Captor.instance().captives();
41: verify(expected, actual);
42: }
43:
44: /**
45: * @testng.test
46: */
47: public void go() {
48: final List expected = Arrays.asList(new String[] {
49: "Demo.setUpFixture", "Demo.setUp" });
50: final List actual = Captor.instance().captives();
51: verify(expected, actual);
52: }
53:
54: private void verify(List expected, List actual) {
55: if (!expected.equals(actual)) {
56: throw new AssertionError("\nExpected:" + dumpList(expected)
57: + "\n Got:" + dumpList(actual));
58: }
59: }
60:
61: private String dumpList(List list) {
62: StringBuffer result = new StringBuffer();
63: for (Iterator it = list.iterator(); it.hasNext();) {
64: result.append(" " + it.next());
65: }
66:
67: return result.toString();
68: }
69: }
|