Showing the changes to java/tests/utils/Utils.java (1 of 11 files). Show all
Unified · Split
| @@ -0,0 +1,61 @@ | |||
| 1 | |||
| 2 | package utils; | ||
| 3 | |||
| 4 | public class Utils { | ||
| 5 | |||
| 6 | public static class AssertionFailedException extends java.lang.RuntimeException { | ||
| 7 | public AssertionFailedException(String msg) { | ||
| 8 | super(msg); | ||
| 9 | System.err.println("Asserion failed: " + msg); | ||
| 10 | } | ||
| 11 | } | ||
| 12 | |||
| 13 | private Utils() { | ||
| 14 | } | ||
| 15 | |||
| 16 | public static void assertEquals(int expected, int found) throws AssertionFailedException { | ||
| 17 | assertEquals(expected, found, "expected " + expected + " but found " + found); | ||
| 18 | } | ||
| 19 | public static void assertEquals(int expected, int found, String msg) throws AssertionFailedException { | ||
| 20 | if (expected != found) | ||
| 21 | throw new AssertionFailedException(msg); | ||
| 22 | } | ||
| 23 | |||
| 24 | |||
| 25 | public static void assertEquals(long expected, long found) throws AssertionFailedException { | ||
| 26 | assertEquals(expected, found, "expected " + expected + " but found " + found); | ||
| 27 | } | ||
| 28 | public static void assertEquals(long expected, long found, String msg) throws AssertionFailedException { | ||
| 29 | if (expected != found) | ||
| 30 | throw new AssertionFailedException(msg); | ||
| 31 | } | ||
| 32 | |||
| 33 | public static void assertEquals(float expected, float found) throws AssertionFailedException { | ||
| 34 | assertEquals(expected, found, "expected " + expected + " but found " + found); | ||
| 35 | } | ||
| 36 | public static void assertEquals(float expected, float found, String msg) throws AssertionFailedException { | ||
| 37 | if (expected != found) | ||
| 38 | throw new AssertionFailedException(msg); | ||
| 39 | } | ||
| 40 | |||
| 41 | public static void assertEquals(double expected, double found) throws AssertionFailedException { | ||
| 42 | assertEquals(expected, found, "expected " + expected + " but found " + found); | ||
| 43 | } | ||
| 44 | public static void assertEquals(double expected, double found, String msg) throws AssertionFailedException { | ||
| 45 | if (expected != found) | ||
| 46 | throw new AssertionFailedException(msg); | ||
| 47 | } | ||
| 48 | |||
| 49 | public static void assertEquals(Object expected, Object found) throws AssertionFailedException { | ||
| 50 | assertEquals(expected, found, "expected " + expected + " but found " + found); | ||
| 51 | } | ||
| 52 | public static void assertEquals(Object expected, Object found, String msg) throws AssertionFailedException { | ||
| 53 | if (!expected.equals(found)) | ||
| 54 | throw new AssertionFailedException(msg); | ||
| 55 | } | ||
| 56 | |||
| 57 | public static void main(String[] args) { | ||
| 58 | // This is only for convenience, so that | ||
| 59 | // test system may assume this is also a test | ||
| 60 | } | ||
| 61 | } | ||