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
24
25import javax.security.auth.callback.PasswordCallback;
26
27import junit.framework.TestCase;
28
29/**
30 * Tests PasswordCallback class
31 */
32
33public class PasswordCallbackTest extends TestCase {
34
35    PasswordCallback pc;
36
37    public final void testPasswordCallback() {
38        pc = new PasswordCallback("prompt", true);
39        assertEquals("prompt", pc.getPrompt());
40        assertTrue(pc.isEchoOn());
41        pc.setPassword(null);
42        pc.clearPassword();
43        assertNull(pc.getPassword());
44        char[] pwd = {'a','b','c'};
45        pc.setPassword(pwd);
46        assertEquals(new String(pwd), new String(pc.getPassword()));
47        pc.clearPassword();
48        assertEquals(pwd.length, pc.getPassword().length);
49        assertFalse(new String(pwd).equals(pc.getPassword()));
50        char[] p = new char[5];
51        pc.setPassword(p);
52        pc.clearPassword();
53        assertEquals(p.length, pc.getPassword().length);
54    }
55
56    public final void testInit_01() {
57        try {
58        pc = new PasswordCallback("", true);
59        fail("Prompt and DefaultName should not be empty");
60        } catch (IllegalArgumentException e){}
61    }
62
63    public final void testInit_02() {
64        try {
65        pc = new PasswordCallback(null, true);
66        fail("Prompt and DefaultName should not null");
67        } catch (IllegalArgumentException e){}
68    }
69
70}
71