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