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