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.net; 19 20import dalvik.annotation.TestTargetClass; 21import dalvik.annotation.TestTargets; 22import dalvik.annotation.TestLevel; 23import dalvik.annotation.TestTargetNew; 24 25import java.net.PasswordAuthentication; 26 27@TestTargetClass(PasswordAuthentication.class) 28public class PasswordAuthenticationTest extends junit.framework.TestCase { 29 30 /** 31 * @tests java.net.PasswordAuthentication#PasswordAuthentication(java.lang.String, 32 * char[]) 33 */ 34 @TestTargets({ 35 @TestTargetNew( 36 level = TestLevel.COMPLETE, 37 notes = "", 38 method = "PasswordAuthentication", 39 args = {java.lang.String.class, char[].class} 40 ), 41 @TestTargetNew( 42 level = TestLevel.COMPLETE, 43 notes = "", 44 method = "getPassword", 45 args = {} 46 ), 47 @TestTargetNew( 48 level = TestLevel.COMPLETE, 49 notes = "", 50 method = "getUserName", 51 args = {} 52 ) 53 }) 54 public void test_ConstructorLjava_lang_String$C() { 55 // Test for method java.net.PasswordAuthentication(java.lang.String, 56 // char []) 57 char[] password = new char[] { 'd', 'r', 'o', 'w', 's', 's', 'a', 'p' }; 58 final String name = "Joe Blow"; 59 PasswordAuthentication pa = new PasswordAuthentication(name, password); 60 char[] returnedPassword = pa.getPassword(); 61 assertTrue("Incorrect name", pa.getUserName().equals(name)); 62 assertTrue("Password was not cloned", returnedPassword != password); 63 assertTrue("Passwords not equal length", 64 returnedPassword.length == password.length); 65 for (int counter = password.length - 1; counter >= 0; counter--) 66 assertTrue("Passwords not equal", 67 returnedPassword[counter] == password[counter]); 68 69 try { 70 new PasswordAuthentication(name, null); 71 fail("NullPointerException was not thrown."); 72 } catch(NullPointerException npe) { 73 //expected 74 } 75 76 pa = new PasswordAuthentication(null, password); 77 assertNull(pa.getUserName()); 78 assertEquals(password.length, pa.getPassword().length); 79 } 80 81 /** 82 * Sets up the fixture, for example, open a network connection. This method 83 * is called before a test is executed. 84 */ 85 protected void setUp() { 86 } 87 88 /** 89 * Tears down the fixture, for example, close a network connection. This 90 * method is called after a test is executed. 91 */ 92 protected void tearDown() { 93 } 94} 95