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