1 25 package org.archive.crawler.settings.refinements; 26 27 import java.text.DateFormat ; 28 import java.text.ParseException ; 29 import java.text.SimpleDateFormat ; 30 import java.util.Date ; 31 import java.util.TimeZone ; 32 33 import junit.framework.TestCase; 34 35 36 41 public class TimespanCriteriaTest extends TestCase { 42 public final void testIsWithinRefinementBounds() throws ParseException { 43 DateFormat timeFormat; 44 TimeZone TZ = TimeZone.getTimeZone("GMT"); 45 timeFormat = new SimpleDateFormat ("HHmm"); 46 timeFormat.setTimeZone(TZ); 47 Date now = timeFormat.parse(timeFormat.format(new Date ())); 48 49 String nowTime = timeFormat.format(now); 50 String beforeTime1 = timeFormat.format(new Date (now.getTime() - 51 1000 * 60 * 2)); 52 String beforeTime2 = timeFormat.format(new Date (now.getTime() - 53 1000 * 60 * 1)); 54 String afterTime1 = timeFormat.format(new Date (now.getTime() + 55 1000 * 60 * 1)); 56 57 TimespanCriteria c = new TimespanCriteria(beforeTime1, afterTime1); 59 assertTrue(c.isWithinRefinementBounds(null)); 60 61 c = new TimespanCriteria(nowTime, afterTime1); 63 assertTrue(c.isWithinRefinementBounds(null)); 64 65 c = new TimespanCriteria(beforeTime1, nowTime); 67 assertTrue(c.isWithinRefinementBounds(null)); 68 69 c = new TimespanCriteria(beforeTime1, beforeTime2); 71 assertFalse(c.isWithinRefinementBounds(null)); 72 73 c = new TimespanCriteria(afterTime1, beforeTime1); 75 assertFalse(c.isWithinRefinementBounds(null)); 76 77 c = new TimespanCriteria(beforeTime2, beforeTime1); 79 assertTrue(c.isWithinRefinementBounds(null)); 80 81 c = new TimespanCriteria(nowTime, beforeTime1); 83 assertTrue(c.isWithinRefinementBounds(null)); 84 85 c = new TimespanCriteria(afterTime1, nowTime); 87 assertTrue(c.isWithinRefinementBounds(null)); 88 } 89 90 } 91 | Popular Tags |