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