Home | History | Annotate | Download | only in lang
      1 /*
      2  *  Licensed to the Apache Software Foundation (ASF) under one or more
      3  *  contributor license agreements.  See the NOTICE file distributed with
      4  *  this work for additional information regarding copyright ownership.
      5  *  The ASF licenses this file to You under the Apache License, Version 2.0
      6  *  (the "License"); you may not use this file except in compliance with
      7  *  the License.  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.apache.harmony.tests.java.lang;
     19 
     20 import junit.framework.TestCase;
     21 
     22 import org.apache.harmony.testframework.serialization.SerializationTest;
     23 
     24 public class IllegalStateExceptionTest extends TestCase {
     25 
     26     /**
     27      * java.lang.IllegalStateException#IllegalStateException()
     28      */
     29     public void test_Constructor() {
     30         IllegalStateException e = new IllegalStateException();
     31         assertNull(e.getMessage());
     32         assertNull(e.getLocalizedMessage());
     33         assertNull(e.getCause());
     34     }
     35 
     36     /**
     37      * java.lang.IllegalStateException#IllegalStateException(java.lang.String)
     38      */
     39     public void test_ConstructorLjava_lang_String() {
     40         IllegalStateException e = new IllegalStateException("fixture");
     41         assertEquals("fixture", e.getMessage());
     42         assertNull(e.getCause());
     43     }
     44 
     45     /**
     46      * {@link java.land.IllegalStateException#IllIllegalStateException(java.lang.Throwable)}
     47      */
     48     public void test_ConstructorLjava_lang_Throwable() {
     49         Throwable emptyThrowable = new Exception();
     50         IllegalStateException emptyException = new IllegalStateException(emptyThrowable);
     51         assertEquals(emptyThrowable.getClass().getName(), emptyException.getMessage());
     52         assertEquals(emptyThrowable.getClass().getName(), emptyException.getLocalizedMessage());
     53         assertEquals(emptyThrowable.getClass().getName(), emptyException.getCause().toString());
     54 
     55         Throwable throwable = new Exception("msg");
     56         IllegalStateException exception = new IllegalStateException(throwable);
     57         assertEquals(throwable.getClass().getName() + ": " + "msg", exception.getMessage());
     58         assertEquals(throwable.getClass().getName(), emptyException.getLocalizedMessage());
     59         assertEquals(throwable.getClass().getName(), emptyException.getCause().toString());
     60     }
     61 
     62     /**
     63      * {@link java.land.IllegalStateException#IllIllegalStateException(java.lang.String, java.lang.Throwable)}
     64      */
     65     public void test_ConstructorLjava_lang_StringLjava_lang_Throwable() {
     66         Throwable emptyThrowable = new Exception();
     67         IllegalStateException emptyException = new IllegalStateException("msg", emptyThrowable);
     68         assertEquals("msg", emptyException.getMessage());
     69         assertEquals("msg", emptyException.getLocalizedMessage());
     70         assertEquals(emptyThrowable.getClass().getName(), emptyException.getCause().toString());
     71 
     72         Throwable throwable = new Exception("msg_exception");
     73         IllegalStateException exception = new IllegalStateException("msg", throwable);
     74         assertEquals("msg", exception.getMessage());
     75         assertEquals("msg", exception.getLocalizedMessage());
     76         assertEquals(throwable.getClass().getName() + ": " + throwable.getMessage(), exception
     77                 .getCause().toString());
     78     }
     79 
     80     /**
     81      * serialization/deserialization.
     82      */
     83     public void testSerializationSelf() throws Exception {
     84 
     85         SerializationTest.verifySelf(new IllegalStateException());
     86     }
     87 
     88     /**
     89      * serialization/deserialization compatibility with RI.
     90      */
     91     public void testSerializationCompatibility() throws Exception {
     92 
     93         SerializationTest.verifyGolden(this, new IllegalStateException());
     94     }
     95 }
     96