1 16 package junit.framework; 17 18 21 public class Assert { 22 public static void assertEquals(boolean obj1, boolean obj2) { 23 assertEquals("", obj1, obj2); 24 } 25 26 public static void assertEquals(byte obj1, byte obj2) { 27 assertEquals("", obj1, obj2); 28 } 29 30 public static void assertEquals(char obj1, char obj2) { 31 assertEquals("", obj1, obj2); 32 } 33 34 public static void assertEquals(double obj1, double obj2, double delta) { 35 assertEquals("", obj1, obj2, delta); 36 } 37 38 public static void assertEquals(float obj1, float obj2, float delta) { 39 assertEquals("", obj1, obj2, delta); 40 } 41 42 public static void assertEquals(int expected, int actual) { 43 assertEquals("", expected, actual); 44 } 45 46 public static void assertEquals(long obj1, long obj2) { 47 assertEquals("", obj1, obj2); 48 } 49 50 public static void assertEquals(Object obj1, Object obj2) { 51 assertEquals("", obj1, obj2); 52 } 53 54 public static void assertEquals(String str, boolean obj1, boolean obj2) { 55 assertEquals(str, Boolean.valueOf(obj1), Boolean.valueOf(obj2)); 56 } 57 58 public static void assertEquals(String str, byte obj1, byte obj2) { 59 assertEquals(str, new Byte (obj1), new Byte (obj2)); 60 } 61 62 public static void assertEquals(String str, char obj1, char obj2) { 63 assertEquals(str, new Character (obj1), new Character (obj2)); 64 } 65 66 public static void assertEquals(String str, double obj1, double obj2, 67 double delta) { 68 if (obj1 == obj2) { 69 return; 70 } else if (Math.abs(obj1 - obj2) <= delta) { 71 return; 72 } else { 73 fail(str + " expected=" + obj1 + " actual=" + obj2 + " delta=" + delta); 74 } 75 } 76 77 public static void assertEquals(String str, float obj1, float obj2, 78 float delta) { 79 if (obj1 == obj2) { 80 return; 81 } else if (Math.abs(obj1 - obj2) <= delta) { 82 return; 83 } else { 84 fail(str + " expected=" + obj1 + " actual=" + obj2 + " delta=" + delta); 85 } 86 } 87 88 public static void assertEquals(String msg, int expected, int actual) { 89 if (expected != actual) { 90 fail(msg + " expected=" + expected + " actual=" + actual); 91 } 92 } 93 94 public static void assertEquals(String str, long obj1, long obj2) { 95 assertEquals(str, new Long (obj1), new Long (obj2)); 96 } 97 98 public static void assertEquals(String msg, Object obj1, Object obj2) { 99 if (obj1 == null && obj2 == null) { 100 return; 101 } 102 103 if (obj1 != null && obj1.equals(obj2)) { 104 return; 105 } 106 107 fail(msg + " expected=" + obj1 + " actual=" + obj2); 108 } 109 110 public static void assertFalse(boolean condition) { 111 assertFalse(null, condition); 112 } 113 114 public static void assertFalse(String message, boolean condition) { 115 assertTrue(message, !condition); 116 } 117 118 public static void assertNotNull(Object obj) { 119 assertNotNull(null, obj); 120 } 121 122 public static void assertNotNull(String msg, Object obj) { 123 assertTrue(msg, obj != null); 124 } 125 126 public static void assertNotSame(Object obj1, Object obj2) { 127 assertNotSame(null, obj1, obj2); 128 } 129 130 public static void assertNotSame(String msg, Object obj1, Object obj2) { 131 if (obj1 != obj2) { 132 return; 133 } 134 135 if (msg == null) { 136 msg = ""; 137 } 138 139 fail(msg + " expected and actual match"); 140 } 141 142 public static void assertNull(Object obj) { 143 assertNull(null, obj); 144 } 145 146 public static void assertNull(String msg, Object obj) { 147 assertTrue(msg, obj == null); 148 } 149 150 public static void assertSame(Object obj1, Object obj2) { 151 assertSame(null, obj1, obj2); 152 } 153 154 public static void assertSame(String msg, Object obj1, Object obj2) { 155 if (obj1 == obj2) { 156 return; 157 } 158 159 if (msg == null) { 160 msg = ""; 161 } 162 163 fail(msg + " expected and actual do not match"); 164 } 165 166 public static void assertTrue(boolean condition) { 167 assertTrue(null, condition); 168 } 169 170 public static void assertTrue(String message, boolean condition) { 171 if (!condition) { 172 fail(message); 173 } 174 } 175 176 public static void fail() { 177 fail(null); 178 } 179 180 public static void fail(String message) { 181 throw new AssertionFailedError(message); 182 } 183 184 187 protected Assert() { 188 } 189 } 190 | Popular Tags |