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.nio_char.tests.java.nio.charset; 18 19import java.io.Serializable; 20import java.nio.charset.CharacterCodingException; 21import java.nio.charset.UnmappableCharacterException; 22 23import junit.framework.TestCase; 24 25import org.apache.harmony.testframework.serialization.SerializationTest; 26import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert; 27 28/** 29 * Test class UnmappableCharacterException. 30 */ 31public class UnmappableCharacterExceptionTest extends TestCase { 32 33 public void testConstructor() { 34 UnmappableCharacterException ex = new UnmappableCharacterException(3); 35 assertTrue(ex instanceof CharacterCodingException); 36 assertNull(ex.getCause()); 37 assertEquals(ex.getInputLength(), 3); 38 assertTrue(ex.getMessage().indexOf("3") != -1); 39 40 ex = new UnmappableCharacterException(-3); 41 assertNull(ex.getCause()); 42 assertEquals(ex.getInputLength(), -3); 43 assertTrue(ex.getMessage().indexOf("-3") != -1); 44 45 ex = new UnmappableCharacterException(0); 46 assertNull(ex.getCause()); 47 assertEquals(ex.getInputLength(), 0); 48 assertTrue(ex.getMessage().indexOf("0") != -1); 49 50 } 51 52 // comparator for UnmappableCharacterException objects 53 private static final SerializableAssert COMPARATOR = new SerializableAssert() { 54 public void assertDeserialized(Serializable initial, 55 Serializable deserialized) { 56 57 // do common checks for all throwable objects 58 SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial, 59 deserialized); 60 61 UnmappableCharacterException initEx = (UnmappableCharacterException) initial; 62 UnmappableCharacterException desrEx = (UnmappableCharacterException) deserialized; 63 64 assertEquals("InputLength", initEx.getInputLength(), desrEx 65 .getInputLength()); 66 } 67 }; 68 69 /** 70 * @tests serialization/deserialization compatibility. 71 */ 72 public void testSerializationSelf() throws Exception { 73 74 SerializationTest.verifySelf(new UnmappableCharacterException(11), 75 COMPARATOR); 76 } 77 78 /** 79 * @tests serialization/deserialization compatibility with RI. 80 */ 81 public void testSerializationCompatibility() throws Exception { 82 83 SerializationTest.verifyGolden(this, new UnmappableCharacterException( 84 11), COMPARATOR); 85 } 86} 87