1 package org.itracker;
2
3 import org.apache.log4j.Logger;
4 import org.itracker.model.Entity;
5
6 import java.util.Comparator;
7
8
9
10
11 public class Assert extends junit.framework.Assert {
12
13 private static final Logger log = Logger.getLogger(Assert.class);
14
15
16
17
18 @SuppressWarnings("unchecked")
19 public static void assertEntityComparator(String message, Comparator comparator, Entity lhs, Entity rhs) {
20 if (log.isDebugEnabled()) {
21 log.debug("assertEntityComparator: " + message + " " + comparator);
22 }
23 if (null == lhs) {
24 throw new IllegalArgumentException("lhs must not both be null.");
25 }
26
27
28 if (null == rhs) {
29
30 try {
31 assertNull(message + " lhs, null: " + comparator, comparator.compare(lhs, rhs));
32 fail();
33 } catch (NullPointerException npe) {
34 }
35
36 try {
37 assertNull(message + " null, lhs: " + comparator, comparator.compare(rhs, lhs));
38 fail();
39 } catch (NullPointerException npe) {
40 }
41
42 return;
43 }
44
45 assertTrue(message + " lhs, rhs: " + comparator, 0 > comparator.compare(lhs, rhs));
46 assertTrue(message + " rhs, lhs: " + comparator, 0 < comparator.compare(rhs, lhs));
47 }
48
49
50
51
52
53 @SuppressWarnings("unchecked")
54 public static void assertEntityComparatorEquals(String message, Comparator comparator, Entity lhs, Entity rhs) {
55 if (log.isDebugEnabled()) {
56 log.debug("assertEntityComparatorEquals: " + message + " " + comparator);
57 }
58 if (null == lhs || null == rhs) {
59 throw new IllegalArgumentException("rhs and lhs must not be null.");
60 }
61
62 assertTrue(message + " lhs, rhs: " + comparator, 0 == comparator.compare(lhs, rhs));
63 assertTrue(message + " rhs, lhs: " + comparator, 0 == comparator.compare(rhs, lhs));
64 }
65 }