View Javadoc
1   package org.junit.tests.listening;
2   
3   import static org.junit.Assert.assertEquals;
4   
5   import org.junit.Test;
6   import org.junit.runner.Description;
7   import org.junit.runner.JUnitCore;
8   import org.junit.runner.notification.RunListener;
9   
10  public class ListenerTest {
11      static private String log;
12  
13      public static class OneTest {
14          @Test
15          public void nothing() {
16          }
17      }
18  
19      @Test
20      public void notifyListenersInTheOrderInWhichTheyAreAdded() {
21          JUnitCore core = new JUnitCore();
22          log = "";
23          core.addListener(new RunListener() {
24              @Override
25              public void testRunStarted(Description description) throws Exception {
26                  log += "first ";
27              }
28          });
29          core.addListener(new RunListener() {
30              @Override
31              public void testRunStarted(Description description) throws Exception {
32                  log += "second ";
33              }
34          });
35          core.run(OneTest.class);
36          assertEquals("first second ", log);
37      }
38  }