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 */
16ab762bb740405d0fefcccf4a0899a234f995be13Narayan Kamathpackage org.apache.harmony.tests.java.util;
17cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
18cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamathimport java.io.Serializable;
19cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamathimport java.util.IllegalFormatWidthException;
20cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
21cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamathimport junit.framework.TestCase;
22cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
23cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamathimport org.apache.harmony.testframework.serialization.SerializationTest;
24cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamathimport org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
25cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
26cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamathpublic class IllegalFormatWidthExceptionTest extends TestCase {
27cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
28cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    /**
29cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath     * java.util.IllegalFormatWidthException#IllegalFormatWidthException(int)
30cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath     */
31cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    public void test_illegalFormatWidthException() {
32cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath        int width = Integer.MAX_VALUE;
33cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath        IllegalFormatWidthException illegalFormatWidthException = new IllegalFormatWidthException(
34cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath                width);
35cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath        assertEquals(width, illegalFormatWidthException.getWidth());
36cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
37cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    }
38cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
39cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    /**
40cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath     * java.util.IllegalFormatWidthException#getWidth()
41cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath     */
42cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    public void test_getWidth() {
43cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath        int width = 12345;
44cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath        IllegalFormatWidthException illegalFormatWidthException = new IllegalFormatWidthException(
45cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath                width);
46cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath        assertEquals(width, illegalFormatWidthException.getWidth());
47cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
48cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    }
49cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
50cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    /**
51cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath     * java.util.IllegalFormatWidthException#getMessage()
52cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath     */
53cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    public void test_getMessage() {
54cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath        int width = 12345;
55cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath        IllegalFormatWidthException illegalFormatWidthException = new IllegalFormatWidthException(
56cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath                width);
57cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath        assertTrue(null != illegalFormatWidthException.getMessage());
58cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
59cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    }
60cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
61cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    // comparator for IllegalFormatWidthException objects
62cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    private static final SerializableAssert exComparator = new SerializableAssert() {
63cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath        public void assertDeserialized(Serializable initial,
64cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath                Serializable deserialized) {
65cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
66cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath            SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial,
67cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath                    deserialized);
68cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
69cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath            IllegalFormatWidthException initEx = (IllegalFormatWidthException) initial;
70cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath            IllegalFormatWidthException desrEx = (IllegalFormatWidthException) deserialized;
71cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
72cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath            assertEquals("Width", initEx.getWidth(), desrEx.getWidth());
73cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath        }
74cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    };
75cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
76cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    /**
77cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath     * serialization/deserialization.
78cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath     */
79cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    public void testSerializationSelf() throws Exception {
80cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
81cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath        SerializationTest.verifySelf(new IllegalFormatWidthException(12345),
82cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath                exComparator);
83cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    }
84cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
85cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    /**
86cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath     * serialization/deserialization compatibility with RI.
87cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath     */
88cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    public void testSerializationCompatibility() throws Exception {
89cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath
90cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath        SerializationTest.verifyGolden(this, new IllegalFormatWidthException(
91cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath                12345), exComparator);
92cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath    }
93cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath}
94