OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / libcore / luni / src / test / java / tests / api / org / xml / sax / SAXExceptionTest.java
1 /*
2  * Copyright (C) 2007 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package tests.api.org.xml.sax;
18
19 import junit.framework.TestCase;
20
21 import org.xml.sax.SAXException;
22 import org.xml.sax.SAXParseException;
23
24 import dalvik.annotation.TestLevel;
25 import dalvik.annotation.TestTargetClass;
26 import dalvik.annotation.TestTargetNew;
27
28 @TestTargetClass(SAXException.class)
29 public class SAXExceptionTest extends TestCase {
30
31     public static final String ERR = "Houston, we have a problem";
32
33     @TestTargetNew(
34         level = TestLevel.COMPLETE,
35         method = "SAXException",
36         args = { }
37     )
38     public void testSAXParseException() {
39         SAXException e = new SAXException();
40
41         assertNull(e.getMessage());
42         assertNull(e.getException());
43     }
44
45     @TestTargetNew(
46         level = TestLevel.COMPLETE,
47         method = "SAXException",
48         args = { String.class, Exception.class }
49     )
50     public void testSAXException_String_Exception() {
51         Exception c = new Exception();
52
53         // Ordinary case
54         SAXException e = new SAXException(ERR, c);
55
56         assertEquals(ERR, e.getMessage());
57         assertEquals(c, e.getException());
58
59         // No message
60         e = new SAXException(null, c);
61
62         assertNull(e.getMessage());
63         assertEquals(c, e.getException());
64
65         // No cause
66         e = new SAXParseException(ERR, null);
67
68         assertEquals(ERR, e.getMessage());
69         assertNull(e.getException());
70     }
71
72     @TestTargetNew(
73         level = TestLevel.COMPLETE,
74         method = "SAXException",
75         args = { String.class }
76     )
77     public void testSAXException_String() {
78         // Ordinary case
79         SAXException e = new SAXException(ERR);
80
81         assertEquals(ERR, e.getMessage());
82         assertNull(e.getException());
83
84         // No message
85         e = new SAXException((String)null);
86
87         assertNull(e.getMessage());
88         assertNull(e.getException());
89     }
90
91     @TestTargetNew(
92         level = TestLevel.COMPLETE,
93         method = "SAXException",
94         args = { Exception.class }
95     )
96     public void testSAXException_Exception() {
97         Exception c = new Exception();
98
99         // Ordinary case
100         SAXException e = new SAXException(c);
101
102         assertNull(e.getMessage());
103         assertEquals(c, e.getException());
104
105         // No cause
106         e = new SAXException((Exception)null);
107
108         assertNull(e.getMessage());
109         assertNull(e.getException());
110     }
111
112     @TestTargetNew(
113         level = TestLevel.COMPLETE,
114         method = "toString",
115         args = { }
116     )
117     public void testToString() {
118         // Ordinary case
119         SAXException e = new SAXException(ERR);
120         String s = e.toString();
121
122         assertTrue(s.contains(ERR));
123
124         // No message
125         e = new SAXException();
126         s = e.toString();
127
128         assertFalse(s.contains(ERR));
129    }
130
131 }