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 Vera Y. Petrashkova 20 * @version $Revision$ 21 */ 22 23 package org.apache.harmony.crypto.tests.javax.crypto; 24 25 import javax.crypto.ExemptionMechanismException; 26 27 import junit.framework.TestCase; 28 29 /** 30 * Tests for <code>ExemptionMechanismException</code> class constructors and 31 * methods. 32 * 33 */ 34 public class ExemptionMechanismExceptionTest extends TestCase { 35 36 static String[] msgs = { 37 "", 38 "Check new message", 39 "Check new message Check new message Check new message Check new message Check new message" }; 40 41 static Throwable tCause = new Throwable("Throwable for exception"); 42 43 static String createErr(Exception tE, Exception eE) { 44 return "ExemptionMechanismException: ".concat(tE.toString()).concat( 45 " is not equal to caught exception: ").concat(eE.toString()); 46 } 47 48 /** 49 * Test for <code>ExemptionMechanismException()</code> constructor 50 * Assertion: constructs ExemptionMechanismException with no detail message 51 */ 52 public void testExemptionMechanismException01() { 53 ExemptionMechanismException tE = new ExemptionMechanismException(); 54 assertNull("getMessage() must return null.", tE.getMessage()); 55 assertNull("getCause() must return null", tE.getCause()); 56 try { 57 throw tE; 58 } catch (Exception e) { 59 assertTrue(createErr(tE, e), tE.equals(e)); 60 } 61 } 62 63 /** 64 * Test for <code>ExemptionMechanismException(String)</code> constructor 65 * Assertion: constructs ExemptionMechanismException with detail message 66 * msg. Parameter <code>msg</code> is not null. 67 */ 68 public void testExemptionMechanismException02() { 69 ExemptionMechanismException tE; 70 for (int i = 0; i < msgs.length; i++) { 71 tE = new ExemptionMechanismException(msgs[i]); 72 assertEquals("getMessage() must return: ".concat(msgs[i]), tE 73 .getMessage(), msgs[i]); 74 assertNull("getCause() must return null", tE.getCause()); 75 try { 76 throw tE; 77 } catch (Exception e) { 78 assertTrue(createErr(tE, e), tE.equals(e)); 79 } 80 } 81 } 82 83 /** 84 * Test for <code>ExemptionMechanismException(String)</code> constructor 85 * Assertion: constructs ExemptionMechanismException when <code>msg</code> 86 * is null 87 */ 88 public void testExemptionMechanismException03() { 89 String msg = null; 90 ExemptionMechanismException tE = new ExemptionMechanismException(msg); 91 assertNull("getMessage() must return null.", tE.getMessage()); 92 assertNull("getCause() must return null", tE.getCause()); 93 try { 94 throw tE; 95 } catch (Exception e) { 96 assertTrue(createErr(tE, e), tE.equals(e)); 97 } 98 } 99 100 } 101