⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exceptiontestcase.java

📁 JAVA 数学程序库 提供常规的数值计算程序包
💻 JAVA
字号:
package jmathlib.tools.junit.extensions;

import jmathlib.tools.junit.framework.*;

/**
 * A TestCase that expects an Exception of class fExpected to be thrown.
 * The other way to check that an expected exception is thrown is:
 * <pre>
 * try {
 *   shouldThrow();
 * }
 * catch (SpecialException e) {
 *   return;
 * }
 * fail("Expected SpecialException");
 * </pre>
 *
 * To use ExceptionTestCase, create a TestCase like:
 * <pre>
 * new ExceptionTestCase("testShouldThrow", SpecialException.class);
 * </pre>
 */
public class ExceptionTestCase extends TestCase {
	Class fExpected;

	public ExceptionTestCase(String name, Class exception) {
		super(name);
		fExpected= exception;
	}
	/**
	 * Execute the test method expecting that an Exception of
	 * class fExpected or one of its subclasses will be thrown
	 */
	protected void runTest() throws Throwable {
		try {
			super.runTest();
		}
		catch (Exception e) {
			if (fExpected.isAssignableFrom(e.getClass()))
				return;
			else
				throw e;
		}
		fail("Expected exception " + fExpected);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -