View Javadoc
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    * Itracker specific assertions for include static to test-classes.
10   */
11  public class Assert extends junit.framework.Assert {
12  
13      private static final Logger log = Logger.getLogger(Assert.class);
14  
15      /**
16       * asserts true when comparator compares for lhs being < rhs and rhs > lhs.
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          // test nullpointer
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              } // ok
35  
36              try {
37                  assertNull(message + " null, lhs: " + comparator, comparator.compare(rhs, lhs));
38                  fail();
39              } catch (NullPointerException npe) {
40              } // ok
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       * asserts true when comparator compares for lhs being equal to rhs and rhs equal lhs.
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  }