1 package test.pholser; 2 3 import org.testng.annotations.AfterClass; 4 import org.testng.annotations.AfterMethod; 5 import org.testng.annotations.BeforeClass; 6 import org.testng.annotations.BeforeMethod; 7 import org.testng.annotations.Test; 8 9 import java.util.Arrays; 10 import java.util.List; 11 12 /** 13 * @author <a href="mailto:pholser@thoughtworks.com">Paul Holser</a> 14 * @version $Id: Demo.java,v 1.5 2006/06/22 13:45:01 cedric Exp $ 15 */ 16 public class Demo { 17 @BeforeClass setUpFixture()18 public void setUpFixture() { 19 Captor.reset(); 20 Captor.instance().capture( "Demo.setUpFixture" ); 21 } 22 23 @BeforeMethod setUp()24 public void setUp() { 25 Captor.instance().capture( "Demo.setUp" ); 26 } 27 28 @AfterMethod tearDown()29 public void tearDown() { 30 Captor.instance().capture( "Demo.tearDown" ); 31 } 32 33 @AfterClass tearDownFixture()34 public void tearDownFixture() { 35 final List<String> expected = Arrays.asList(new String[] { "Demo.setUpFixture", "Demo.setUp", "Demo.tearDown" }); 36 final List<String> actual = Captor.instance().captives(); 37 verify(expected, actual); 38 } 39 40 @Test go()41 public void go() { 42 final List<String> expected = Arrays.asList(new String[] { "Demo.setUpFixture", "Demo.setUp" } ); 43 final List<String> actual = Captor.instance().captives(); 44 verify(expected, actual); 45 } 46 verify(List<String> expected, List<String> actual)47 private void verify(List<String> expected, List<String> actual) { 48 if (! expected.equals(actual)) { 49 throw new AssertionError("\nExpected:" + dumpList(expected) + "\n Got:" + dumpList(actual)); 50 } 51 } 52 dumpList(List<String> list)53 private String dumpList(List<String> list) { 54 StringBuffer result = new StringBuffer(); 55 for (String l : list) { 56 result.append(" " + l); 57 } 58 59 return result.toString(); 60 } 61 }