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 dalvik.annotation.TestTargetClass; 20import dalvik.annotation.TestTargets; 21import dalvik.annotation.TestTargetNew; 22import dalvik.annotation.TestLevel; 23 24import java.io.Serializable; 25import java.nio.charset.CharacterCodingException; 26import java.nio.charset.UnmappableCharacterException; 27 28import junit.framework.TestCase; 29 30import org.apache.harmony.testframework.serialization.SerializationTest; 31import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert; 32 33@TestTargetClass(UnmappableCharacterException.class) 34/** 35 * Test class UnmappableCharacterException. 36 */ 37public class UnmappableCharacterExceptionTest extends TestCase { 38 39 @TestTargets({ 40 @TestTargetNew( 41 level = TestLevel.COMPLETE, 42 notes = "", 43 method = "UnmappableCharacterException", 44 args = {int.class} 45 ), 46 @TestTargetNew( 47 level = TestLevel.COMPLETE, 48 notes = "", 49 method = "getMessage", 50 args = {} 51 ), 52 @TestTargetNew( 53 level = TestLevel.COMPLETE, 54 notes = "", 55 method = "getInputLength", 56 args = {} 57 ) 58 }) 59 public void testConstructor() { 60 UnmappableCharacterException ex = new UnmappableCharacterException(3); 61 assertTrue(ex instanceof CharacterCodingException); 62 assertNull(ex.getCause()); 63 assertEquals(ex.getInputLength(), 3); 64 assertTrue(ex.getMessage().indexOf("3") != -1); 65 66 ex = new UnmappableCharacterException(-3); 67 assertNull(ex.getCause()); 68 assertEquals(ex.getInputLength(), -3); 69 assertTrue(ex.getMessage().indexOf("-3") != -1); 70 71 ex = new UnmappableCharacterException(0); 72 assertNull(ex.getCause()); 73 assertEquals(ex.getInputLength(), 0); 74 assertTrue(ex.getMessage().indexOf("0") != -1); 75 76 } 77 78 // comparator for UnmappableCharacterException objects 79 private static final SerializableAssert COMPARATOR = new SerializableAssert() { 80 public void assertDeserialized(Serializable initial, 81 Serializable deserialized) { 82 83 // do common checks for all throwable objects 84 SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial, 85 deserialized); 86 87 UnmappableCharacterException initEx = (UnmappableCharacterException) initial; 88 UnmappableCharacterException desrEx = (UnmappableCharacterException) deserialized; 89 90 assertEquals("InputLength", initEx.getInputLength(), desrEx 91 .getInputLength()); 92 } 93 }; 94 95 /** 96 * @tests serialization/deserialization compatibility. 97 */ 98 @TestTargetNew( 99 level = TestLevel.COMPLETE, 100 notes = "Verifies serialization.", 101 method = "!SerializationSelf", 102 args = {} 103 ) 104 public void testSerializationSelf() throws Exception { 105 106 SerializationTest.verifySelf(new UnmappableCharacterException(11), 107 COMPARATOR); 108 } 109 110 /** 111 * @tests serialization/deserialization compatibility with RI. 112 */ 113 @TestTargetNew( 114 level = TestLevel.COMPLETE, 115 notes = "Verifies serialization.", 116 method = "!SerializationGolden", 117 args = {} 118 ) 119 public void testSerializationCompatibility() throws Exception { 120 121 SerializationTest.verifyGolden(this, new UnmappableCharacterException( 122 11), COMPARATOR); 123 } 124} 125