KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > james > util > TimeConverterTest


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

19
20
21 package org.apache.james.util;
22
23 import junit.framework.TestCase;
24
25 public class TimeConverterTest extends TestCase {
26     
27     private final long AMOUNT = 2;
28     
29
30     public TimeConverterTest(String JavaDoc arg0) {
31         super(arg0);
32     }
33
34     
35     public void testGetMilliSecondsMsec() {
36         long time = 2;
37         String JavaDoc unit = "msec";
38         
39         assertEquals(TimeConverter.getMilliSeconds(AMOUNT,unit),time);
40         assertEquals(TimeConverter.getMilliSeconds(AMOUNT +" " + unit),time);
41     }
42     
43     public void testGetMilliSecondsMsecs() {
44         long time = 2;
45         String JavaDoc unit = "msecs";
46         
47         assertEquals(TimeConverter.getMilliSeconds(AMOUNT,unit),time);
48         assertEquals(TimeConverter.getMilliSeconds(AMOUNT +" " + unit),time);
49     }
50     
51     public void testGetMilliSecondsSec() {
52         long time = 2000;
53         String JavaDoc unit = "sec";
54         
55         assertEquals(TimeConverter.getMilliSeconds(AMOUNT,unit),time);
56         assertEquals(TimeConverter.getMilliSeconds(AMOUNT +" " + unit),time);
57     }
58     
59     public void testGetMilliSecondsSecs() {
60         long time = 2000;
61         String JavaDoc unit = "secs";
62         
63         assertEquals(TimeConverter.getMilliSeconds(AMOUNT,unit),time);
64         assertEquals(TimeConverter.getMilliSeconds(AMOUNT +" " + unit),time);
65     }
66     
67     public void testGetMilliSecondsMinute() {
68         long time = 120000;
69         String JavaDoc unit = "minute";
70         
71         assertEquals(TimeConverter.getMilliSeconds(AMOUNT,unit),time);
72         assertEquals(TimeConverter.getMilliSeconds(AMOUNT +" " + unit),time);
73     }
74     
75     public void testGetMilliSecondsMinutes() {
76         long time = 120000;
77         String JavaDoc unit = "minutes";
78         
79         assertEquals(TimeConverter.getMilliSeconds(AMOUNT,unit),time);
80         assertEquals(TimeConverter.getMilliSeconds(AMOUNT +" " + unit),time);
81     }
82     
83     public void testGetMilliSecondsHour() {
84         long time = 7200000;
85         String JavaDoc unit = "hour";
86         
87         assertEquals(TimeConverter.getMilliSeconds(AMOUNT,unit),time);
88         assertEquals(TimeConverter.getMilliSeconds(AMOUNT +" " + unit),time);
89     }
90     
91     public void testGetMilliSecondsHours() {
92         long time = 7200000;
93         String JavaDoc unit = "hours";
94         
95         assertEquals(TimeConverter.getMilliSeconds(AMOUNT,unit),time);
96         assertEquals(TimeConverter.getMilliSeconds(AMOUNT +" " + unit),time);
97     }
98     
99     public void testGetMilliSecondsDay() {
100         long time = 172800000;
101         String JavaDoc unit = "day";
102         
103         assertEquals(TimeConverter.getMilliSeconds(AMOUNT,unit),time);
104         assertEquals(TimeConverter.getMilliSeconds(AMOUNT +" " + unit),time);
105     }
106     
107     public void testGetMilliSecondsDays() {
108         long time = 172800000;
109         String JavaDoc unit = "days";
110         
111         assertEquals(TimeConverter.getMilliSeconds(AMOUNT,unit),time);
112         assertEquals(TimeConverter.getMilliSeconds(AMOUNT +" " + unit),time);
113     }
114     
115     public void testIllegalUnit() {
116         boolean exceptionThrown = false;
117         try {
118             TimeConverter.getMilliSeconds(2,"week");
119             TimeConverter.getMilliSeconds(2 +" week");
120         } catch (NumberFormatException JavaDoc e) {
121             exceptionThrown = true;
122         }
123         
124         assertTrue(exceptionThrown);
125     }
126     
127     public void testIllegalPattern() {
128         boolean exceptionThrown = false;
129         try {
130             TimeConverter.getMilliSeconds("illegal pattern");
131         } catch (NumberFormatException JavaDoc e) {
132             exceptionThrown = true;
133         }
134         
135         assertTrue(exceptionThrown);
136     }
137     
138 }
139
Popular Tags