Diff for ExpectException.java

Created Diff never expires
2 removals
Lines
Total
Removed
Words
Total
Removed
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
43 lines
6 additions
Lines
Total
Added
Words
Total
Added
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
47 lines
package org.junit.internal.runners.statements;
package org.junit.internal.runners.statements;


import org.junit.internal.AssumptionViolatedException;
import org.junit.internal.AssumptionViolatedException;
import org.junit.runners.model.Statement;
import org.junit.runners.model.Statement;
import com.ibm.jit.JITHelpers;
import com.ibm.jit.JITHelpers;
public class ExpectException extends Statement {
public class ExpectException extends Statement {
private final Statement next;
private final Statement next;
private final Class<? extends Throwable> expected;
private final Class<? extends Throwable> expected;


public ExpectException(Statement next, Class<? extends Throwable> expected) {
public ExpectException(Statement next, Class<? extends Throwable> expected) {
this.next = next;
this.next = next;
this.expected = expected;
this.expected = expected;
}
}


@Override
@Override
public void evaluate() throws Exception {
public void evaluate() throws Exception {
boolean complete = false;
boolean complete = false;
com.ibm.jit.JITHelpers.setExpectedException(expected);
// get VM thread
Thread t = java.lang.Thread.currentThread();
String name = t.getName();

com.ibm.jit.JITHelpers.setExpectedException(expected, name);
System.out.println("Setting expected exception to " + expected.getName());
System.out.println("Setting expected exception to " + expected.getName());
try {
try {
next.evaluate();
next.evaluate();
complete = true;
complete = true;
} catch (AssumptionViolatedException e) {
} catch (AssumptionViolatedException e) {
if (!expected.isAssignableFrom(e.getClass())) {
if (!expected.isAssignableFrom(e.getClass())) {
throw e;
throw e;
}
}
} catch (Throwable e) {
} catch (Throwable e) {
if (!expected.isAssignableFrom(e.getClass())) {
if (!expected.isAssignableFrom(e.getClass())) {
String message = "Unexpected exception, expected<"
String message = "Unexpected exception, expected<"
+ expected.getName() + "> but was<"
+ expected.getName() + "> but was<"
+ e.getClass().getName() + ">";
+ e.getClass().getName() + ">";
throw new Exception(message, e);
throw new Exception(message, e);
}
}
} finally {
} finally {
System.out.println("Clearing expected exception");
System.out.println("Clearing expected exception");
com.ibm.jit.JITHelpers.setExpectedException(null);
com.ibm.jit.JITHelpers.setExpectedException(null, name);
}
}
if (complete) {
if (complete) {
throw new AssertionError("Expected exception: "
throw new AssertionError("Expected exception: "
+ expected.getName());
+ expected.getName());
}
}
}
}
}
}