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.MalformedInputException; 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 MalformedInputException. 30 */ 31public class MalformedInputExceptionTest extends TestCase { 32 33 public void testConstructor() { 34 MalformedInputException ex = new MalformedInputException(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 MalformedInputException(-3); 41 assertNull(ex.getCause()); 42 assertEquals(ex.getInputLength(), -3); 43 assertTrue(ex.getMessage().indexOf("-3") != -1); 44 45 ex = new MalformedInputException(0); 46 assertNull(ex.getCause()); 47 assertEquals(ex.getInputLength(), 0); 48 assertTrue(ex.getMessage().indexOf("0") != -1); 49 } 50 51 // comparator for MalformedInputException objects 52 private static final SerializableAssert COMPARATOR = new SerializableAssert() { 53 public void assertDeserialized(Serializable initial, 54 Serializable deserialized) { 55 56 // do common checks for all throwable objects 57 SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial, 58 deserialized); 59 60 MalformedInputException initEx = (MalformedInputException) initial; 61 MalformedInputException desrEx = (MalformedInputException) deserialized; 62 63 assertEquals("InputLength", initEx.getInputLength(), desrEx 64 .getInputLength()); 65 } 66 }; 67 68 /** 69 * @tests serialization/deserialization compatibility. 70 */ 71 public void testSerializationSelf() throws Exception { 72 73 SerializationTest.verifySelf(new MalformedInputException(11), 74 COMPARATOR); 75 } 76 77 /** 78 * @tests serialization/deserialization compatibility with RI. 79 */ 80 public void testSerializationCompatibility() throws Exception { 81 82 SerializationTest.verifyGolden(this, new MalformedInputException(11), 83 COMPARATOR); 84 } 85} 86