View Javadoc

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[] 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 name) {
39          super(name);
40      }
41  
42      protected void setUp() throws Exception {
43      }
44  
45      protected void tearDown() throws Exception {
46      }
47  
48      //-----------------------------------------------------------------------
49      public void test_subtract() throws Exception {
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 ex) {}
60      }
61  
62  }