View Javadoc
1   package com.atlassian.plugin.event;
2   
3   import org.junit.Test;
4   
5   import java.util.ArrayList;
6   import java.util.List;
7   
8   import static org.junit.Assert.assertEquals;
9   
10  /**
11   * @since 2.3.0
12   */
13  @SuppressWarnings({"ThrowableResultOfMethodCallIgnored", "ThrowableInstanceNeverThrown"})
14  public class TestNotificationException {
15  
16      @Test
17      public void testSingletonConstructor() {
18          Exception cause = new Exception("I don't like it");
19          NotificationException notificationException = new NotificationException(cause);
20  
21          assertEquals(cause, notificationException.getCause());
22          assertEquals(1, notificationException.getAllCauses().size());
23          assertEquals(cause, notificationException.getAllCauses().get(0));
24      }
25  
26      @Test
27      public void testListConstructor() {
28          Exception cause1 = new Exception("I don't like it");
29          Exception cause2 = new Exception("Me neither");
30          final List<Throwable> causes = new ArrayList<>();
31          causes.add(cause1);
32          causes.add(cause2);
33  
34          NotificationException notificationException = new NotificationException(causes);
35  
36          assertEquals(cause1, notificationException.getCause());
37          assertEquals(2, notificationException.getAllCauses().size());
38          assertEquals(cause1, notificationException.getAllCauses().get(0));
39          assertEquals(cause2, notificationException.getAllCauses().get(1));
40      }
41  
42      @Test(expected = NullPointerException.class)
43      public void testListConstructorThrowsForNullCauses() {
44          new NotificationException((List) null);
45      }
46  
47      @Test(expected = IndexOutOfBoundsException.class)
48      public void testListConstructorForEmptyCauses() {
49          new NotificationException(new ArrayList<>());
50      }
51  }