1/* Licensed to the Apache Software Foundation (ASF) under one or more 2 * contributor license agreements. See the NOTICE file distributed with 3 * this work for additional information regarding copyright ownership. 4 * The ASF licenses this file to You under the Apache License, Version 2.0 5 * (the "License"); you may not use this file except in compliance with 6 * the License. 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 17package org.apache.harmony.tests.java.nio.charset; 18 19import java.io.Serializable; 20import java.nio.charset.UnsupportedCharsetException; 21 22import junit.framework.TestCase; 23 24import org.apache.harmony.testframework.serialization.SerializationTest; 25import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert; 26 27/** 28 * Test class UnsupportedCharsetException. 29 */ 30public class UnsupportedCharsetExceptionTest extends TestCase { 31 32 public void testConstructor() { 33 UnsupportedCharsetException ex = new UnsupportedCharsetException( 34 "impossible"); 35 assertTrue(ex instanceof IllegalArgumentException); 36 assertNull(ex.getCause()); 37 assertEquals(ex.getCharsetName(), "impossible"); 38 assertTrue(ex.getMessage().indexOf("impossible") != -1); 39 40 ex = new UnsupportedCharsetException("ascii"); 41 assertNull(ex.getCause()); 42 assertEquals(ex.getCharsetName(), "ascii"); 43 assertTrue(ex.getMessage().indexOf("ascii") != -1); 44 45 ex = new UnsupportedCharsetException(""); 46 assertNull(ex.getCause()); 47 assertEquals(ex.getCharsetName(), ""); 48 ex.getMessage(); 49 50 ex = new UnsupportedCharsetException(null); 51 assertNull(ex.getCause()); 52 assertNull(ex.getCharsetName()); 53 assertTrue(ex.getMessage().indexOf("null") != -1); 54 } 55 56 // comparator for UnsupportedCharsetException objects 57 private static final SerializableAssert COMPARATOR = new SerializableAssert() { 58 public void assertDeserialized(Serializable initial, 59 Serializable deserialized) { 60 61 // FIXME?: getMessage() returns more helpful string but 62 // this leads to incompatible message in serial form 63 // 64 // do common checks for all throwable objects 65 // SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial, 66 // deserialized); 67 68 UnsupportedCharsetException initEx = (UnsupportedCharsetException) initial; 69 UnsupportedCharsetException desrEx = (UnsupportedCharsetException) deserialized; 70 71 assertEquals("CharsetName", initEx.getCharsetName(), desrEx 72 .getCharsetName()); 73 } 74 }; 75 76 /** 77 * @tests serialization/deserialization compatibility. 78 */ 79 public void testSerializationSelf() throws Exception { 80 81 SerializationTest.verifySelf(new UnsupportedCharsetException( 82 "charsetName"), COMPARATOR); 83 } 84 85 /** 86 * @tests serialization/deserialization compatibility with RI. 87 */ 88 public void testSerializationCompatibility() throws Exception { 89 90 SerializationTest.verifyGolden(this, new UnsupportedCharsetException( 91 "charsetName"), COMPARATOR); 92 } 93} 94