1cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath/* Licensed to the Apache Software Foundation (ASF) under one or more
2cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * contributor license agreements.  See the NOTICE file distributed with
3cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * this work for additional information regarding copyright ownership.
4cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * The ASF licenses this file to You under the Apache License, Version 2.0
5cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * (the "License"); you may not use this file except in compliance with
6cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * the License.  You may obtain a copy of the License at
7cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath *
8cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath *     http://www.apache.org/licenses/LICENSE-2.0
9cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath *
10cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * Unless required by applicable law or agreed to in writing, software
11cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * distributed under the License is distributed on an "AS IS" BASIS,
12cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * See the License for the specific language governing permissions and
14cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * limitations under the License.
15cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */
16cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
17ab762bb740405d0fefcccf4a0899a234f995be13Narayan Kamathpackage org.apache.harmony.tests.java.util;
18cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
19cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamathimport java.io.Serializable;
20cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamathimport java.util.MissingFormatArgumentException;
21cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
22cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamathimport junit.framework.TestCase;
23cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
24cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamathimport org.apache.harmony.testframework.serialization.SerializationTest;
25cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamathimport org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
26cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
27cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamathpublic class MissingFormatArgumentExceptionTest extends TestCase {
28cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
29cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    /**
30cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath     * java.util.MissingFormatArgumentException#MissingFormatArgumentException(String)
31cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath     */
32cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    public void test_missingFormatArgumentException() {
33cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
34cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath        try {
35cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath            new MissingFormatArgumentException(null);
36cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath            fail("should throw NullPointerExcepiton.");
37cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath        } catch (NullPointerException e) {
38cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath            // expected
39cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath        }
40cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    }
41cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
42cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    /**
43cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath     * java.util.MissingFormatArgumentException#getFormatSpecifier()
44cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath     */
45cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    public void test_getFormatSpecifier() {
46cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath        String s = "MYTESTSTRING";
47cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath        MissingFormatArgumentException missingFormatArgumentException = new MissingFormatArgumentException(
48cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath                s);
49cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath        assertEquals(s, missingFormatArgumentException.getFormatSpecifier());
50cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    }
51cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
52cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    /**
53cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath     * java.util.MissingFormatArgumentException#getMessage()
54cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath     */
55cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    public void test_getMessage() {
56cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath        String s = "MYTESTSTRING";
57cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath        MissingFormatArgumentException missingFormatArgumentException = new MissingFormatArgumentException(
58cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath                s);
59cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath        assertTrue(null != missingFormatArgumentException.getMessage());
60cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
61cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    }
62cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
63cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    // comparator for comparing MissingFormatArgumentException objects
64cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    private static final SerializableAssert exComparator = new SerializableAssert() {
65cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath        public void assertDeserialized(Serializable initial,
66cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath                Serializable deserialized) {
67cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
68cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath            SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial,
69cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath                    deserialized);
70cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
71cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath            MissingFormatArgumentException initEx = (MissingFormatArgumentException) initial;
72cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath            MissingFormatArgumentException desrEx = (MissingFormatArgumentException) deserialized;
73cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
74cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath            assertEquals("FormatSpecifier", initEx.getFormatSpecifier(), desrEx
75cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath                    .getFormatSpecifier());
76cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath        }
77cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    };
78cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
79cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    /**
80cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath     * serialization/deserialization.
81cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath     */
82cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    public void testSerializationSelf() throws Exception {
83cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
84cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath        SerializationTest.verifySelf(new MissingFormatArgumentException(
85cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath                "MYTESTSTRING"), exComparator);
86cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    }
87cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
88cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    /**
89cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath     * serialization/deserialization compatibility with RI.
90cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath     */
91cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    public void testSerializationCompatibility() throws Exception {
92cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
93cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath        SerializationTest.verifyGolden(this,
94cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath                new MissingFormatArgumentException("MYTESTSTRING"),
95cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath                exComparator);
96cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    }
97cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath}
98