UnsupportedOperationExceptionTest.java revision 561ee011997c6c2f1befbfaa9d5f0a99771c1d63
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 18package org.apache.harmony.luni.tests.java.lang; 19 20import junit.framework.TestCase; 21 22import org.apache.harmony.testframework.serialization.SerializationTest; 23 24public class UnsupportedOperationExceptionTest extends TestCase { 25 26 /** 27 * @tests java.lang.UnsupportedOperationException#UnsupportedOperationException() 28 */ 29 public void test_Constructor() { 30 UnsupportedOperationException e = new UnsupportedOperationException(); 31 assertNull(e.getMessage()); 32 assertNull(e.getLocalizedMessage()); 33 assertNull(e.getCause()); 34 } 35 36 /** 37 * @tests java.lang.UnsupportedOperationException#UnsupportedOperationException(java.lang.String) 38 */ 39 public void test_ConstructorLjava_lang_String() { 40 UnsupportedOperationException e = new UnsupportedOperationException("fixture"); 41 assertEquals("fixture", e.getMessage()); 42 assertNull(e.getCause()); 43 } 44 45 /** 46 * @tests {@link java.land.UnsupportedOperationException#UnsupportedOperationException(java.lang.Throwable)} 47 */ 48 public void test_ConstructorLjava_lang_Throwable() { 49 Throwable emptyThrowable = new Exception(); 50 UnsupportedOperationException emptyException = new UnsupportedOperationException( 51 emptyThrowable); 52 assertEquals(emptyThrowable.getClass().getName(), emptyException.getMessage()); 53 assertEquals(emptyThrowable.getClass().getName(), emptyException.getLocalizedMessage()); 54 assertEquals(emptyThrowable.getClass().getName(), emptyException.getCause().toString()); 55 56 Throwable throwable = new Exception("msg"); 57 UnsupportedOperationException exception = new UnsupportedOperationException(throwable); 58 assertEquals(throwable.getClass().getName() + ": " + "msg", exception.getMessage()); 59 assertEquals(throwable.getClass().getName(), emptyException.getLocalizedMessage()); 60 assertEquals(throwable.getClass().getName(), emptyException.getCause().toString()); 61 } 62 63 /** 64 * @tests {@link java.land.UnsupportedOperationException#UnsupportedOperationException(java.lang.String, java.lang.Throwable)} 65 */ 66 public void test_ConstructorLjava_lang_StringLjava_lang_Throwable() { 67 Throwable emptyThrowable = new Exception(); 68 UnsupportedOperationException emptyException = new UnsupportedOperationException( 69 "msg", emptyThrowable); 70 assertEquals("msg", emptyException.getMessage()); 71 assertEquals("msg", emptyException.getLocalizedMessage()); 72 assertEquals(emptyThrowable.getClass().getName(), emptyException.getCause().toString()); 73 74 Throwable throwable = new Exception("msg_exception"); 75 UnsupportedOperationException exception = new UnsupportedOperationException( 76 "msg", throwable); 77 assertEquals("msg", exception.getMessage()); 78 assertEquals("msg", exception.getLocalizedMessage()); 79 assertEquals(throwable.getClass().getName() + ": " + throwable.getMessage(), exception 80 .getCause().toString()); 81 } 82 83 84 /** 85 * @tests serialization/deserialization. 86 */ 87 public void testSerializationSelf() throws Exception { 88 89 SerializationTest.verifySelf(new UnsupportedOperationException()); 90 } 91 92 /** 93 * @tests serialization/deserialization compatibility with RI. 94 */ 95 public void testSerializationCompatibility() throws Exception { 96 97 SerializationTest.verifyGolden(this, 98 new UnsupportedOperationException()); 99 } 100} 101