1561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes/* Licensed to the Apache Software Foundation (ASF) under one or more
2561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * contributor license agreements.  See the NOTICE file distributed with
3561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * this work for additional information regarding copyright ownership.
4561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * The ASF licenses this file to You under the Apache License, Version 2.0
5561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * (the "License"); you may not use this file except in compliance with
6561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * the License.  You may obtain a copy of the License at
7561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes *
8561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes *     http://www.apache.org/licenses/LICENSE-2.0
9561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes *
10561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * Unless required by applicable law or agreed to in writing, software
11561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * distributed under the License is distributed on an "AS IS" BASIS,
12561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * See the License for the specific language governing permissions and
14561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * limitations under the License.
15561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes */
16561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughespackage org.apache.harmony.luni.tests.java.util;
17561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
18561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport java.io.Serializable;
19561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport java.util.MissingFormatWidthException;
20561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
21561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport junit.framework.TestCase;
22561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
23561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport org.apache.harmony.testframework.serialization.SerializationTest;
24561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
25561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
26561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughespublic class MissingFormatWidthExceptionTest extends TestCase {
27561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
28561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    /**
29561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @tests java.util.MissingFormatWidthException#MissingFormatWidthException(String)
30561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     */
31561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void test_missingFormatWidthException() {
32561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        try {
33561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            new MissingFormatWidthException(null);
34561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            fail("should throw NullPointerExcepiton");
35561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        } catch (NullPointerException e) {
36561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            // expected
37561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
38561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
39561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
40561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    /**
41561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @tests java.util.MissingFormatWidthException#getFormatSpecifier()
42561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     */
43561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void test_getFormatSpecifier() {
44561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        String s = "MYTESTSTRING";
45561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        MissingFormatWidthException missingFormatWidthException = new MissingFormatWidthException(
46561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                s);
47561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals(s, missingFormatWidthException.getFormatSpecifier());
48561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
49561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
50561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
51561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    /**
52561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @tests java.util.MissingFormatWidthException#getMessage()
53561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     */
54561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void test_getMessage() {
55561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        String s = "MYTESTSTRING";
56561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        MissingFormatWidthException missingFormatWidthException = new MissingFormatWidthException(
57561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                s);
58561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertTrue(null != missingFormatWidthException.getMessage());
59561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
60561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
61561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
62561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    // comparator for comparing MissingFormatWidthException objects
63561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    private static final SerializableAssert exComparator = new SerializableAssert() {
64561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        public void assertDeserialized(Serializable initial,
65561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                Serializable deserialized) {
66561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
67561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial,
68561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                    deserialized);
69561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
70561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            MissingFormatWidthException initEx = (MissingFormatWidthException) initial;
71561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            MissingFormatWidthException desrEx = (MissingFormatWidthException) deserialized;
72561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
73561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            assertEquals("FormatSpecifier", initEx.getFormatSpecifier(), desrEx
74561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                    .getFormatSpecifier());
75561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
76561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    };
77561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
78561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    /**
79561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @tests serialization/deserialization.
80561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     */
81561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void testSerializationSelf() throws Exception {
82561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
83561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        SerializationTest.verifySelf(new MissingFormatWidthException(
84561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                "MYTESTSTRING"), exComparator);
85561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
86561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
87561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    /**
88561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @tests serialization/deserialization compatibility with RI.
89561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     */
90561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void testSerializationCompatibility() throws Exception {
91561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
92561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        SerializationTest.verifyGolden(this, new MissingFormatWidthException(
93561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                "MYTESTSTRING"), exComparator);
94561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
95561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes}
96