< prev index next >

test/lib/testlibrary/AssertsTest.java

Print this page
rev 1531 : 8171415: Remove Java 7 features from testlibrary
Reviewed-by: omajid

*** 36,45 **** --- 36,47 ---- public int compareTo(Foo f) { return new Integer(id).compareTo(new Integer(f.id)); } } + private static final Foo NULL = null; + public static void main(String[] args) throws Exception { testLessThan(); testLessThanOrEqual(); testEquals(); testGreaterThanOrEqual();
*** 69,79 **** expectFail(Assertion.LTE, 2, null); } private static void testEquals() throws Exception { expectPass(Assertion.EQ, 1, 1); ! expectPass(Assertion.EQ, null, null); Foo f1 = new Foo(1); expectPass(Assertion.EQ, f1, f1); Foo f2 = new Foo(1); --- 71,81 ---- expectFail(Assertion.LTE, 2, null); } private static void testEquals() throws Exception { expectPass(Assertion.EQ, 1, 1); ! expectPass(Assertion.EQ, NULL, NULL); Foo f1 = new Foo(1); expectPass(Assertion.EQ, f1, f1); Foo f2 = new Foo(1);
*** 106,149 **** Foo f1 = new Foo(1); Foo f2 = new Foo(1); expectPass(Assertion.NE, f1, f2); ! expectFail(Assertion.NE, null, null); expectFail(Assertion.NE, f1, f1); expectFail(Assertion.NE, 1, 1); } private static void testNull() throws Exception { ! expectPass(Assertion.NULL, null); expectFail(Assertion.NULL, 1); } private static void testNotNull() throws Exception { expectPass(Assertion.NOTNULL, 1); ! expectFail(Assertion.NOTNULL, null); } private static void testTrue() throws Exception { ! expectPass(Assertion.TRUE, true); ! expectFail(Assertion.TRUE, false); } private static void testFalse() throws Exception { ! expectPass(Assertion.FALSE, false); ! expectFail(Assertion.FALSE, true); } private static <T extends Comparable<T>> void expectPass(Assertion assertion, T ... args) throws Exception { Assertion.run(assertion, args); } private static <T extends Comparable<T>> void expectFail(Assertion assertion, T ... args) throws Exception { try { Assertion.run(assertion, args); } catch (RuntimeException e) { --- 108,156 ---- Foo f1 = new Foo(1); Foo f2 = new Foo(1); expectPass(Assertion.NE, f1, f2); ! expectFail(Assertion.NE, NULL, NULL); expectFail(Assertion.NE, f1, f1); expectFail(Assertion.NE, 1, 1); } private static void testNull() throws Exception { ! expectPass(Assertion.NULL, NULL); expectFail(Assertion.NULL, 1); } private static void testNotNull() throws Exception { expectPass(Assertion.NOTNULL, 1); ! expectFail(Assertion.NOTNULL, NULL); } private static void testTrue() throws Exception { ! expectPassBool(Assertion.TRUE, true); ! expectFailBool(Assertion.TRUE, false); } private static void testFalse() throws Exception { ! expectPassBool(Assertion.FALSE, false); ! expectFailBool(Assertion.FALSE, true); } private static <T extends Comparable<T>> void expectPass(Assertion assertion, T ... args) throws Exception { Assertion.run(assertion, args); } + private static void expectPassBool(Assertion assertion, boolean bool) + throws Exception { + Assertion.runBool(assertion, bool); + } + private static <T extends Comparable<T>> void expectFail(Assertion assertion, T ... args) throws Exception { try { Assertion.run(assertion, args); } catch (RuntimeException e) {
*** 151,167 **** } throw new Exception("Expected " + Assertion.format(assertion, (Object[]) args) + " to throw a RuntimeException"); } } enum Assertion { LT, LTE, EQ, GTE, GT, NE, NULL, NOTNULL, FALSE, TRUE; public static <T extends Comparable<T>> void run(Assertion assertion, T ... args) { ! String msg = "Expected " + format(assertion, args) + " to pass"; switch (assertion) { case LT: assertLessThan(args[0], args[1], msg); break; case LTE: --- 158,184 ---- } throw new Exception("Expected " + Assertion.format(assertion, (Object[]) args) + " to throw a RuntimeException"); } + private static void expectFailBool(Assertion assertion, boolean bool) + throws Exception { + try { + Assertion.runBool(assertion, bool); + } catch (RuntimeException e) { + return; + } + throw new Exception("Expected " + Assertion.format(assertion, bool + + " to throw a RuntimeException")); + } } enum Assertion { LT, LTE, EQ, GTE, GT, NE, NULL, NOTNULL, FALSE, TRUE; 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:
*** 183,197 **** 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 } } --- 200,224 ---- assertNull(args == null ? args : args[0], msg); break; case NOTNULL: assertNotNull(args == null ? args : args[0], msg); break; + default: + // do nothing + } + } + + public static void runBool(Assertion assertion, Boolean bool) { + String msg = "Expected " + format(assertion, bool) + " to pass"; + switch (assertion) { case FALSE: ! System.err.println("assertFalse(" + bool + ", " + msg + ")"); ! assertFalse(bool, msg); break; case TRUE: ! System.err.println("assertTrue(" + bool + ", " + msg + ")"); ! assertTrue(bool, msg); break; default: // do nothing } }
< prev index next >