InputMismatchExceptionTest.java revision 89c1feb0a69a7707b271086e749975b3f7acacf7
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 */ 16package org.apache.harmony.luni.tests.java.util; 17 18import dalvik.annotation.TestInfo; 19import dalvik.annotation.TestLevel; 20import dalvik.annotation.TestTarget; 21import dalvik.annotation.TestTargetClass; 22 23import junit.framework.TestCase; 24 25import java.io.Serializable; 26import java.util.InputMismatchException; 27import java.util.NoSuchElementException; 28 29import org.apache.harmony.testframework.serialization.SerializationTest; 30 31@TestTargetClass(InputMismatchException.class) 32public class InputMismatchExceptionTest extends TestCase { 33 34 private static final String ERROR_MESSAGE = "for serialization test"; //$NON-NLS-1$ 35 36 /** 37 * @tests java.util.InputMismatchException#InputMismatchException() 38 */ 39 @TestInfo( 40 level = TestLevel.COMPLETE, 41 purpose = "", 42 targets = { 43 @TestTarget( 44 methodName = "InputMismatchException", 45 methodArgs = {} 46 ) 47 }) 48 @SuppressWarnings("cast") 49 public void test_Constructor() { 50 InputMismatchException exception = new InputMismatchException(); 51 assertNotNull(exception); 52 assertTrue(exception instanceof NoSuchElementException); 53 assertTrue(exception instanceof Serializable); 54 } 55 56 /** 57 * @tests java.util.InputMismatchException#InputMismatchException(String) 58 */ 59 @TestInfo( 60 level = TestLevel.COMPLETE, 61 purpose = "", 62 targets = { 63 @TestTarget( 64 methodName = "InputMismatchException", 65 methodArgs = {java.lang.String.class} 66 ) 67 }) 68 public void test_ConstructorLjava_lang_String() { 69 InputMismatchException exception = new InputMismatchException( 70 ERROR_MESSAGE); 71 assertNotNull(exception); 72 assertEquals(ERROR_MESSAGE, exception.getMessage()); 73 } 74 75 /** 76 * @tests serialization/deserialization. 77 */ 78 @TestInfo( 79 level = TestLevel.COMPLETE, 80 purpose = "", 81 targets = { 82 @TestTarget( 83 methodName = "!SerializationSelf", 84 methodArgs = {} 85 ) 86 }) 87 public void testSerializationSelf() throws Exception { 88 89 SerializationTest.verifySelf(new InputMismatchException(ERROR_MESSAGE)); 90 } 91 92 /** 93 * @tests serialization/deserialization compatibility with RI. 94 */ 95 @TestInfo( 96 level = TestLevel.COMPLETE, 97 purpose = "", 98 targets = { 99 @TestTarget( 100 methodName = "!SerializationGolden", 101 methodArgs = {} 102 ) 103 }) 104 public void testSerializationCompatibility() throws Exception { 105 106 SerializationTest.verifyGolden(this, new InputMismatchException( 107 ERROR_MESSAGE)); 108 } 109} 110