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 package org.apache.harmony.tests.javax.security.auth.login;
19 
20 import junit.framework.TestCase;
21 
22 import javax.security.auth.callback.PasswordCallback;
23 import javax.security.auth.login.LoginException;
24 import org.apache.harmony.testframework.serialization.SerializationTest;
25 
26 /**
27  * Tests for <code>LoginException</code> class constructors and methods.
28  *
29  */
30 public class LoginExceptionTest extends TestCase {
31 
32     private static String[] msgs = {
33             "",
34             "Check new message",
35             "Check new message Check new message Check new message Check new message Check new message" };
36 
37 
38     /**
39      * javax.security.auth.login.LoginException#LoginException()
40      * Assertion: constructs LoginException with no detail message
41      */
testLoginException01()42     public void testLoginException01() {
43         LoginException lE = new LoginException();
44         assertNull("getMessage() must return null.", lE.getMessage());
45         assertNull("getCause() must return null", lE.getCause());
46     }
47 
48     /**
49      * javax.security.auth.login.LoginException#LoginException(String msg)
50      * Assertion: constructs with not null parameter.
51      */
testLoginException02()52     public void testLoginException02() {
53         LoginException lE;
54         for (int i = 0; i < msgs.length; i++) {
55             lE = new LoginException(msgs[i]);
56             assertEquals("getMessage() must return: ".concat(msgs[i]), lE.getMessage(), msgs[i]);
57             assertNull("getCause() must return null", lE.getCause());
58         }
59     }
60 
61     /**
62      * javax.security.auth.login.LoginException#LoginException(String msg)
63      * Assertion: constructs with null parameter.
64      */
testLoginException03()65     public void testLoginException03() {
66         String msg = null;
67         LoginException lE = new LoginException(msg);
68         assertNull("getMessage() must return null.", lE.getMessage());
69         assertNull("getCause() must return null", lE.getCause());
70     }
71 
testSerializationSelf()72     public void testSerializationSelf() throws Exception {
73         SerializationTest.verifySelf(getSerializationData());
74     }
75 
testSerializationGolden()76     public void testSerializationGolden() throws Exception {
77         SerializationTest.verifyGolden(this, getSerializationData());
78     }
79 
getSerializationData()80     private Object[] getSerializationData() {
81         return new Object[] { new LoginException("message") };
82     }
83 }
84