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 java.io.Serializable;
20import java.util.IllegalFormatConversionException;
21
22import junit.framework.TestCase;
23
24import org.apache.harmony.testframework.serialization.SerializationTest;
25import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
26
27public class IllegalFormatConversionExceptionTest extends TestCase {
28
29    /**
30     * @tests java.util.IllegalFormatConversionException#IllegalFormatConversionException(char,
31     *        Class)
32     */
33    public void test_illegalFormatConversionException() {
34        try {
35            new IllegalFormatConversionException(' ', null);
36            fail("should throw NullPointerExcetpion.");
37        } catch (NullPointerException e) {
38            // desired
39        }
40    }
41
42    /**
43     * @tests java.util.IllegalFormatConversionException#getArgumentClass()
44     */
45    public void test_getArgumentClass() {
46        char c = '*';
47        Class<String> argClass = String.class;
48        IllegalFormatConversionException illegalFormatConversionException = new IllegalFormatConversionException(
49                c, argClass);
50        assertEquals(argClass, illegalFormatConversionException
51                .getArgumentClass());
52
53    }
54
55    /**
56     * @tests java.util.IllegalFormatConversionException#getConversion()
57     */
58    public void test_getConversion() {
59        char c = '*';
60        Class<String> argClass = String.class;
61        IllegalFormatConversionException illegalFormatConversionException = new IllegalFormatConversionException(
62                c, argClass);
63        assertEquals(c, illegalFormatConversionException.getConversion());
64
65    }
66
67    /**
68     * @tests java.util.IllegalFormatConversionException#getMessage()
69     */
70    public void test_getMessage() {
71        char c = '*';
72        Class<String> argClass = String.class;
73        IllegalFormatConversionException illegalFormatConversionException = new IllegalFormatConversionException(
74                c, argClass);
75        assertTrue(null != illegalFormatConversionException.getMessage());
76
77    }
78
79    // comparator for IllegalFormatConversionException objects
80    private static final SerializableAssert exComparator = new SerializableAssert() {
81        public void assertDeserialized(Serializable initial,
82                Serializable deserialized) {
83
84            SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial,
85                    deserialized);
86
87            IllegalFormatConversionException initEx = (IllegalFormatConversionException) initial;
88            IllegalFormatConversionException desrEx = (IllegalFormatConversionException) deserialized;
89
90            assertEquals("ArgumentClass", initEx.getArgumentClass(), desrEx
91                    .getArgumentClass());
92            assertEquals("Conversion", initEx.getConversion(), desrEx
93                    .getConversion());
94        }
95    };
96
97    /**
98     * @tests serialization/deserialization.
99     */
100    public void testSerializationSelf() throws Exception {
101
102        SerializationTest.verifySelf(new IllegalFormatConversionException('*',
103                String.class), exComparator);
104    }
105
106    /**
107     * @tests serialization/deserialization compatibility with RI.
108     */
109    public void testSerializationCompatibility() throws Exception {
110
111        SerializationTest.verifyGolden(this,
112                new IllegalFormatConversionException('*', String.class),
113                exComparator);
114    }
115}
116