1/**
2 *
3 */
4package org.junit.internal.runners.statements;
5
6import org.junit.internal.AssumptionViolatedException;
7import org.junit.runners.model.Statement;
8
9public class ExpectException extends Statement {
10	private Statement fNext;
11	private final Class<? extends Throwable> fExpected;
12
13	public ExpectException(Statement next, Class<? extends Throwable> expected) {
14		fNext= next;
15		fExpected= expected;
16	}
17
18	@Override
19	public void evaluate() throws Exception {
20		boolean complete = false;
21		try {
22			fNext.evaluate();
23			complete = true;
24		} catch (AssumptionViolatedException e) {
25			throw e;
26		} catch (Throwable e) {
27			if (!fExpected.isAssignableFrom(e.getClass())) {
28				String message= "Unexpected exception, expected<"
29							+ fExpected.getName() + "> but was<"
30							+ e.getClass().getName() + ">";
31				throw new Exception(message, e);
32			}
33		}
34		if (complete)
35			throw new AssertionError("Expected exception: "
36					+ fExpected.getName());
37	}
38}