Home | History | Annotate | Download | only in parsers
      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 
     22 public class FactoryConfigurationErrorTest extends TestCase {
     23 
     24     public void test_Constructor() {
     25         FactoryConfigurationError fce = new FactoryConfigurationError();
     26         assertNull(fce.getMessage());
     27         assertNull(fce.getLocalizedMessage());
     28         assertNull(fce.getCause());
     29     }
     30 
     31     public void test_ConstructorLjava_lang_Exception() {
     32         Exception e = new Exception();
     33         // case 1: Try to create FactoryConfigurationError
     34         // which is based on Exception without parameters.
     35         FactoryConfigurationError fce = new FactoryConfigurationError(e);
     36         assertNotNull(fce.getMessage());
     37         assertNotNull(fce.getLocalizedMessage());
     38         assertEquals(e.getCause(), fce.getCause());
     39 
     40         // case 2: Try to create FactoryConfigurationError
     41         // which is based on Exception with String parameter.
     42         e = new Exception("test message");
     43         fce = new FactoryConfigurationError(e);
     44         assertEquals(e.toString(), fce.getMessage());
     45         assertEquals(e.toString(), fce.getLocalizedMessage());
     46         assertEquals(e.getCause(), fce.getCause());
     47     }
     48 
     49     public void test_ConstructorLjava_lang_ExceptionLjava_lang_String() {
     50         Exception e = new Exception();
     51         // case 1: Try to create FactoryConfigurationError
     52         // which is based on Exception without parameters.
     53         FactoryConfigurationError fce = new FactoryConfigurationError(e, "msg");
     54         assertNotNull(fce.getMessage());
     55         assertNotNull(fce.getLocalizedMessage());
     56         assertEquals(e.getCause(), fce.getCause());
     57 
     58         // case 2: Try to create FactoryConfigurationError
     59         // which is based on Exception with String parameter.
     60         e = new Exception("test message");
     61         fce = new FactoryConfigurationError(e, "msg");
     62         assertEquals("msg", fce.getMessage());
     63         assertEquals("msg", fce.getLocalizedMessage());
     64         assertEquals(e.getCause(), fce.getCause());
     65     }
     66 
     67     public void test_ConstructorLjava_lang_String() {
     68         FactoryConfigurationError fce = new FactoryConfigurationError("Oops!");
     69         assertEquals("Oops!", fce.getMessage());
     70         assertEquals("Oops!", fce.getLocalizedMessage());
     71         assertNull(fce.getCause());
     72     }
     73 
     74     public void test_getException() {
     75         FactoryConfigurationError fce = new FactoryConfigurationError();
     76         assertNull(fce.getException());
     77         fce = new FactoryConfigurationError("test");
     78         assertNull(fce.getException());
     79         Exception e = new Exception("msg");
     80         fce = new FactoryConfigurationError(e);
     81         assertEquals(e, fce.getException());
     82         NullPointerException npe = new NullPointerException();
     83         fce = new FactoryConfigurationError(npe);
     84         assertEquals(npe, fce.getException());
     85     }
     86 
     87     public void test_getMessage() {
     88         assertNull(new FactoryConfigurationError().getMessage());
     89         assertEquals("msg1",
     90                 new FactoryConfigurationError("msg1").getMessage());
     91         assertEquals(new Exception("msg2").toString(),
     92                 new FactoryConfigurationError(
     93                         new Exception("msg2")).getMessage());
     94         assertEquals(new NullPointerException().toString(),
     95                 new FactoryConfigurationError(
     96                         new NullPointerException()).getMessage());
     97     }
     98 
     99 }
    100