KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sablecc > sablecc > exception > InvalidArgumentRuntimeExceptionTest


1 /* This file is part of SableCC ( http://sablecc.org ).
2  *
3  * Copyright 2007 Raymond Audet <raymond.audet@gmail.com>
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.sablecc.sablecc.exception;
19
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.fail;
22
23 import org.junit.Before;
24 import org.junit.Test;
25
26 public class InvalidArgumentRuntimeExceptionTest {
27
28     InvalidArgumentRuntimeException exception;
29
30     String JavaDoc message;
31
32     Throwable JavaDoc cause;
33
34     @Before
35     public void setUp() {
36
37         this.message = "valid message";
38         this.cause = new Throwable JavaDoc();
39     }
40
41     @Test
42     public void testInvalidArgumentRuntimeExceptionString() {
43
44         // Case with null message
45
String JavaDoc nullMessage = null;
46         try {
47             this.exception = new InvalidArgumentRuntimeException(nullMessage);
48             fail("message may not be null");
49         }
50         catch (InternalException e) {
51             // Expected
52
}
53
54         // Typical case
55
this.exception = new InvalidArgumentRuntimeException(this.message);
56         assertEquals("Invalid exception message", this.message, this.exception
57                 .getMessage());
58     }
59
60     @Test
61     public void testInvalidArgumentRuntimeExceptionStringThrowable() {
62
63         // Case with null message
64
String JavaDoc nullMessage = null;
65
66         try {
67             this.exception = new InvalidArgumentRuntimeException(nullMessage,
68                     this.cause);
69             fail("message may not be null");
70         }
71         catch (InternalException e) {
72             // Expected
73
}
74
75         // Case with null cause
76
Throwable JavaDoc nullCause = null;
77         try {
78             this.exception = new InvalidArgumentRuntimeException(this.message,
79                     nullCause);
80             fail("a cause may not be null");
81         }
82         catch (InternalException e) {
83             // Expected
84
}
85
86         // Typical case
87
this.exception = new InvalidArgumentRuntimeException(this.message,
88                 this.cause);
89         assertEquals("Invalid exception message", this.message, this.exception
90                 .getMessage());
91         assertEquals("Invalid exception cause", this.cause, this.exception
92                 .getCause());
93     }
94
95 }
96
Popular Tags