Home | History | Annotate | Download | only in callback
      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.callback;
     19 
     20 import junit.framework.TestCase;
     21 
     22 import javax.security.auth.callback.UnsupportedCallbackException;
     23 import javax.security.auth.callback.Callback;
     24 
     25 /**
     26  * Tests for <code>UnsupportedCallbackException</code> class constructors and methods.
     27  *
     28  */
     29 public class UnsupportedCallbackExceptionTest extends TestCase {
     30 
     31     private static String[] msgs = {
     32             "",
     33             "Check new message",
     34             "Check new message Check new message Check new message Check new message Check new message" };
     35 
     36 
     37     /**
     38      * javax.security.auth.callback.UnsupportedCallbackExceptionTest#UnsupportedCallbackException(Callback callback)
     39      * javax.security.auth.callback.UnsupportedCallbackExceptionTest#getCallback()
     40      * Assertion: constructs with null parameter.
     41      */
     42     public void testUnsupportedCallbackException01() {
     43         Callback c = null;
     44         UnsupportedCallbackException ucE = new UnsupportedCallbackException(c);
     45         assertNull("getMessage() must return null.", ucE.getMessage());
     46         assertNull("getCallback() must return null", ucE.getCallback());
     47     }
     48 
     49     /**
     50      * javax.security.auth.callback.UnsupportedCallbackExceptionTest#UnsupportedCallbackException(Callback callback)
     51      * javax.security.auth.callback.UnsupportedCallbackExceptionTest#getCallback()
     52      * Assertion: constructs with not null parameter.
     53      */
     54     public void testUnsupportedCallbackException02() {
     55         myCallback c = new myCallback();
     56         assertNotNull("Callback object is null", c);
     57         UnsupportedCallbackException ucE = new UnsupportedCallbackException(c);
     58         assertNull("getMessage() must return null.", ucE.getMessage());
     59         assertEquals("Incorrect callback object was returned", c, ucE.getCallback());
     60     }
     61 
     62     /**
     63      * javax.security.auth.callback.UnsupportedCallbackExceptionTest#UnsupportedCallbackException(Callback callback, String msg)
     64      * Assertion: constructs with null callback parameter and null message.
     65      */
     66     public void testUnsupportedCallbackException03() {
     67         UnsupportedCallbackException ucE = new UnsupportedCallbackException(null, null);
     68         assertNull("getMessage() must return null.", ucE.getMessage());
     69         assertNull("getCallback() must return null.", ucE.getCallback());
     70     }
     71 
     72     /**
     73      * javax.security.auth.callback.UnsupportedCallbackExceptionTest#UnsupportedCallbackException(Callback callback, String msg)
     74      * Assertion: constructs with null callback parameter and not null message.
     75      */
     76     public void testUnsupportedCallbackException04() {
     77         UnsupportedCallbackException ucE;
     78         for (int i = 0; i < msgs.length; i++) {
     79             ucE = new UnsupportedCallbackException(null, msgs[i]);
     80             assertEquals("getMessage() must return: ".concat(msgs[i]), ucE.getMessage(), msgs[i]);
     81             assertNull("getCallback() must return null.", ucE.getCallback());
     82         }
     83     }
     84 
     85     /**
     86      * javax.security.auth.callback.UnsupportedCallbackExceptionTest#UnsupportedCallbackException(Callback callback, String msg)
     87      * Assertion: constructs with not null callback parameter and null message.
     88      */
     89     public void testUnsupportedCallbackException05() {
     90         myCallback c = new myCallback();
     91         assertNotNull("Callback object is null", c);
     92         UnsupportedCallbackException ucE = new UnsupportedCallbackException(c, null);
     93         assertNull("getMessage() must return null.", ucE.getMessage());
     94         assertEquals("Incorrect callback object was returned", c, ucE.getCallback());
     95     }
     96 
     97     /**
     98      * javax.security.auth.callback.UnsupportedCallbackExceptionTest#UnsupportedCallbackException(Callback callback, String msg)
     99      * Assertion: constructs with not null parameters.
    100      */
    101     public void testUnsupportedCallbackException06() {
    102         myCallback c = new myCallback();
    103         assertNotNull("Callback object is null", c);
    104         UnsupportedCallbackException ucE;
    105         for (int i = 0; i < msgs.length; i++) {
    106             ucE = new UnsupportedCallbackException(c, msgs[i]);
    107             assertEquals("getMessage() must return: ".concat(msgs[i]), ucE.getMessage(), msgs[i]);
    108             assertEquals("Incorrect callback object was returned", c, ucE.getCallback());
    109         }
    110     }
    111 }
    112 
    113 class myCallback implements Callback {
    114     myCallback(){
    115     }
    116 }
    117 
    118