KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > plugin > version > IntervalUtilsTest


1 package org.apache.maven.plugin.version;
2
3 import junit.framework.TestCase;
4
5 import java.util.Calendar JavaDoc;
6 import java.util.Date JavaDoc;
7
8 /*
9  * Copyright 2001-2005 The Apache Software Foundation.
10  *
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  * http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  */

23
24 public class IntervalUtilsTest
25     extends TestCase
26 {
27     
28     private static final long ONE_MINUTE = 60 * 1000;
29     private static final long ONE_HOUR = 60 * ONE_MINUTE;
30     private static final long ONE_DAY = 24 * ONE_HOUR;
31     private static final long ONE_WEEK = 7 * ONE_DAY;
32
33     public void testOneWeek()
34     {
35         assertEquals( ONE_WEEK, IntervalUtils.parseInterval( "1w" ) );
36     }
37
38     public void testTwoWeeks()
39     {
40         assertEquals( ( 2 * ONE_WEEK ), IntervalUtils.parseInterval( "2w" ) );
41     }
42
43     public void testOneDay()
44     {
45         assertEquals( ONE_DAY, IntervalUtils.parseInterval( "1d" ) );
46     }
47
48     public void testOneHour()
49     {
50         assertEquals( ONE_HOUR, IntervalUtils.parseInterval( "1h" ) );
51     }
52
53     public void testOneMinute()
54     {
55         assertEquals( ONE_MINUTE, IntervalUtils.parseInterval( "1m" ) );
56     }
57
58     public void testTwoDaysThreeHoursAndOneMinute()
59     {
60         assertEquals( 2 * ONE_DAY + 3 * ONE_HOUR + ONE_MINUTE, IntervalUtils.parseInterval( "2d 3h 1m" ) );
61     }
62
63     public void testTwoDaysThreeHoursAndOneMinuteCondensed()
64     {
65         assertEquals( 2 * ONE_DAY + 3 * ONE_HOUR + ONE_MINUTE, IntervalUtils.parseInterval( "2d3h1m" ) );
66     }
67
68     public void testTwoDaysThreeHoursAndOneMinuteCommaSeparated()
69     {
70         assertEquals( 2 * ONE_DAY + 3 * ONE_HOUR + ONE_MINUTE, IntervalUtils.parseInterval( "2d,3h,1m" ) );
71     }
72
73     public void testTwoDaysThreeHoursAndOneMinuteRearranged()
74     {
75         assertEquals( 2 * ONE_DAY + 3 * ONE_HOUR + ONE_MINUTE, IntervalUtils.parseInterval( "1m 2d 3h" ) );
76     }
77
78     public void testThreeDaysPoorlySpecified()
79     {
80         assertEquals( 3 * ONE_DAY, IntervalUtils.parseInterval( "1d 2d" ) );
81     }
82     
83     public void testNeverInterval()
84     {
85         assertFalse( IntervalUtils.isExpired( "never", null ) );
86     }
87
88     public void testAlwaysInterval()
89     {
90         assertTrue( IntervalUtils.isExpired( "always", null ) );
91     }
92
93     public void testOneMinuteIntervalShouldBeExpired()
94     {
95         Calendar JavaDoc cal = Calendar.getInstance();
96         cal.add( Calendar.MINUTE, -2 );
97         
98         Date JavaDoc lastChecked = cal.getTime();
99         
100         assertTrue( IntervalUtils.isExpired( "interval:1m", lastChecked ) );
101     }
102
103 }
104
Popular Tags