MissingFormatWidthExceptionTest.java revision f6c387128427e121477c1b32ad35cdcaa5101ba3
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.MissingFormatWidthException;
27
28import org.apache.harmony.testframework.serialization.SerializationTest;
29import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
30
31@TestTargetClass(MissingFormatWidthException.class)
32public class MissingFormatWidthExceptionTest extends TestCase {
33
34    /**
35     * @tests java.util.MissingFormatWidthException#MissingFormatWidthException(String)
36     */
37    @TestTargetNew(
38        level = TestLevel.COMPLETE,
39        notes = "",
40        method = "MissingFormatWidthException",
41        args = {java.lang.String.class}
42    )
43    public void test_missingFormatWidthException() {
44        assertNotNull(new MissingFormatWidthException("String"));
45        try {
46            new MissingFormatWidthException(null);
47            fail("should throw NullPointerExcepiton");
48        } catch (NullPointerException e) {
49            // expected
50        }
51    }
52
53    /**
54     * @tests java.util.MissingFormatWidthException#getFormatSpecifier()
55     */
56    @TestTargetNew(
57        level = TestLevel.COMPLETE,
58        notes = "",
59        method = "getFormatSpecifier",
60        args = {}
61    )
62    public void test_getFormatSpecifier() {
63        String s = "MYTESTSTRING";
64        MissingFormatWidthException missingFormatWidthException = new MissingFormatWidthException(
65                s);
66        assertEquals(s, missingFormatWidthException.getFormatSpecifier());
67
68    }
69
70    /**
71     * @tests java.util.MissingFormatWidthException#getMessage()
72     */
73    @TestTargetNew(
74        level = TestLevel.COMPLETE,
75        notes = "",
76        method = "getMessage",
77        args = {}
78    )
79    public void test_getMessage() {
80        String s = "MYTESTSTRING";
81        MissingFormatWidthException missingFormatWidthException = new MissingFormatWidthException(
82                s);
83        assertTrue(null != missingFormatWidthException.getMessage());
84
85    }
86
87    // comparator for comparing MissingFormatWidthException objects
88    private static final SerializableAssert exComparator = new SerializableAssert() {
89        public void assertDeserialized(Serializable initial,
90                Serializable deserialized) {
91
92            SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial,
93                    deserialized);
94
95            MissingFormatWidthException initEx = (MissingFormatWidthException) initial;
96            MissingFormatWidthException desrEx = (MissingFormatWidthException) deserialized;
97
98            assertEquals("FormatSpecifier", initEx.getFormatSpecifier(), desrEx
99                    .getFormatSpecifier());
100        }
101    };
102
103    /**
104     * @tests serialization/deserialization.
105     */
106    @TestTargetNew(
107        level = TestLevel.COMPLETE,
108        notes = "",
109        method = "!SerializationSelf",
110        args = {}
111    )
112    public void testSerializationSelf() throws Exception {
113
114        SerializationTest.verifySelf(new MissingFormatWidthException(
115                "MYTESTSTRING"), exComparator);
116    }
117
118    /**
119     * @tests serialization/deserialization compatibility with RI.
120     */
121    @TestTargetNew(
122        level = TestLevel.COMPLETE,
123        notes = "",
124        method = "!SerializationGolden",
125        args = {}
126    )
127    public void testSerializationCompatibility() throws Exception {
128
129        SerializationTest.verifyGolden(this, new MissingFormatWidthException(
130                "MYTESTSTRING"), exComparator);
131    }
132}
133