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