本文整理匯總了Java中junit.framework.AssertionFailedError.initCause方法的典型用法代碼示例。如果您正苦於以下問題:Java AssertionFailedError.initCause方法的具體用法?Java AssertionFailedError.initCause怎麽用?Java AssertionFailedError.initCause使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類junit.framework.AssertionFailedError
的用法示例。
在下文中一共展示了AssertionFailedError.initCause方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: assertThrows
import junit.framework.AssertionFailedError; //導入方法依賴的package包/類
public void assertThrows(Class<? extends Throwable> expectedExceptionClass,
Runnable... throwingActions) {
for (Runnable throwingAction : throwingActions) {
boolean threw = false;
try { throwingAction.run(); }
catch (Throwable t) {
threw = true;
if (!expectedExceptionClass.isInstance(t)) {
AssertionFailedError afe =
new AssertionFailedError
("Expected " + expectedExceptionClass.getName() +
", got " + t.getClass().getName());
afe.initCause(t);
threadUnexpectedException(afe);
}
}
if (!threw)
shouldThrow(expectedExceptionClass.getName());
}
}
示例2: testStaticEvaluation
import junit.framework.AssertionFailedError; //導入方法依賴的package包/類
public void testStaticEvaluation () throws Exception {
try {
List<Method> methods = getMethods(true);
AssertionFailedError te = null;
AssertionFailedError ex = null;
for (Method m : methods) {
try {
checkEval (m);
} catch (AssertionFailedError e) {
if (te == null) {
te = ex = e;
} else {
ex.initCause(e);
ex = e;
}
}
}
if (te != null) {
throw te;
}
//checkEvalFails ("this");
checkEvalFails ("NoSuchClass.class");
} finally {
support.doFinish ();
}
}
示例3: tearDown
import junit.framework.AssertionFailedError; //導入方法依賴的package包/類
/**
* Extra checks that get done for all test cases.
*
* Triggers test case failure if any thread assertions have failed,
* by rethrowing, in the test harness thread, any exception recorded
* earlier by threadRecordFailure.
*
* Triggers test case failure if interrupt status is set in the main thread.
*/
public void tearDown() throws Exception {
Throwable t = threadFailure.getAndSet(null);
if (t != null) {
if (t instanceof Error)
throw (Error) t;
else if (t instanceof RuntimeException)
throw (RuntimeException) t;
else if (t instanceof Exception)
throw (Exception) t;
else {
AssertionFailedError afe =
new AssertionFailedError(t.toString());
afe.initCause(t);
throw afe;
}
}
if (Thread.interrupted())
throw new AssertionFailedError("interrupt status set in main thread");
}
示例4: findStackFrame
import junit.framework.AssertionFailedError; //導入方法依賴的package包/類
private static int findStackFrame(
ExecutionException e, String clazz, String method) {
StackTraceElement[] elements = e.getStackTrace();
for (int i = 0; i < elements.length; i++) {
StackTraceElement element = elements[i];
if (element.getClassName().equals(clazz)
&& element.getMethodName().equals(method)) {
return i;
}
}
AssertionFailedError failure =
new AssertionFailedError("Expected element " + clazz + "." + method
+ " not found in stack trace");
failure.initCause(e);
throw failure;
}
示例5: threadUnexpectedException
import junit.framework.AssertionFailedError; //導入方法依賴的package包/類
/**
* Records the given exception using {@link #threadRecordFailure},
* then rethrows the exception, wrapping it in an
* AssertionFailedError if necessary.
*/
public void threadUnexpectedException(Throwable t) {
threadRecordFailure(t);
t.printStackTrace();
if (t instanceof RuntimeException)
throw (RuntimeException) t;
else if (t instanceof Error)
throw (Error) t;
else {
AssertionFailedError afe =
new AssertionFailedError("unexpected exception: " + t);
afe.initCause(t);
throw afe;
}
}
示例6: sleep
import junit.framework.AssertionFailedError; //導入方法依賴的package包/類
/**
* Sleeps until the given time has elapsed.
* Throws AssertionFailedError if interrupted.
*/
static void sleep(long millis) {
try {
delay(millis);
} catch (InterruptedException fail) {
AssertionFailedError afe =
new AssertionFailedError("Unexpected InterruptedException");
afe.initCause(fail);
throw afe;
}
}
示例7: await
import junit.framework.AssertionFailedError; //導入方法依賴的package包/類
public int await() {
try {
return super.await(2 * LONG_DELAY_MS, MILLISECONDS);
} catch (TimeoutException timedOut) {
throw new AssertionFailedError("timed out");
} catch (Exception fail) {
AssertionFailedError afe =
new AssertionFailedError("Unexpected exception: " + fail);
afe.initCause(fail);
throw afe;
}
}
示例8: assertFile
import junit.framework.AssertionFailedError; //導入方法依賴的package包/類
private void assertFile(FileObject primaryFile) {
if (!primaryFile.equals(file)) {
AssertionFailedError afe = new AssertionFailedError("Files shall be the same:\nExpected:" + primaryFile + "\nReal :" + file);
afe.initCause(who);
throw afe;
}
}
示例9: assertAccess
import junit.framework.AssertionFailedError; //導入方法依賴的package包/類
public static void assertAccess(String msg, int expectURL, int expectFO) {
try {
DataShadow.waitUpdatesProcessed();
assertEquals(msg + " file object check", expectFO, toFOCnt);
assertEquals(msg + " to url check", expectURL, toURLCnt);
toFOCnt = 0;
toURLCnt = 0;
} catch (AssertionFailedError ex) {
if (lastAccess != null) ex.initCause(lastAccess);
throw ex;
}
}
示例10: sleep
import junit.framework.AssertionFailedError; //導入方法依賴的package包/類
/**
* Sleeps until the given time has elapsed.
* Throws AssertionFailedError if interrupted.
*/
void sleep(long millis) {
try {
delay(millis);
} catch (InterruptedException ie) {
AssertionFailedError afe =
new AssertionFailedError("Unexpected InterruptedException");
afe.initCause(ie);
throw afe;
}
}
示例11: runTest
import junit.framework.AssertionFailedError; //導入方法依賴的package包/類
protected void runTest () throws Throwable {
try {
super.runTest();
} catch (Error err) {
AssertionFailedError newErr = new AssertionFailedError (err.getMessage () + "\n" + ErrManager.messages);
newErr.initCause (err);
throw newErr;
}
}
示例12: runInstanceEvaluation
import junit.framework.AssertionFailedError; //導入方法依賴的package包/類
private void runInstanceEvaluation(int bpNo) throws Exception {
try {
Utils.BreakPositions bp = Utils.getBreakPositions(System.getProperty ("test.dir.src")+
"org/netbeans/api/debugger/jpda/testapps/EvaluatorApp.java");
LineBreakpoint lb = bp.getLineBreakpoints().get(bpNo);
DebuggerManager.getDebuggerManager ().addBreakpoint (lb);
support.doContinue();
support.waitState (JPDADebugger.STATE_STOPPED);
List<Method> methods = getMethods(false);
AssertionFailedError te = null;
AssertionFailedError ex = null;
for (Method m : methods) {
try {
checkEval (m);
} catch (AssertionFailedError e) {
if (te == null) {
te = ex = e;
} else {
ex.initCause(e);
ex = e;
}
}
}
if (te != null) {
throw te;
}
} finally {
support.doFinish ();
}
}
示例13: sanityError
import junit.framework.AssertionFailedError; //導入方法依賴的package包/類
private static AssertionFailedError sanityError(
Class<?> cls, List<String> explicitTestNames, String description, Throwable e) {
String message = String.format(Locale.ROOT,
"Error in automated %s of %s\n"
+ "If the class is better tested explicitly, you can add %s() to %sTest",
description, cls, explicitTestNames.get(0), cls.getName());
AssertionFailedError error = new AssertionFailedError(message);
error.initCause(e);
return error;
}
示例14: getDoneFromTimeoutOverload
import junit.framework.AssertionFailedError; //導入方法依賴的package包/類
/**
* Retrieves the result of a {@code Future} known to be done but uses the {@code get(long,
* TimeUnit)} overload in order to test that method.
*/
static <V> V getDoneFromTimeoutOverload(Future<V> future) throws ExecutionException {
checkState(future.isDone(), "Future was expected to be done: %s", future);
try {
return getUninterruptibly(future, 0, SECONDS);
} catch (TimeoutException e) {
AssertionFailedError error = new AssertionFailedError(e.getMessage());
error.initCause(e);
throw error;
}
}
示例15: failureWithCause
import junit.framework.AssertionFailedError; //導入方法依賴的package包/類
static AssertionFailedError failureWithCause(Throwable cause, String message) {
AssertionFailedError failure = new AssertionFailedError(message);
failure.initCause(cause);
return failure;
}