コード例 #1
0
ファイル: Log.java プロジェクト: JSansalone/NetBeansIDE
 static Throwable wrapWithAddendum(Throwable ex, String addendum, boolean after) {
   if (ex instanceof AssertionFailedError) {
     AssertionFailedError ne = new AssertionFailedError(combineMessages(ex, addendum, after));
     if (ex.getCause() != null) {
       ne.initCause(ex.getCause());
     }
     ne.setStackTrace(ex.getStackTrace());
     return ne;
   }
   if (ex instanceof AssertionError) { // preferred in JUnit 4
     AssertionError ne = new AssertionError(combineMessages(ex, addendum, after));
     if (ex.getCause() != null) {
       ne.initCause(ex.getCause());
     }
     ne.setStackTrace(ex.getStackTrace());
     return ne;
   }
   if (ex instanceof IOException) { // #66208
     IOException ne = new IOException(combineMessages(ex, addendum, after));
     if (ex.getCause() != null) {
       ne.initCause(ex.getCause());
     }
     ne.setStackTrace(ex.getStackTrace());
     return ne;
   }
   if (ex instanceof Exception) {
     return new InvocationTargetException(ex, combineMessages(ex, addendum, after));
   }
   return ex;
 }
コード例 #2
0
ファイル: ObjectChecker.java プロジェクト: akune/immutables
 static void fail(@Nullable Object actualValue, Matcher<?> matcher) {
   Description description =
       new StringDescription()
           .appendText("\nExpected: ")
           .appendDescriptionOf(matcher)
           .appendText("\n     but: ");
   matcher.describeMismatch(actualValue, description);
   AssertionError assertionError = new AssertionError(description.toString());
   assertionError.setStackTrace(ObjectChecker.trimStackTrace(assertionError.getStackTrace()));
   throw assertionError;
 }
コード例 #3
0
 private void verifyCount(
     DslStep step,
     ObjectSink node,
     InternalWorkingMemory wm,
     String[] cmd,
     Map<String, Object> context)
     throws AssertionError {
   int times = Integer.valueOf(cmd[3]);
   VerificationMode counter;
   if (times >= 0) {
     counter = times(times);
   } else {
     counter = atLeastOnce();
   }
   try {
     ArgumentCaptor<InternalFactHandle> captor = ArgumentCaptor.forClass(InternalFactHandle.class);
     if ("assert".equals(cmd[1])) {
       verify(node, counter)
           .assertObject(captor.capture(), any(PropagationContext.class), same(wm));
     } else if ("modify".equals(cmd[1])) {
       verify(node, counter)
           .modifyObject(
               captor.capture(),
               any(ModifyPreviousTuples.class),
               any(PropagationContext.class),
               same(wm));
     } else {
       throw new IllegalArgumentException(
           "line " + step.getLine() + ": command does not exist " + Arrays.toString(cmd));
     }
     String key = getCaptorKey(node, cmd);
     context.put(key, captor);
   } catch (MockitoAssertionError e) {
     AssertionError ae =
         new AssertionError("line " + step.getLine() + ": verify failed: " + e.getMessage());
     ae.setStackTrace(e.getStackTrace());
     throw ae;
   }
 }