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.OFBizDateComparator;
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 java.sql.Timestamp;
20  import java.util.Date;
21  
22  import junit.framework.TestCase;
23  
24  public class TestOFBizDateComparator extends TestCase
25  {
26      protected void setUp() throws Exception
27      {
28          UtilsForTests.cleanOFBiz();
29      }
30  
31      public void testComparison()
32      {
33          final OFBizDateComparator comp = new OFBizDateComparator("foo");
34  
35          GenericValue gv = new MockGenericValue("Issue", UtilMisc.toMap("foo", null));
36          GenericValue gv2 = new MockGenericValue("Issue", UtilMisc.toMap("foo", null));
37          assertTrue(0 == comp.compare(gv, gv2));
38          assertTrue(0 == comp.compare(gv2, gv));
39  
40          gv = new MockGenericValue("Issue", UtilMisc.toMap("foo", new Timestamp(new Date().getTime())));
41          assertTrue(comp.compare(gv, gv2) > 0);
42          assertTrue(comp.compare(gv2, gv) < 0);
43  
44          gv2 = new MockGenericValue("Issue", UtilMisc.toMap("foo", new Timestamp(new Date().getTime() + 1000)));
45          assertTrue(comp.compare(gv, gv2) < 0);
46          assertTrue(comp.compare(gv2, gv) > 0);
47      }
48  
49  }