當前位置: 首頁>>代碼示例>>Java>>正文


Java AssertionFailedError.initCause方法代碼示例

本文整理匯總了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());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:JSR166TestCase.java

示例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 ();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:EvaluatorTest.java

示例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");
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:30,代碼來源:JSR166TestCase.java

示例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;
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:17,代碼來源:AbstractFutureTest.java

示例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;
    }
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:20,代碼來源:JSR166TestCase.java

示例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;
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:JSR166TestCase.java

示例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;
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:JSR166TestCase.java

示例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;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:8,代碼來源:FileEncodingQueryDataEditorSupportTest.java

示例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;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:13,代碼來源:DataShadowBrokenAreNotTestedTest.java

示例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;
    }
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:15,代碼來源:JSR166TestCase.java

示例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;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:10,代碼來源:AddRemoveNotifyRaceConditionTest.java

示例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 ();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:32,代碼來源:EvaluatorTest.java

示例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;
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:11,代碼來源:AbstractPackageSanityTests.java

示例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;
  }
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:15,代碼來源:TestPlatform.java

示例15: failureWithCause

import junit.framework.AssertionFailedError; //導入方法依賴的package包/類
static AssertionFailedError failureWithCause(Throwable cause, String message) {
  AssertionFailedError failure = new AssertionFailedError(message);
  failure.initCause(cause);
  return failure;
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:6,代碼來源:FuturesTest.java


注:本文中的junit.framework.AssertionFailedError.initCause方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。