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
18/**
19* @author Maxim V. Makarov
20*/
21
22package org.apache.harmony.auth.tests.javax.security.auth.callback;
23
24import javax.security.auth.callback.TextInputCallback;
25
26import junit.framework.TestCase;
27
28/**
29 * Tests TextInputCallback class
30 */
31
32public class TextInputCallbackTest extends TestCase {
33
34    TextInputCallback text;
35
36    /**
37     * Test for TextInputCallback(String), TextInputCallback(String, String) ctors
38     */
39    public final void testTextInputCallback_01() {
40        text = new TextInputCallback("prompt");
41        assertEquals("prompt", text.getPrompt());
42        text = new TextInputCallback("prompt", "defaultText");
43        assertEquals("prompt", text.getPrompt());
44        assertEquals("defaultText", text.getDefaultText());
45        text.setText("Text");
46        assertEquals("Text", text.getText());
47
48    }
49
50    /**
51     * Test for TextOutputCallback(String prompt,String defaultText) ctor
52     * if prompt or defaultText is null or empty then expected IAE
53     */
54    public final void testTextInputCallback_02() {
55        try {
56            text = new TextInputCallback("", "defaultText");
57            fail("Prompt and DefaultText should not be empty");
58        } catch (IllegalArgumentException e) {
59        }
60        try {
61            text = new TextInputCallback(null);
62            fail("Prompt and DefaultText should not be null");
63        } catch (IllegalArgumentException e) {
64        }
65        try {
66            text = new TextInputCallback(null, "defaultText");
67            fail("Prompt and DefaultText should not be null");
68        } catch (IllegalArgumentException e) {
69        }
70
71        try {
72            text = new TextInputCallback("prompt", "");
73            fail("Prompt and DefaultText should not be null");
74        } catch (IllegalArgumentException e) {
75        }
76
77        try {
78            text = new TextInputCallback("prompt", null);
79            fail("Prompt and DefaultText should not be null");
80        } catch (IllegalArgumentException e) {
81        }
82
83    }
84
85
86}
87