InputContextTest.java revision 14851:980da45565c8
1/*
2 * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24/*
25 * @test
26 * @key headful
27 * @bug 4151222
28 * @bug 4150206
29 * @bug 4243948
30 * @summary removeNotify(null) and selectInputMethod(null) have to
31 * throw a NullPointerException. selectInputMethod doesn't throw a
32 * NullPointerException.
33 */
34
35import java.awt.Frame;
36import java.awt.im.InputContext;
37import java.util.Locale;
38
39public class InputContextTest {
40
41    public static void main(String[] args) throws Exception {
42
43        Frame frame = new Frame();
44        InputContext ic = frame.getInputContext();
45
46        // 4151222
47        try {
48            ic.removeNotify(null);
49            throw new Exception("InputContext.removeNotify(null) doesn't throw NullPointerException");
50        } catch (Exception e) {
51            if (! (e instanceof NullPointerException)) {
52                throw new Exception("InputContext.removeNotify(null) throws " + e
53                                    + " instead of NullPointerException.");
54            }
55        }
56
57        // 4150206
58        try {
59            ic.selectInputMethod(null);
60            throw new Exception("InputContext.selectInputMethod(null) doesn't throw NullPointerException");
61        } catch (Exception e) {
62            if (! (e instanceof NullPointerException)) {
63                throw new Exception("InputContext.selectInputMethod(null) throws " + e
64                                    + " instead of NullPointerException.");
65            }
66        }
67
68        // 4243948
69        try {
70            ic.selectInputMethod(Locale.JAPANESE);
71        } catch (Exception e) {
72            throw new Exception("InputContext.selectInputMethod(Locale) throws " + e);
73        }
74    }
75}
76