/*
 * This file is covered by the terms of the Common Public License v1.0.
 *
 * Copyright (c) SZEDER Gábor
 *
 * Parts of this software were developed within the JEOPARD research
 * project, which received funding from the European Union's Seventh
 * Framework Programme under grant agreement No. 216682.
 */

package de.fzi.cjunit.jpf.inside;

import java.lang.reflect.InvocationTargetException;

public class TestMethod extends ReflectiveMethod {

	protected String expectedExceptionName;
	protected Throwable exception;

	public void setMethodName(String methodName) {
		this.methodName = methodName;
	}

	public void setExpectedExceptionName(String exceptionName) {
		this.expectedExceptionName = exceptionName;
	}

	public String getExpectedExceptionName() {
		return expectedExceptionName;
	}

	public Throwable getException() {
		return exception;
	}

	@Override
	public void invoke() {
		try {
			invokeMethod();
			exception = null;
		} catch (Throwable t) {
			exception = t;
		}
	}

	public void checkException() throws ClassNotFoundException,
			AssertionError, Exception, Throwable {
		if (exception == null) {
			if (isExpectingException()) {
				throw new AssertionError(
						"Expected exception: " +
						expectedExceptionName);
			}
		} else if (exception instanceof InvocationTargetException) {
			Throwable cause = exception.getCause();
			if (!isExpectingException()) {
				throw cause;
			}
			if (!isExpectedException(cause)) {
				String message
					= "Unexpected exception, expected<"
					+ expectedExceptionName + "> but was<"
					+ cause.getClass().getName() + ">";
				throw new Exception(message, cause);
			}
		} else {
			throw exception;
		}
	}

	public boolean isExpectingException() {
		return expectedExceptionName != null;
	}

	protected boolean isExpectedException(Throwable t)
			throws ClassNotFoundException {
		return Class.forName(expectedExceptionName)
				.isAssignableFrom(t.getClass());
	}
}

@@ -441,16 +441,36 @@
 eMethod 
+implements Runnable 
 %7B%0A%0A%09prot
@@ -1954,11 +1954,59 @@
 s());%0A%09%7D
+%0A%0A%09@Override%0A%09public void run() %7B%0A%09%09invoke();%0A%09%7D
 %0A%7D%0A

implement Runnable interface