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