KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > joda > time > TestDurationField


1 /*
2  * Copyright 2001-2005 Stephen Colebourne
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 package org.joda.time;
17
18 import org.joda.time.chrono.ISOChronology;
19
20 import junit.framework.TestCase;
21 import junit.framework.TestSuite;
22
23 /**
24  * This class is a Junit unit test for DurationField.
25  *
26  * @author Stephen Colebourne
27  */

28 public class TestDurationField extends TestCase {
29
30     public static void main(String JavaDoc[] args) {
31         junit.textui.TestRunner.run(suite());
32     }
33
34     public static TestSuite suite() {
35         return new TestSuite(TestDurationField.class);
36     }
37
38     public TestDurationField(String JavaDoc name) {
39         super(name);
40     }
41
42     protected void setUp() throws Exception JavaDoc {
43     }
44
45     protected void tearDown() throws Exception JavaDoc {
46     }
47
48     //-----------------------------------------------------------------------
49
public void test_subtract() throws Exception JavaDoc {
50         DurationField fld = ISOChronology.getInstanceUTC().millis();
51         assertEquals(900, fld.subtract(1000L, 100));
52         assertEquals(900L, fld.subtract(1000L, 100L));
53         assertEquals((1000L - Integer.MAX_VALUE), fld.subtract(1000L, Integer.MAX_VALUE));
54         assertEquals((1000L - Integer.MIN_VALUE), fld.subtract(1000L, Integer.MIN_VALUE));
55         assertEquals((1000L - Long.MAX_VALUE), fld.subtract(1000L, Long.MAX_VALUE));
56         try {
57             fld.subtract(-1000L, Long.MIN_VALUE);
58             fail();
59         } catch (ArithmeticException JavaDoc ex) {}
60     }
61
62 }
63
Popular Tags