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