UnknownFormatConversionExceptionTest.java revision f6c387128427e121477c1b32ad35cdcaa5101ba3
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.TestTargets; 19import dalvik.annotation.TestLevel; 20import dalvik.annotation.TestTargetNew; 21import dalvik.annotation.TestTargetClass; 22 23import junit.framework.TestCase; 24 25import java.io.Serializable; 26import java.util.UnknownFormatConversionException; 27 28import org.apache.harmony.testframework.serialization.SerializationTest; 29import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert; 30 31@TestTargetClass(UnknownFormatConversionException.class) 32public class UnknownFormatConversionExceptionTest extends TestCase { 33 34 /** 35 * @tests java.util.UnknownFormatConversionException#UnknownFormatConversionException(String) 36 */ 37 @TestTargetNew( 38 level = TestLevel.COMPLETE, 39 notes = "", 40 method = "UnknownFormatConversionException", 41 args = {java.lang.String.class} 42 ) 43 public void test_unknownFormatConversionException() { 44 45 // RI 5.0 will not throw NullPointerException, it is the bug according 46 // to spec. 47 try { 48 new UnknownFormatConversionException(null); 49 } catch (NullPointerException e) { 50 fail("should not throw NullPointerExcepiton"); 51 } 52 } 53 54 /** 55 * @tests java.util.UnknownFormatConversionException#getConversion() 56 */ 57 @TestTargetNew( 58 level = TestLevel.COMPLETE, 59 notes = "", 60 method = "getConversion", 61 args = {} 62 ) 63 public void test_getConversion() { 64 String s = "MYTESTSTRING"; 65 UnknownFormatConversionException UnknownFormatConversionException = new UnknownFormatConversionException( 66 s); 67 assertEquals(s, UnknownFormatConversionException.getConversion()); 68 } 69 70 /** 71 * @tests java.util.UnknownFormatConversionException#getMessage() 72 */ 73 @TestTargetNew( 74 level = TestLevel.COMPLETE, 75 notes = "", 76 method = "getMessage", 77 args = {} 78 ) 79 public void test_getMessage() { 80 String s = "MYTESTSTRING"; 81 UnknownFormatConversionException UnknownFormatConversionException = new UnknownFormatConversionException( 82 s); 83 assertTrue(null != UnknownFormatConversionException.getMessage()); 84 } 85 86 // comparator for comparing UnknownFormatConversionException objects 87 private static final SerializableAssert exComparator = new SerializableAssert() { 88 public void assertDeserialized(Serializable initial, 89 Serializable deserialized) { 90 91 SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial, 92 deserialized); 93 94 UnknownFormatConversionException initEx = (UnknownFormatConversionException) initial; 95 UnknownFormatConversionException desrEx = (UnknownFormatConversionException) deserialized; 96 97 assertEquals("Conversion", initEx.getConversion(), desrEx 98 .getConversion()); 99 } 100 }; 101 102 /** 103 * @tests serialization/deserialization. 104 */ 105 @TestTargetNew( 106 level = TestLevel.COMPLETE, 107 notes = "", 108 method = "!SerializationSelf", 109 args = {} 110 ) 111 public void testSerializationSelf() throws Exception { 112 113 SerializationTest.verifySelf(new UnknownFormatConversionException( 114 "MYTESTSTRING"), exComparator); 115 } 116 117 /** 118 * @tests serialization/deserialization compatibility with RI. 119 */ 120 @TestTargetNew( 121 level = TestLevel.COMPLETE, 122 notes = "", 123 method = "!SerializationGolden", 124 args = {} 125 ) 126 public void testSerializationCompatibility() throws Exception { 127 128 SerializationTest.verifyGolden(this, 129 new UnknownFormatConversionException("MYTESTSTRING"), 130 exComparator); 131 } 132} 133