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.prefs.tests.java.util.prefs;
18
19import java.util.prefs.InvalidPreferencesFormatException;
20
21import junit.framework.TestCase;
22
23import org.apache.harmony.testframework.serialization.SerializationTest;
24
25/**
26 *
27 */
28public class InvalidPreferencesFormatExceptionTest extends TestCase {
29
30    /*
31     * Class under test for void InvalidPreferencesFormatException(String)
32     */
33    public void testInvalidPreferencesFormatExceptionString() {
34        InvalidPreferencesFormatException e = new InvalidPreferencesFormatException(
35        "msg");
36        assertNull(e.getCause());
37        assertEquals("msg", e.getMessage());
38    }
39
40    /*
41     * Class under test for void InvalidPreferencesFormatException(String,
42     * Throwable)
43     */
44    public void testInvalidPreferencesFormatExceptionStringThrowable() {
45        Throwable t = new Throwable("root");
46        InvalidPreferencesFormatException e = new InvalidPreferencesFormatException(
47                "msg", t);
48        assertSame(t, e.getCause());
49        assertTrue(e.getMessage().indexOf("root") < 0);
50        assertTrue(e.getMessage().indexOf(t.getClass().getName()) < 0);
51        assertTrue(e.getMessage().indexOf("msg") >= 0);
52    }
53
54    /*
55     * Class under test for void InvalidPreferencesFormatException(Throwable)
56     */
57    public void testInvalidPreferencesFormatExceptionThrowable() {
58        Throwable t = new Throwable("root");
59        InvalidPreferencesFormatException e = new InvalidPreferencesFormatException(
60                t);
61        assertSame(t, e.getCause());
62        assertTrue(e.getMessage().indexOf("root") >= 0);
63        assertTrue(e.getMessage().indexOf(t.getClass().getName()) >= 0);
64    }
65
66    /**
67     * @tests serialization/deserialization.
68     */
69    public void testSerializationSelf() throws Exception {
70
71        SerializationTest.verifySelf(new InvalidPreferencesFormatException(
72        "msg"));
73    }
74
75    /**
76     * @tests serialization/deserialization compatibility with RI.
77     */
78    public void testSerializationCompatibility() throws Exception {
79
80        SerializationTest.verifyGolden(this,
81                new InvalidPreferencesFormatException("msg"));
82    }
83}
84