1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 package org.apache.myfaces; 20 21 /** 22 * Provides various assert calls which can be used for tests. 23 * 24 * @author Mathias Broekelmann (latest modification by $Author: mbr $) 25 * @version $Revision: 514642 $ $Date: 2007-03-05 05:49:41 -0500 (Mon, 05 Mar 2007) $ 26 */ 27 public class Assert 28 { 29 protected Assert() 30 { 31 } 32 33 /** 34 * Asserts that the execution of the {@link TestRunner#run()} method will throw the <code>expected</code> 35 * exception 36 * 37 * @param expected 38 * the expected Exception 39 * @param testCase 40 * the testcase to run 41 */ 42 public static void assertException(Class<? extends Throwable> expected, TestRunner testCase) 43 { 44 junit.framework.Assert.assertNotNull(expected); 45 junit.framework.Assert.assertNotNull(testCase); 46 try 47 { 48 testCase.run(); 49 } 50 catch (Throwable e) 51 { 52 if (!expected.isAssignableFrom(e.getClass())) 53 { 54 AssertionError assertionError = new AssertionError("caught exception <" + e.getClass() 55 + "> does not match expected <" + expected + ">: " + e.getMessage()); 56 assertionError.initCause(e); 57 throw assertionError; 58 } 59 return; 60 } 61 junit.framework.Assert.fail(expected.getName() + " expected"); 62 } 63 64 }