1 package org.itracker.services.exceptions;
2
3 import org.junit.Test;
4
5 import junit.framework.TestCase;
6
7 public class AuthenticatorExceptionTest extends TestCase {
8
9 @Test
10 public void testConstructor() {
11 AuthenticatorException e = new AuthenticatorException();
12 assertTrue(e instanceof Exception);
13
14 e = new AuthenticatorException(1);
15 assertEquals("e.type", 1, e.getType());
16
17 e = new AuthenticatorException(1, "my_key");
18 assertEquals("e.type", 1, e.getType());
19 assertEquals("e.messageKey", "my_key", e.getMessageKey());
20
21 e = new AuthenticatorException("my_message", 1);
22 assertEquals("e.message", "my_message", e.getMessage());
23 assertEquals("e.type", 1, e.getType());
24
25 e = new AuthenticatorException("my_message", 1, "my_key");
26 assertEquals("e.message", "my_message", e.getMessage());
27 assertEquals("e.messageKey", "my_key", e.getMessageKey());
28 assertEquals("e.type", 1, e.getType());
29
30 Throwable cause = new Throwable();
31 e = new AuthenticatorException("my_message", 1, cause);
32 assertEquals("e.message", "my_message", e.getMessage());
33 assertEquals("e.type", 1, e.getType());
34 assertSame("e.cause", cause, e.getCause());
35
36
37 }
38
39
40 @Test
41 public void testSetErrorPageType() {
42 AuthenticatorException e = new AuthenticatorException();
43 e.setErrorPageType(10);
44 assertEquals("e.errorPageType", 10, e.getErrorPageType());
45 }
46
47 @Test
48 public void testSetErrorPageValue() {
49 AuthenticatorException e = new AuthenticatorException();
50 e.setErrorPageValue("my_value");
51 assertEquals("e.errorPageValue", "my_value", e.getErrorPageValue());
52 }
53
54 @Test
55 public void testSetMessageKey() {
56 AuthenticatorException e = new AuthenticatorException();
57 e.setMessageKey("my_key");
58 assertEquals("e.messageKey", "my_key", e.getMessageKey());
59 }
60
61 @Test
62 public void testSetType() {
63 AuthenticatorException e = new AuthenticatorException();
64 e.setType(1);
65 assertEquals("e.type", 1, e.getType());
66 }
67
68 @Test
69 public void testGetMessage() {
70 AuthenticatorException e = new AuthenticatorException();
71 for (int j=-7; j<=2; j++) {
72 e.setType(j);
73 assertNotNull("e.message", e.getMessage());
74 }
75 }
76 }
77