MissingResourceExceptionTest.java revision f6c387128427e121477c1b32ad35cdcaa5101ba3
1/*
2 *  Licensed to the Apache Software Foundation (ASF) under one or more
3 *  contributor license agreements.  See the NOTICE file distributed with
4 *  this work for additional information regarding copyright ownership.
5 *  The ASF licenses this file to You under the Apache License, Version 2.0
6 *  (the "License"); you may not use this file except in compliance with
7 *  the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  See the License for the specific language governing permissions and
15 *  limitations under the License.
16 */
17
18package tests.api.java.util;
19
20import dalvik.annotation.TestTargetNew;
21import dalvik.annotation.TestTargets;
22import dalvik.annotation.TestLevel;
23import dalvik.annotation.TestTargetClass;
24
25import java.util.Locale;
26import java.util.MissingResourceException;
27import java.util.ResourceBundle;
28
29@TestTargetClass(MissingResourceException.class)
30public class MissingResourceExceptionTest extends junit.framework.TestCase {
31
32    /**
33     * @tests java.util.MissingResourceException#MissingResourceException(java.lang.String,
34     *        java.lang.String, java.lang.String)
35     */
36    @TestTargetNew(
37        level = TestLevel.COMPLETE,
38        notes = "",
39        method = "MissingResourceException",
40        args = {java.lang.String.class, java.lang.String.class, java.lang.String.class}
41    )
42    public void test_ConstructorLjava_lang_StringLjava_lang_StringLjava_lang_String() {
43        // Test for method java.util.MissingResourceException(java.lang.String,
44        // java.lang.String, java.lang.String)
45        assertNotNull(new MissingResourceException("Detail string", "Class name string", "Key string"));
46        assertNotNull(new MissingResourceException(null, "Class name string", "Key string"));
47        assertNotNull(new MissingResourceException("Detail string", null, "Key string"));
48        assertNotNull(new MissingResourceException("Detail string", "Class name string", null));
49        try {
50            ResourceBundle.getBundle("Non-ExistentBundle");
51        } catch (MissingResourceException e) {
52            return;
53        }
54        fail("Failed to generate expected exception");
55    }
56
57    /**
58     * @tests java.util.MissingResourceException#getClassName()
59     */
60    @TestTargetNew(
61        level = TestLevel.COMPLETE,
62        notes = "",
63        method = "getClassName",
64        args = {}
65    )
66    public void test_getClassName() {
67        // Test for method java.lang.String
68        // java.util.MissingResourceException.getClassName()
69        try {
70            ResourceBundle.getBundle("Non-ExistentBundle");
71        } catch (MissingResourceException e) {
72            assertEquals("Returned incorrect class name", "Non-ExistentBundle"
73                    + '_' + Locale.getDefault(), e.getClassName());
74        }
75    }
76
77    /**
78     * @tests java.util.MissingResourceException#getKey()
79     */
80    @TestTargetNew(
81        level = TestLevel.COMPLETE,
82        notes = "",
83        method = "getKey",
84        args = {}
85    )
86    public void test_getKey() {
87        // Test for method java.lang.String
88        // java.util.MissingResourceException.getKey()
89        try {
90            ResourceBundle.getBundle("Non-ExistentBundle");
91        } catch (MissingResourceException e) {
92            assertTrue("Returned incorrect class name", e.getKey().equals(""));
93        }
94    }
95
96    /**
97     * Sets up the fixture, for example, open a network connection. This method
98     * is called before a test is executed.
99     */
100    protected void setUp() {
101    }
102
103    /**
104     * Tears down the fixture, for example, close a network connection. This
105     * method is called after a test is executed.
106     */
107    protected void tearDown() {
108    }
109}
110