UnknownFormatFlagsExceptionTest.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 */
16
17package org.apache.harmony.luni.tests.java.util;
18
19import dalvik.annotation.TestTargets;
20import dalvik.annotation.TestLevel;
21import dalvik.annotation.TestTargetNew;
22import dalvik.annotation.TestTargetClass;
23
24import junit.framework.TestCase;
25
26import java.io.Serializable;
27import java.util.UnknownFormatFlagsException;
28
29import org.apache.harmony.testframework.serialization.SerializationTest;
30import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
31
32@TestTargetClass(UnknownFormatFlagsException.class)
33public class UnknownFormatFlagsExceptionTest extends TestCase {
34
35    /**
36     * @tests java.util.UnknownFormatFlagsException#UnknownFormatFlagsException(String)
37     */
38    @TestTargetNew(
39        level = TestLevel.COMPLETE,
40        notes = "",
41        method = "UnknownFormatFlagsException",
42        args = {java.lang.String.class}
43    )
44    public void test_unknownFormatFlagsException() {
45
46        try {
47            new UnknownFormatFlagsException(null);
48            fail("should throw NullPointerExcepiton");
49        } catch (NullPointerException e) {
50            // expected
51        }
52        assertNotNull(new UnknownFormatFlagsException("String"));
53    }
54
55    /**
56     * @tests java.util.UnknownFormatFlagsException#getFlags()
57     */
58    @TestTargetNew(
59        level = TestLevel.COMPLETE,
60        notes = "",
61        method = "getFlags",
62        args = {}
63    )
64    public void test_getFlags() {
65        String s = "MYTESTSTRING";
66        UnknownFormatFlagsException UnknownFormatFlagsException = new UnknownFormatFlagsException(
67                s);
68        assertEquals(s, UnknownFormatFlagsException.getFlags());
69    }
70
71    /**
72     * @tests java.util.UnknownFormatFlagsException#getMessage()
73     */
74    @TestTargetNew(
75        level = TestLevel.COMPLETE,
76        notes = "",
77        method = "getMessage",
78        args = {}
79    )
80    public void test_getMessage() {
81        String s = "MYTESTSTRING";
82        UnknownFormatFlagsException UnknownFormatFlagsException = new UnknownFormatFlagsException(
83                s);
84        assertNotNull(UnknownFormatFlagsException.getMessage());
85    }
86
87    // comparator for comparing UnknownFormatFlagsException 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            UnknownFormatFlagsException initEx = (UnknownFormatFlagsException) initial;
96            UnknownFormatFlagsException desrEx = (UnknownFormatFlagsException) deserialized;
97
98            assertEquals("Flags", initEx.getFlags(), desrEx.getFlags());
99        }
100    };
101
102    /**
103     * @tests serialization/deserialization.
104     */
105    @TestTargetNew(
106        level = TestLevel.COMPLETE,
107        notes = "",
108        method = "!SerializationSelf",
109        args = {}
110    )
111    public void testSerializationSelf() throws Exception {
112
113        SerializationTest.verifySelf(new UnknownFormatFlagsException(
114                "MYTESTSTRING"), exComparator);
115    }
116
117    /**
118     * @tests serialization/deserialization compatibility with RI.
119     */
120    @TestTargetNew(
121        level = TestLevel.COMPLETE,
122        notes = "",
123        method = "!SerializationGolden",
124        args = {}
125    )
126    public void testSerializationCompatibility() throws Exception {
127
128        SerializationTest.verifyGolden(this, new UnknownFormatFlagsException(
129                "MYTESTSTRING"), exComparator);
130    }
131}
132