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 IllegalArgumentExceptionTest extends TestCase {
     25 
     26     /**
     27      * java.lang.IllegalArgumentException#IllegalArgumentException()
     28      */
     29     public void test_Constructor() {
     30         IllegalArgumentException e = new IllegalArgumentException();
     31         assertNull(e.getMessage());
     32         assertNull(e.getLocalizedMessage());
     33         assertNull(e.getCause());
     34     }
     35 
     36     /**
     37      * java.lang.IllegalArgumentException#IllegalArgumentException(java.lang.String)
     38      */
     39     public void test_ConstructorLjava_lang_String() {
     40         IllegalArgumentException e = new IllegalArgumentException("fixture");
     41         assertEquals("fixture", e.getMessage());
     42         assertNull(e.getCause());
     43     }
     44 
     45     /**
     46      * {@link java.lang.IllegalArgumentException#IllegalArgumentException(Throwable)}
     47      */
     48     public void test_ConstructorLjava_lang_Throwable() {
     49         Throwable emptyThrowable = new Exception();
     50         IllegalArgumentException emptyException = new IllegalArgumentException(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 exception = new Exception("msg");
     56         IllegalArgumentException e = new IllegalArgumentException(exception);
     57         assertEquals(exception.getClass().getName() + ": " + "msg", e.getMessage());
     58         assertEquals(exception.getClass().getName(), emptyException.getLocalizedMessage());
     59         assertEquals(exception.getClass().getName(), emptyException.getCause().toString());
     60     }
     61 
     62     /**
     63      * java.lang.IllegalArgumentException#IllegalArgumentException(String, Throwable)
     64      */
     65     @SuppressWarnings("nls")
     66     public void test_ConstructorLjava_lang_StringLjava_lang_Throwable() {
     67         NullPointerException npe = new NullPointerException();
     68         IllegalArgumentException e = new IllegalArgumentException("fixture",
     69                 npe);
     70         assertSame("fixture", e.getMessage());
     71         assertSame(npe, e.getCause());
     72     }
     73 
     74     /**
     75      * serialization/deserialization.
     76      */
     77     public void testSerializationSelf() throws Exception {
     78         SerializationTest.verifySelf(new IllegalArgumentException());
     79     }
     80 
     81     /**
     82      * serialization/deserialization compatibility with RI.
     83      */
     84     public void testSerializationCompatibility() throws Exception {
     85         SerializationTest.verifyGolden(this, new IllegalArgumentException());
     86     }
     87 }
     88