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