package com.openxc.util;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.lessThanOrEqualTo;

import java.util.Date;

import junit.framework.TestCase;

import com.openxc.TestUtils;
import com.openxc.units.Degree;

public class AgingDataTest extends TestCase {
    AgingData<Degree> data;
    Degree value = new Degree(0.0);

    public void testBornNow() {
        data = new AgingData<Degree>(value);
        TestUtils.pause(10);
        assertThat(data.getAge(), greaterThan(Long.valueOf(0)));
    }

    public void testBornEarlier() {
        data = new AgingData<Degree>(value);
        Date otherTime = new Date(data.getAge() + 100);
        data = new AgingData<Degree>(otherTime, value);
        assertThat(data.getAge(), greaterThanOrEqualTo(Long.valueOf(100)));
    }

    public void testSetOverride() {
        data = new AgingData<Degree>(value);
        assertThat(data.getAge(), lessThanOrEqualTo(Long.valueOf(1)));
        data.setTimestamp(data.getAge() + 100);
        assertThat(data.getAge(), greaterThanOrEqualTo(Long.valueOf(100)));
    }
}

@@ -108,27 +108,17 @@
 atchers.
-greaterThan
+*
 ;%0Aimport
@@ -133,158 +133,94 @@
 org.
-hamcrest.Matchers.greaterThanOrEqualTo;%0Aimport static org.hamcrest.Matchers.lessThanOrEqualTo;%0A%0Aimport java.util.Date;%0A%0Aimport junit.framework.TestCas
+junit.Assert.*;%0A%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0A%0Aimport java.util.Dat
 e;%0A%0A
@@ -312,25 +312,8 @@
 est 
-extends TestCase 
 %7B%0A  
@@ -358,105 +358,175 @@
 alue
- = new Degree(0.0);%0A%0A    public void testBornNow() %7B%0A        data = new AgingData%3CDegree%3E(value);
+;%0A%0A    @Before%0A    public void setUp() %7B%0A        value = new Degree(0.0);%0A        data = new AgingData%3CDegree%3E(value);%0A    %7D%0A%0A    @Test%0A    public void testBornNow() %7B
 %0A   
@@ -615,32 +615,42 @@
 Of(0)));%0A    %7D%0A%0A
+    @Test%0A
     public void 
@@ -673,53 +673,8 @@
 ) %7B%0A
-        data = new AgingData%3CDegree%3E(value);%0A
     
@@ -860,24 +860,34 @@
 )));%0A    %7D%0A%0A
+    @Test%0A
     public v
@@ -914,53 +914,8 @@
 ) %7B%0A
-        data = new AgingData%3CDegree%3E(value);%0A
     
@@ -1110,11 +1110,314 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void setInvalidTimstampIgnored() %7B%0A        long timestamp = data.getTimestamp();%0A        data.setTimestamp(0);%0A        assertEquals(timestamp, data.getTimestamp());%0A    %7D%0A%0A    @Test%0A    public void testToStringNotNull() %7B%0A        assertThat(data.toString(), notNullValue());%0A    %7D
 %0A%7D%0A

Add a few tests for AgingData to get 100% coverage.