1 54 55 package junitx.framework; 56 57 72 public class Assert 73 extends junit.framework.Assert { 74 75 78 private Assert() { 79 } 80 81 87 public static void assertFalse(String message, 88 boolean condition) { 89 if (condition) { 90 failFalse(message); 91 } 92 } 93 94 100 public static void assertFalse(boolean condition) { 101 assertFalse(null, condition); 102 } 103 104 108 public static void assertEquals(String expected, String actual) { 109 assertEquals(null, expected, actual); 110 } 111 112 116 public static void assertEquals(String message, String expected, String actual) { 117 if ((expected == null && actual == null) || (expected != null && expected.equals(actual))) { 118 return; 119 } 120 throw new ComparisonFailure(message, expected, actual); 121 } 122 123 127 public static void assertNotEquals(String message, 128 Object expected, 129 Object actual) { 130 if ((expected == null && actual == null) || 131 (expected != null && expected.equals(actual))) { 132 failNotEquals(message, expected); 133 } 134 } 135 136 140 public static void assertNotEquals(Object expected, 141 Object actual) { 142 assertNotEquals(null, expected, actual); 143 } 144 145 149 public static void assertNotEquals(String message, 150 byte expected, 151 byte actual) { 152 assertNotEquals(message, new Byte (expected), new Byte (actual)); 153 } 154 155 159 public static void assertNotEquals(byte expected, 160 byte actual) { 161 assertNotEquals(null, expected, actual); 162 } 163 164 168 public static void assertNotEquals(String message, 169 char expected, 170 char actual) { 171 assertNotEquals(message, new Character (expected), new Character (actual)); 172 } 173 174 178 public static void assertNotEquals(char expected, 179 char actual) { 180 assertNotEquals(null, expected, actual); 181 } 182 183 188 public static void assertNotEquals(String message, 189 double expected, 190 double actual, 191 double delta) { 192 if (Double.isInfinite(expected)) { 193 if (expected == actual) { 194 failNotEquals(message, new Double (expected)); 195 } 196 } else if (Math.abs(expected - actual) <= delta) { 197 failNotEquals(message, new Double (expected)); 198 } 199 } 200 201 206 public static void assertNotEquals(double expected, 207 double actual, 208 double delta) { 209 assertNotEquals(null, expected, actual, delta); 210 } 211 212 217 public static void assertNotEquals(String message, 218 float expected, 219 float actual, 220 float delta) { 221 if (Float.isInfinite(expected)) { 222 if (expected == actual) { 223 failNotEquals(message, new Float (expected)); 224 } 225 } else if (Math.abs(expected - actual) <= delta) { 226 failNotEquals(message, new Float (expected)); 227 } 228 } 229 230 235 public static void assertNotEquals(float expected, 236 float actual, 237 float delta) { 238 assertNotEquals(null, expected, actual, delta); 239 } 240 241 245 public static void assertNotEquals(String message, 246 int expected, 247 int actual) { 248 assertNotEquals(message, new Integer (expected), new Integer (actual)); 249 } 250 251 255 public static void assertNotEquals(int expected, 256 int actual) { 257 assertNotEquals(null, expected, actual); 258 } 259 260 264 public static void assertNotEquals(String message, 265 long expected, 266 long actual) { 267 assertNotEquals(message, new Long (expected), new Long (actual)); 268 } 269 270 274 public static void assertNotEquals(long expected, 275 long actual) { 276 assertNotEquals(null, expected, actual); 277 } 278 279 283 public static void assertNotEquals(String message, 284 short expected, 285 short actual) { 286 assertNotEquals(message, new Short (expected), new Short (actual)); 287 } 288 289 293 public static void assertNotEquals(short expected, 294 short actual) { 295 assertNotEquals(null, expected, actual); 296 } 297 298 302 public static void assertNotEquals(String message, 303 boolean expected, 304 boolean actual) { 305 assertNotEquals(message, new Boolean (expected), new Boolean (actual)); 306 } 307 308 312 public static void assertNotEquals(boolean expected, 313 boolean actual) { 314 assertNotEquals(null, expected, actual); 315 } 316 317 321 public static void assertNotSame(String message, 322 Object expected, 323 Object actual) { 324 if (expected == actual) { 325 failSame(message, expected); 326 } 327 } 328 329 333 public static void assertNotSame(Object expected, 334 Object actual) { 335 assertNotSame(null, expected, actual); 336 } 337 338 static private void failFalse(String message) { 339 String formatted = ""; 340 if (message != null) { 341 formatted = message + " "; 342 } 343 344 fail(formatted + "expected <false>"); 345 } 346 347 static private void failNotEquals(String message, 348 Object expected) { 349 String formatted = ""; 350 if (message != null) { 351 formatted = message + " "; 352 } 353 354 fail(formatted + "expected not equals to: <" + expected + ">"); 355 } 356 357 static private void failSame(String message, 358 Object expected) { 359 String formatted = ""; 360 if (message != null) { 361 formatted = message + " "; 362 } 363 364 fail(formatted + "expected not same as: <" + expected + ">"); 365 } 366 367 371 static public void fail(Throwable cause) { 372 fail(null, cause); 373 } 374 375 379 static public void fail(String message, Throwable cause) { 380 throw new AssertionFailedError(message, cause); 381 } 382 383 } 384 | Popular Tags |