01: /*
02: * Copyright 2001-2005 Stephen Colebourne
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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,
54: Integer.MAX_VALUE));
55: assertEquals((1000L - Integer.MIN_VALUE), fld.subtract(1000L,
56: Integer.MIN_VALUE));
57: assertEquals((1000L - Long.MAX_VALUE), fld.subtract(1000L,
58: Long.MAX_VALUE));
59: try {
60: fld.subtract(-1000L, Long.MIN_VALUE);
61: fail();
62: } catch (ArithmeticException ex) {
63: }
64: }
65:
66: }
|