1 package test.methodinterceptors.multipleinterceptors;
2 
3 import java.util.Collections;
4 
5 import org.testng.Assert;
6 import org.testng.TestListenerAdapter;
7 import org.testng.TestNG;
8 import org.testng.annotations.Test;
9 
10 import test.SimpleBaseTest;
11 
12 public class MultipleInterceptorsTest extends SimpleBaseTest {
13 
14     @Test
testMultipleInterceptors()15     public void testMultipleInterceptors(){
16       TestNG tng = create(FooTest.class);
17       tng.setMethodInterceptor(new FirstInterceptor());
18       tng.setMethodInterceptor(new SecondInterceptor());
19       tng.setMethodInterceptor(new ThirdInterceptor());
20       TestListenerAdapter tla = new TestListenerAdapter();
21       tng.addListener(tla);
22       tng.run();
23       Assert.assertEquals(tla.getPassedTests().size(), 1);
24       Assert.assertEquals(tla.getPassedTests().get(0).getName(), "d");
25     }
26 
27     @Test
testMultipleInterceptorsWithPreserveOrder()28     public void testMultipleInterceptorsWithPreserveOrder() {
29       TestNG tng = create();
30       tng.setTestSuites(Collections.singletonList(
31           getPathToResource("/methodinterceptors/multipleinterceptors/multiple-interceptors.xml")));
32       TestListenerAdapter tla = new TestListenerAdapter();
33       tng.addListener(tla);
34       tng.run();
35       Assert.assertEquals(tla.getPassedTests().get(0).getMethod().getDescription(), "abc");
36     }
37 }
38