Package org.openqreg.bean

Examples of org.openqreg.bean.Interval


public class TestInterval {

 
  @Test
  public void testContains() {
    Interval interval = new Interval();
   
    Calendar fromDate = Calendar.getInstance();
    fromDate.set(2007, 0, 1, 0, 0, 0);
    interval.setFromDate(fromDate);
   
    Calendar toDate = (Calendar)fromDate.clone();
    toDate.add(Calendar.MONTH, 1);
    interval.setToDate(toDate);

    // testDate == fromDate
    Calendar testDate = (Calendar)fromDate.clone();
    assertEquals("fromDate and testDate should be equal", fromDate.getTimeInMillis(), testDate.getTimeInMillis());
    assertTrue("Contains is an closed interval - fromDate is in the interval", interval.contains(testDate));

    // testDate == toDate
    testDate = (Calendar)toDate.clone();
    assertEquals("toDate and testDate should be equal", toDate.getTimeInMillis(), testDate.getTimeInMillis());
    assertTrue("Contains is an closed interval - toDate is in the interval", interval.contains(testDate));
   
    // testDate < fromDate
    testDate = (Calendar)fromDate.clone();
    testDate.add(Calendar.DAY_OF_YEAR, -1);
    assertTrue("testDate should be less then fromDate", testDate.getTimeInMillis() < fromDate.getTimeInMillis());
    assertFalse("Testdate is before startdate", interval.contains(testDate));   
   
    // testDate > toDate
    testDate = (Calendar)toDate.clone();
    testDate.add(Calendar.DAY_OF_YEAR, 1);
    assertTrue("testDate should be greater then toDate", testDate.getTimeInMillis() > toDate.getTimeInMillis());
    assertFalse("Testdate is after startdate", interval.contains(testDate));   

    // testDate inside interval
    testDate = (Calendar)fromDate.clone();
    testDate.add(Calendar.DAY_OF_YEAR, 1);
    assertTrue("testDate should be greater then fromDate", testDate.getTimeInMillis() > fromDate.getTimeInMillis());
    assertTrue("testDate should be less then fromDate", testDate.getTimeInMillis() < toDate.getTimeInMillis());
    assertTrue("testDate should be insed the interval", interval.contains(testDate));
  }
View Full Code Here

TOP

Related Classes of org.openqreg.bean.Interval

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.