KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > util > DateUtilsTest


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

17 package org.apache.tools.ant.util;
18
19 import java.util.Date JavaDoc;
20 import java.util.Calendar JavaDoc;
21 import java.util.TimeZone JavaDoc;
22
23 import junit.framework.TestCase;
24
25 /**
26  * TestCase for DateUtils.
27  *
28  */

29 public class DateUtilsTest extends TestCase {
30     public DateUtilsTest(String JavaDoc s) {
31         super(s);
32     }
33
34     public void testElapsedTime(){
35         String JavaDoc text = DateUtils.formatElapsedTime(50*1000);
36         assertEquals("50 seconds", text);
37         text = DateUtils.formatElapsedTime(65*1000);
38         assertEquals("1 minute 5 seconds", text);
39         text = DateUtils.formatElapsedTime(120*1000);
40         assertEquals("2 minutes 0 seconds", text);
41         text = DateUtils.formatElapsedTime(121*1000);
42         assertEquals("2 minutes 1 second", text);
43     }
44
45     public void testDateTimeISO(){
46         TimeZone JavaDoc timeZone = TimeZone.getTimeZone("GMT+1");
47         Calendar JavaDoc cal = Calendar.getInstance(timeZone);
48         cal.set(2002,1,23,10,11,12);
49         String JavaDoc text = DateUtils.format(cal.getTime(),
50                 DateUtils.ISO8601_DATETIME_PATTERN);
51         assertEquals("2002-02-23T09:11:12", text);
52     }
53
54     public void testDateISO(){
55         TimeZone JavaDoc timeZone = TimeZone.getTimeZone("GMT");
56         Calendar JavaDoc cal = Calendar.getInstance(timeZone);
57         cal.set(2002,1,23);
58         String JavaDoc text = DateUtils.format(cal.getTime(),
59                 DateUtils.ISO8601_DATE_PATTERN);
60         assertEquals("2002-02-23", text);
61     }
62
63     public void testTimeISODate(){
64         // make sure that elapsed time in set via date works
65
TimeZone JavaDoc timeZone = TimeZone.getTimeZone("GMT+1");
66         Calendar JavaDoc cal = Calendar.getInstance(timeZone);
67         cal.set(2002,1,23, 21, 11, 12);
68         String JavaDoc text = DateUtils.format(cal.getTime(),
69                 DateUtils.ISO8601_TIME_PATTERN);
70         assertEquals("20:11:12", text);
71     }
72
73     public void testTimeISO(){
74         // make sure that elapsed time in ms works
75
long ms = (20*3600 + 11*60 + 12)*1000;
76         String JavaDoc text = DateUtils.format(ms,
77                 DateUtils.ISO8601_TIME_PATTERN);
78         assertEquals("20:11:12", text);
79     }
80
81     public void testPhaseOfMoon() {
82         TimeZone JavaDoc timeZone = TimeZone.getTimeZone("GMT");
83         Calendar JavaDoc cal = Calendar.getInstance(timeZone);
84         // should be full moon
85
cal.set(2002, 2, 27);
86         assertEquals(4, DateUtils.getPhaseOfMoon(cal));
87         // should be new moon
88
cal.set(2002, 2, 12);
89         assertEquals(0, DateUtils.getPhaseOfMoon(cal));
90     }
91 }
92
Popular Tags