1   /*
2    * Atlassian Source Code Template.
3    * User: Administrator
4    * Created: Oct 16, 2002
5    * Time: 7:12:21 PM
6    * CVS Revision: $Revision: 1.1 $
7    * Last CVS Commit: $Date: 2003/09/30 07:11:38 $
8    * Author of last CVS Commit: $Author: mcannon $
9    */
10  package test.atlassian.core.ofbiz.comparator;
11  
12  import com.atlassian.core.ofbiz.comparators.OFBizFieldComparator;
13  import com.atlassian.core.ofbiz.test.UtilsForTests;
14  import com.atlassian.core.ofbiz.test.mock.MockGenericValue;
15  
16  import org.ofbiz.core.entity.GenericValue;
17  import org.ofbiz.core.util.UtilMisc;
18  
19  import junit.framework.TestCase;
20  
21  public class TestOFBizFieldComparator extends TestCase
22  {
23      protected void setUp() throws Exception
24      {
25          UtilsForTests.cleanOFBiz();
26      }
27  
28      public void testComparison()
29      {
30          final OFBizFieldComparator comp = new OFBizFieldComparator("foo");
31  
32          assertTrue(0 == comp.compare(null, null));
33  
34          GenericValue gv = new MockGenericValue("Issue", UtilMisc.toMap("foo", null));
35          assertTrue(comp.compare(gv, gv) == 0);
36          assertTrue(comp.compare(gv, null) < 0);
37          assertTrue(comp.compare(null, gv) > 0);
38  
39          GenericValue gv2 = new MockGenericValue("Issue", UtilMisc.toMap("foo", null));
40          assertTrue(0 == comp.compare(gv, gv2));
41          assertTrue(0 == comp.compare(gv2, gv));
42  
43          gv = new MockGenericValue("Issue", UtilMisc.toMap("foo", "value"));
44          assertTrue(comp.compare(gv, gv2) < 0);
45          assertTrue(comp.compare(gv2, gv) > 0);
46  
47          gv2 = new MockGenericValue("Issue", UtilMisc.toMap("foo", "a value"));
48          assertTrue(comp.compare(gv, gv2) > 0);
49          assertTrue(comp.compare(gv2, gv) < 0);
50      }
51  }