Created
October 23, 2021 05:22
-
-
Save qasimy123/56f3f69b2315551268e71e3276f8d385 to your computer and use it in GitHub Desktop.
Modified ExpectException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.junit.internal.runners.statements; | |
import org.junit.internal.AssumptionViolatedException; | |
import org.junit.runners.model.Statement; | |
import com.ibm.jit.JITHelpers; | |
public class ExpectException extends Statement { | |
private final Statement next; | |
private final Class<? extends Throwable> expected; | |
public ExpectException(Statement next, Class<? extends Throwable> expected) { | |
this.next = next; | |
this.expected = expected; | |
} | |
@Override | |
public void evaluate() throws Exception { | |
boolean complete = false; | |
com.ibm.jit.JITHelpers.setExpectedException(expected); | |
System.out.println("Setting expected exception to " + expected.getName()); | |
try { | |
next.evaluate(); | |
complete = true; | |
} catch (AssumptionViolatedException e) { | |
if (!expected.isAssignableFrom(e.getClass())) { | |
throw e; | |
} | |
} catch (Throwable e) { | |
if (!expected.isAssignableFrom(e.getClass())) { | |
String message = "Unexpected exception, expected<" | |
+ expected.getName() + "> but was<" | |
+ e.getClass().getName() + ">"; | |
throw new Exception(message, e); | |
} | |
} finally { | |
System.out.println("Clearing expected exception"); | |
com.ibm.jit.JITHelpers.setExpectedException(null); | |
} | |
if (complete) { | |
throw new AssertionError("Expected exception: " | |
+ expected.getName()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment