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