summaryrefslogtreecommitdiffstats
path: root/harmony-tests/src/test/java/org/apache/harmony/tests/javax/xml/parsers/FactoryConfigurationErrorTest.java
blob: cdef4e2b727d2853d36461f03317d73c9e1fd146 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
 * Copyright (C) 2007 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package tests.api.javax.xml.parsers;

import javax.xml.parsers.FactoryConfigurationError;

import junit.framework.TestCase;

public class FactoryConfigurationErrorTest extends TestCase {

    public void test_Constructor() {
        FactoryConfigurationError fce = new FactoryConfigurationError();
        assertNull(fce.getMessage());
        assertNull(fce.getLocalizedMessage());
        assertNull(fce.getCause());
    }

    public void test_ConstructorLjava_lang_Exception() {
        Exception e = new Exception();
        // case 1: Try to create FactoryConfigurationError
        // which is based on Exception without parameters.
        FactoryConfigurationError fce = new FactoryConfigurationError(e);
        assertNotNull(fce.getMessage());
        assertNotNull(fce.getLocalizedMessage());
        assertEquals(e.getCause(), fce.getCause());

        // case 2: Try to create FactoryConfigurationError
        // which is based on Exception with String parameter.
        e = new Exception("test message");
        fce = new FactoryConfigurationError(e);
        assertEquals(e.toString(), fce.getMessage());
        assertEquals(e.toString(), fce.getLocalizedMessage());
        assertEquals(e.getCause(), fce.getCause());
    }

    public void test_ConstructorLjava_lang_ExceptionLjava_lang_String() {
        Exception e = new Exception();
        // case 1: Try to create FactoryConfigurationError
        // which is based on Exception without parameters.
        FactoryConfigurationError fce = new FactoryConfigurationError(e, "msg");
        assertNotNull(fce.getMessage());
        assertNotNull(fce.getLocalizedMessage());
        assertEquals(e.getCause(), fce.getCause());

        // case 2: Try to create FactoryConfigurationError
        // which is based on Exception with String parameter.
        e = new Exception("test message");
        fce = new FactoryConfigurationError(e, "msg");
        assertEquals("msg", fce.getMessage());
        assertEquals("msg", fce.getLocalizedMessage());
        assertEquals(e.getCause(), fce.getCause());
    }

    public void test_ConstructorLjava_lang_String() {
        FactoryConfigurationError fce = new FactoryConfigurationError("Oops!");
        assertEquals("Oops!", fce.getMessage());
        assertEquals("Oops!", fce.getLocalizedMessage());
        assertNull(fce.getCause());
    }

    public void test_getException() {
        FactoryConfigurationError fce = new FactoryConfigurationError();
        assertNull(fce.getException());
        fce = new FactoryConfigurationError("test");
        assertNull(fce.getException());
        Exception e = new Exception("msg");
        fce = new FactoryConfigurationError(e);
        assertEquals(e, fce.getException());
        NullPointerException npe = new NullPointerException();
        fce = new FactoryConfigurationError(npe);
        assertEquals(npe, fce.getException());
    }

    public void test_getMessage() {
        assertNull(new FactoryConfigurationError().getMessage());
        assertEquals("msg1",
                new FactoryConfigurationError("msg1").getMessage());
        assertEquals(new Exception("msg2").toString(),
                new FactoryConfigurationError(
                        new Exception("msg2")).getMessage());
        assertEquals(new NullPointerException().toString(),
                new FactoryConfigurationError(
                        new NullPointerException()).getMessage());
    }

}