1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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 /***
37 *
38 * @author John Erik Halse
39 *
40 */
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
58 TimespanCriteria c = new TimespanCriteria(beforeTime1, afterTime1);
59 assertTrue(c.isWithinRefinementBounds(null));
60
61
62 c = new TimespanCriteria(nowTime, afterTime1);
63 assertTrue(c.isWithinRefinementBounds(null));
64
65
66 c = new TimespanCriteria(beforeTime1, nowTime);
67 assertTrue(c.isWithinRefinementBounds(null));
68
69
70 c = new TimespanCriteria(beforeTime1, beforeTime2);
71 assertFalse(c.isWithinRefinementBounds(null));
72
73
74 c = new TimespanCriteria(afterTime1, beforeTime1);
75 assertFalse(c.isWithinRefinementBounds(null));
76
77
78 c = new TimespanCriteria(beforeTime2, beforeTime1);
79 assertTrue(c.isWithinRefinementBounds(null));
80
81
82 c = new TimespanCriteria(nowTime, beforeTime1);
83 assertTrue(c.isWithinRefinementBounds(null));
84
85
86 c = new TimespanCriteria(afterTime1, nowTime);
87 assertTrue(c.isWithinRefinementBounds(null));
88 }
89
90 }