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 java.io.Serializable; 19import java.util.UnknownFormatConversionException; 20 21import junit.framework.TestCase; 22 23import org.apache.harmony.testframework.serialization.SerializationTest; 24import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert; 25 26public class UnknownFormatConversionExceptionTest extends TestCase { 27 28 /** 29 * @tests java.util.UnknownFormatConversionException#UnknownFormatConversionException(String) 30 */ 31 public void test_unknownFormatConversionException() { 32 33 // RI 5.0 will not throw NullPointerException, it is the bug according 34 // to spec. 35 try { 36 new UnknownFormatConversionException(null); 37 fail("should throw NullPointerExcepiton"); 38 } catch (NullPointerException e) { 39 } 40 } 41 42 /** 43 * @tests java.util.UnknownFormatConversionException#getConversion() 44 */ 45 public void test_getConversion() { 46 String s = "MYTESTSTRING"; 47 UnknownFormatConversionException UnknownFormatConversionException = new UnknownFormatConversionException( 48 s); 49 assertEquals(s, UnknownFormatConversionException.getConversion()); 50 } 51 52 /** 53 * @tests java.util.UnknownFormatConversionException#getMessage() 54 */ 55 public void test_getMessage() { 56 String s = "MYTESTSTRING"; 57 UnknownFormatConversionException UnknownFormatConversionException = new UnknownFormatConversionException( 58 s); 59 assertTrue(null != UnknownFormatConversionException.getMessage()); 60 } 61 62 // comparator for comparing UnknownFormatConversionException objects 63 private static final SerializableAssert exComparator = new SerializableAssert() { 64 public void assertDeserialized(Serializable initial, 65 Serializable deserialized) { 66 67 SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial, 68 deserialized); 69 70 UnknownFormatConversionException initEx = (UnknownFormatConversionException) initial; 71 UnknownFormatConversionException desrEx = (UnknownFormatConversionException) deserialized; 72 73 assertEquals("Conversion", initEx.getConversion(), desrEx 74 .getConversion()); 75 } 76 }; 77 78 /** 79 * @tests serialization/deserialization. 80 */ 81 public void testSerializationSelf() throws Exception { 82 83 SerializationTest.verifySelf(new UnknownFormatConversionException( 84 "MYTESTSTRING"), exComparator); 85 } 86 87 /** 88 * @tests serialization/deserialization compatibility with RI. 89 */ 90 public void testSerializationCompatibility() throws Exception { 91 92 SerializationTest.verifyGolden(this, 93 new UnknownFormatConversionException("MYTESTSTRING"), 94 exComparator); 95 } 96} 97