All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.junit.internal.runners.statements.FailOnTimeout Maven / Gradle / Ivy

Go to download

JUnit is a regression testing framework written by Erich Gamma and Kent Beck. It is used by the developer who implements unit tests in Java.

There is a newer version: 4.11
Show newest version
/**
 * 
 */
package org.junit.internal.runners.statements;

import org.junit.runners.model.Statement;

public class FailOnTimeout extends Statement {
	private Statement fNext;

	private final long fTimeout;

	private boolean fFinished= false;

	private Throwable fThrown= null;

	public FailOnTimeout(Statement next, long timeout) {
		fNext= next;
		fTimeout= timeout;
	}

	@Override
	public void evaluate() throws Throwable {
		Thread thread= new Thread() {
			@Override
			public void run() {
				try {
					fNext.evaluate();
					fFinished= true;
				} catch (Throwable e) {
					fThrown= e;
				}
			}
		};
		thread.start();
		thread.join(fTimeout);
		if (fFinished)
			return;
		if (fThrown != null)
			throw fThrown;
		Exception exception= new Exception(String.format(
				"test timed out after %d milliseconds", fTimeout));
		exception.setStackTrace(thread.getStackTrace());
		throw exception;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy