Beispiel #1
0
  private static void testFail() throws Exception {
    try {
      fail();
    } catch (RuntimeException re) {
      assertEquals("fail", re.getMessage());
    }

    try {
      fail("Failure");
    } catch (RuntimeException re) {
      assertEquals("Failure", re.getMessage());
    }

    Exception e = new Exception("the cause");
    try {
      fail("Fail w/ cause", e);
    } catch (RuntimeException re) {
      assertEquals("Fail w/ cause", re.getMessage());
      assertEquals(e, re.getCause(), "Cause mismatch");
    }

    try {
      fail(1, 2, "Different", "vs");
    } catch (RuntimeException re) {
      assertEquals("Different <1> vs <2>", re.getMessage());
    }
  }
Beispiel #2
0
 @SuppressWarnings("unchecked")
 public static <T extends Comparable<T>> void run(Assertion assertion, T... args) {
   String msg = "Expected " + format(assertion, (Object[]) args) + " to pass";
   switch (assertion) {
     case LT:
       assertLessThan(args[0], args[1], msg);
       break;
     case LTE:
       assertLessThanOrEqual(args[0], args[1], msg);
       break;
     case EQ:
       assertEquals(args[0], args[1], msg);
       break;
     case GTE:
       assertGreaterThanOrEqual(args[0], args[1], msg);
       break;
     case GT:
       assertGreaterThan(args[0], args[1], msg);
       break;
     case NE:
       assertNotEquals(args[0], args[1], msg);
       break;
     case NULL:
       assertNull(args == null ? args : args[0], msg);
       break;
     case NOTNULL:
       assertNotNull(args == null ? args : args[0], msg);
       break;
     case FALSE:
       assertFalse((Boolean) args[0], msg);
       break;
     case TRUE:
       assertTrue((Boolean) args[0], msg);
       break;
     default:
       // do nothing
   }
 }