001 /*
002 * Copyright 2001-2005 Stephen Colebourne
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.joda.time;
017
018 import org.joda.time.chrono.ISOChronology;
019
020 import junit.framework.TestCase;
021 import junit.framework.TestSuite;
022
023 /**
024 * This class is a Junit unit test for DurationField.
025 *
026 * @author Stephen Colebourne
027 */
028 public class TestDurationField extends TestCase {
029
030 public static void main(String[] args) {
031 junit.textui.TestRunner.run(suite());
032 }
033
034 public static TestSuite suite() {
035 return new TestSuite(TestDurationField.class);
036 }
037
038 public TestDurationField(String name) {
039 super(name);
040 }
041
042 protected void setUp() throws Exception {
043 }
044
045 protected void tearDown() throws Exception {
046 }
047
048 //-----------------------------------------------------------------------
049 public void test_subtract() throws Exception {
050 DurationField fld = ISOChronology.getInstanceUTC().millis();
051 assertEquals(900, fld.subtract(1000L, 100));
052 assertEquals(900L, fld.subtract(1000L, 100L));
053 assertEquals((1000L - Integer.MAX_VALUE), fld.subtract(1000L, Integer.MAX_VALUE));
054 assertEquals((1000L - Integer.MIN_VALUE), fld.subtract(1000L, Integer.MIN_VALUE));
055 assertEquals((1000L - Long.MAX_VALUE), fld.subtract(1000L, Long.MAX_VALUE));
056 try {
057 fld.subtract(-1000L, Long.MIN_VALUE);
058 fail();
059 } catch (ArithmeticException ex) {}
060 }
061
062 }