OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / libcore / luni / src / test / java / tests / api / javax / xml / parsers / FactoryConfigurationErrorTest.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 package tests.api.javax.xml.parsers;
17
18 import javax.xml.parsers.FactoryConfigurationError;
19
20 import junit.framework.TestCase;
21 import dalvik.annotation.TestLevel;
22 import dalvik.annotation.TestTargetClass;
23 import dalvik.annotation.TestTargetNew;
24
25 @TestTargetClass(FactoryConfigurationError.class)
26 public class FactoryConfigurationErrorTest extends TestCase {
27
28     @TestTargetNew(
29         level = TestLevel.COMPLETE,
30         notes = "",
31         method = "FactoryConfigurationError",
32         args = {}
33     )
34     public void test_Constructor() {
35         FactoryConfigurationError fce = new FactoryConfigurationError();
36         assertNull(fce.getMessage());
37         assertNull(fce.getLocalizedMessage());
38         assertNull(fce.getCause());
39     }
40
41     @TestTargetNew(
42         level = TestLevel.COMPLETE,
43         notes = "",
44         method = "FactoryConfigurationError",
45         args = {java.lang.Exception.class}
46     )
47     public void test_ConstructorLjava_lang_Exception() {
48         Exception e = new Exception();
49         // case 1: Try to create FactoryConfigurationError
50         // which is based on Exception without parameters.
51         FactoryConfigurationError fce = new FactoryConfigurationError(e);
52         assertNotNull(fce.getMessage());
53         assertNotNull(fce.getLocalizedMessage());
54         assertEquals(e.getCause(), fce.getCause());
55
56         // case 2: Try to create FactoryConfigurationError
57         // which is based on Exception with String parameter.
58         e = new Exception("test message");
59         fce = new FactoryConfigurationError(e);
60         assertEquals(e.toString(), fce.getMessage());
61         assertEquals(e.toString(), fce.getLocalizedMessage());
62         assertEquals(e.getCause(), fce.getCause());
63     }
64
65     @TestTargetNew(
66         level = TestLevel.COMPLETE,
67         notes = "",
68         method = "FactoryConfigurationError",
69         args = {java.lang.Exception.class, java.lang.String.class}
70     )
71     public void test_ConstructorLjava_lang_ExceptionLjava_lang_String() {
72         Exception e = new Exception();
73         // case 1: Try to create FactoryConfigurationError
74         // which is based on Exception without parameters.
75         FactoryConfigurationError fce = new FactoryConfigurationError(e, "msg");
76         assertNotNull(fce.getMessage());
77         assertNotNull(fce.getLocalizedMessage());
78         assertEquals(e.getCause(), fce.getCause());
79
80         // case 2: Try to create FactoryConfigurationError
81         // which is based on Exception with String parameter.
82         e = new Exception("test message");
83         fce = new FactoryConfigurationError(e, "msg");
84         assertEquals("msg", fce.getMessage());
85         assertEquals("msg", fce.getLocalizedMessage());
86         assertEquals(e.getCause(), fce.getCause());
87     }
88
89     @TestTargetNew(
90         level = TestLevel.COMPLETE,
91         notes = "",
92         method = "FactoryConfigurationError",
93         args = {java.lang.String.class}
94     )
95     public void test_ConstructorLjava_lang_String() {
96         FactoryConfigurationError fce = new FactoryConfigurationError("Oops!");
97         assertEquals("Oops!", fce.getMessage());
98         assertEquals("Oops!", fce.getLocalizedMessage());
99         assertNull(fce.getCause());
100     }
101
102     @TestTargetNew(
103         level = TestLevel.COMPLETE,
104         notes = "",
105         method = "getException",
106         args = {}
107     )
108     public void test_getException() {
109         FactoryConfigurationError fce = new FactoryConfigurationError();
110         assertNull(fce.getException());
111         fce = new FactoryConfigurationError("test");
112         assertNull(fce.getException());
113         Exception e = new Exception("msg");
114         fce = new FactoryConfigurationError(e);
115         assertEquals(e, fce.getException());
116         NullPointerException npe = new NullPointerException();
117         fce = new FactoryConfigurationError(npe);
118         assertEquals(npe, fce.getException());
119     }
120
121     @TestTargetNew(
122         level = TestLevel.COMPLETE,
123         notes = "",
124         method = "getMessage",
125         args = {}
126     )
127     public void test_getMessage() {
128         assertNull(new FactoryConfigurationError().getMessage());
129         assertEquals("msg1",
130                 new FactoryConfigurationError("msg1").getMessage());
131         assertEquals(new Exception("msg2").toString(),
132                 new FactoryConfigurationError(
133                         new Exception("msg2")).getMessage());
134         assertEquals(new NullPointerException().toString(),
135                 new FactoryConfigurationError(
136                         new NullPointerException()).getMessage());
137     }
138
139 }