1   package com.atlassian.security.auth.trustedapps;
2   
3   import com.atlassian.security.auth.trustedapps.TransportErrorMessage.Code;
4   
5   import junit.framework.TestCase;
6   
7   public class TestTransportErrorCtors extends TestCase
8   {
9       public void testNullCodeCtor() throws Exception
10      {
11          try
12          {
13              new TransportErrorMessage(null, "message", new String[] { "param" });
14              fail("Exception expected");
15          }
16          catch (RuntimeException expected)
17          {
18          }
19      }
20  
21      public void testNullSingleMessageCtor() throws Exception
22      {
23          try
24          {
25              new TransportErrorMessage(Code.SYSTEM, null, new String[] { "param" });
26              fail("Exception expected");
27          }
28          catch (RuntimeException expected)
29          {
30          }
31      }
32  
33      public void testNullStringArrayCtor() throws Exception
34      {
35          try
36          {
37              new TransportErrorMessage(Code.SYSTEM, "message", (String[]) null);
38              fail("Exception expected");
39          }
40          catch (RuntimeException expected)
41          {
42          }
43      }
44  
45      public void testStringArrayContainsNullCtor() throws Exception
46      {
47          try
48          {
49              new TransportErrorMessage(Code.SYSTEM, "message", new String[] { "one", null });
50              fail("Exception expected");
51          }
52          catch (RuntimeException expected)
53          {
54          }
55      }
56  
57      public void testNullSingleStringCtor() throws Exception
58      {
59          try
60          {
61              new TransportErrorMessage(Code.SYSTEM, "message", (String) null);
62              fail("Exception expected");
63          }
64          catch (RuntimeException expected)
65          {
66          }
67      }
68  
69      public void testNullSecondStringCtor() throws Exception
70      {
71          try
72          {
73              new TransportErrorMessage(Code.SYSTEM, "message", "one", null);
74              fail("Exception expected");
75          }
76          catch (RuntimeException expected)
77          {
78          }
79      }
80  
81      public void testNullThirdStringCtor() throws Exception
82      {
83          try
84          {
85              new TransportErrorMessage(Code.SYSTEM, "message", "one", "two", null);
86              fail("Exception expected");
87          }
88          catch (RuntimeException expected)
89          {
90          }
91      }
92  
93      public void testCtorWorks() throws Exception
94      {
95          TransportErrorMessage message = new TransportErrorMessage(Code.UNKNOWN, "what is happening? {0}", new String[] {"dunno"});
96          assertNotNull(message.getCode());
97          assertSame(Code.UNKNOWN, message.getCode());
98          assertSame(Code.Severity.ERROR, message.getCode().getSeverity());
99          assertEquals("ERROR", message.getCode().getSeverity().toString());
100 
101         assertNotNull(message.getFormattedMessage());
102         assertEquals("what is happening? dunno", message.getFormattedMessage());
103 
104         assertNotNull(message.getParameters());
105         assertEquals(1, message.getParameters().length);
106         assertEquals("dunno", message.getParameters()[0]);
107     }
108 }