001 package org.hackystat.dailyprojectdata.resource.snapshot; 002 003 import static org.junit.Assert.*; 004 005 import javax.xml.datatype.XMLGregorianCalendar; 006 007 import org.hackystat.sensorbase.resource.sensordata.jaxb.SensorDataRef; 008 import org.hackystat.utilities.tstamp.Tstamp; 009 import org.junit.Before; 010 import org.junit.Test; 011 012 /** 013 * Tests that the <code>SensorDataRef</code>s are properly compared. 014 * 015 * @author jsakuda 016 */ 017 public class TestSensorDataRefComparator { 018 private SensorDataRef ref1; 019 020 private SensorDataRef ref2; 021 022 /** 023 * Creates dummy sensor data refs for testing. 024 * 025 * @throws Exception Thrown if there is an error. 026 */ 027 @Before public void setupDataRefs() throws Exception { 028 XMLGregorianCalendar tstamp1 = Tstamp.makeTimestamp("2007-10-30T02:00:00"); 029 XMLGregorianCalendar tstamp2 = Tstamp.makeTimestamp("2007-10-30T04:00:00"); 030 031 this.ref1 = new SensorDataRef(); 032 this.ref1.setTimestamp(tstamp1); 033 034 this.ref2 = new SensorDataRef(); 035 this.ref2.setTimestamp(tstamp2); 036 } 037 038 039 /** Tests the comparing of data refs in ascending order. */ 040 @Test 041 public void testCompareAscending() { 042 SensorDataRefComparator comparator = new SensorDataRefComparator(true); 043 044 assertEquals("ref1 should be before ref2", -1, comparator.compare(this.ref1, this.ref2)); 045 } 046 047 /** Tests the comparing of data refs in descending order. */ 048 @Test 049 public void testCompareDescending() { 050 SensorDataRefComparator comparator = new SensorDataRefComparator(false); 051 052 assertEquals("ref1 should be after ref2", 1, comparator.compare(this.ref1, this.ref2)); 053 } 054 055 /** Tests the comparing of data refs with the same timestamp. */ 056 @Test 057 public void testCompareSame() { 058 SensorDataRefComparator comparator = new SensorDataRefComparator(false); 059 060 assertEquals("ref1 should be equal to itself", 0, comparator.compare(this.ref1, this.ref1)); 061 } 062 063 }