View Javadoc

1   package com.atlassian.johnson.event;
2   
3   import com.atlassian.johnson.Johnson;
4   import org.junit.After;
5   import org.junit.Before;
6   import org.junit.Test;
7   
8   import java.util.function.Supplier;
9   
10  import static com.atlassian.johnson.event.EventLevel.ERROR;
11  import static com.atlassian.johnson.event.EventLevel.FATAL;
12  import static com.atlassian.johnson.event.EventLevel.WARNING;
13  import static org.hamcrest.Matchers.is;
14  import static org.hamcrest.Matchers.notNullValue;
15  import static org.junit.Assert.assertThat;
16  
17  public class EventLevelsTest {
18  
19      @Before
20      @After
21      public void clearJohnsonConfig() {
22          Johnson.terminate();
23      }
24  
25      @Test(expected = IllegalStateException.class)
26      public void shouldNotBeAbleToGetFatalLevelIfJohnsonNotInitialised() {
27          // Invoke
28          EventLevels.fatal();
29      }
30  
31      @Test
32      public void shouldBeAbleToGetErrorLevelIfJohnsonInitialised() {
33          assertLevel(EventLevels::error, ERROR);
34      }
35  
36      @Test
37      public void shouldBeAbleToGetFatalLevelIfJohnsonInitialised() {
38          assertLevel(EventLevels::fatal, FATAL);
39      }
40  
41      @Test
42      public void shouldBeAbleToGetWarningLevelIfJohnsonInitialised() {
43          assertLevel(EventLevels::warning, WARNING);
44      }
45  
46      private static void assertLevel(final Supplier<EventLevel> eventLevelSupplier, final String expectedLevelName) {
47          // Set up
48          Johnson.initialize("test-johnson-config.xml");
49  
50          // Invoke
51          final EventLevel error = eventLevelSupplier.get();
52  
53          // Check
54          assertThat(error, notNullValue());
55          assertThat(error.getLevel(), is(expectedLevelName));
56      }
57  }