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.field;
17  
18  import java.util.Arrays;
19  import java.util.Locale;
20  
21  import junit.framework.TestCase;
22  import junit.framework.TestSuite;
23  
24  import org.joda.time.DateTimeFieldType;
25  import org.joda.time.DurationField;
26  import org.joda.time.DurationFieldType;
27  import org.joda.time.TimeOfDay;
28  import org.joda.time.chrono.ISOChronology;
29  
30  /**
31   * This class is a Junit unit test for PreciseDurationDateTimeField.
32   *
33   * @author Stephen Colebourne
34   */
35  public class TestPreciseDurationDateTimeField extends TestCase {
36  
37      public static void main(String[] args) {
38          junit.textui.TestRunner.run(suite());
39      }
40  
41      public static TestSuite suite() {
42          return new TestSuite(TestPreciseDurationDateTimeField.class);
43      }
44  
45      public TestPreciseDurationDateTimeField(String name) {
46          super(name);
47      }
48  
49      protected void setUp() throws Exception {
50      }
51  
52      protected void tearDown() throws Exception {
53      }
54  
55      //-----------------------------------------------------------------------
56      public void test_constructor() {
57          BaseDateTimeField field = new MockPreciseDurationDateTimeField();
58          assertEquals(DateTimeFieldType.secondOfMinute(), field.getType());
59          try {
60              field = new MockPreciseDurationDateTimeField(null, null);
61              fail();
62          } catch (IllegalArgumentException ex) {}
63          try {
64              field = new MockPreciseDurationDateTimeField(
65                  DateTimeFieldType.minuteOfHour(),
66                  new MockImpreciseDurationField(DurationFieldType.minutes()));
67              fail();
68          } catch (IllegalArgumentException ex) {}
69          try {
70              field = new MockPreciseDurationDateTimeField(
71                  DateTimeFieldType.minuteOfHour(),
72                  new MockZeroDurationField(DurationFieldType.minutes()));
73              fail();
74          } catch (IllegalArgumentException ex) {}
75      }
76  
77      public void test_getType() {
78          BaseDateTimeField field = new MockPreciseDurationDateTimeField(
79              DateTimeFieldType.secondOfDay(), new MockCountingDurationField(DurationFieldType.minutes()));
80          assertEquals(DateTimeFieldType.secondOfDay(), field.getType());
81      }
82  
83      public void test_getName() {
84          BaseDateTimeField field = new MockPreciseDurationDateTimeField(
85              DateTimeFieldType.secondOfDay(), new MockCountingDurationField(DurationFieldType.minutes()));
86          assertEquals("secondOfDay", field.getName());
87      }
88  
89      public void test_toString() {
90          BaseDateTimeField field = new MockPreciseDurationDateTimeField(
91              DateTimeFieldType.secondOfDay(), new MockCountingDurationField(DurationFieldType.minutes()));
92          assertEquals("DateTimeField[secondOfDay]", field.toString());
93      }
94  
95      public void test_isSupported() {
96          BaseDateTimeField field = new MockPreciseDurationDateTimeField();
97          assertEquals(true, field.isSupported());
98      }
99  
100     public void test_isLenient() {
101         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
102         assertEquals(false, field.isLenient());
103     }
104 
105     public void test_get() {
106         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
107         assertEquals(0, field.get(0));
108         assertEquals(1, field.get(60));
109         assertEquals(2, field.get(123));
110     }
111 
112     //-----------------------------------------------------------------------
113     public void test_getAsText_long_Locale() {
114         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
115         assertEquals("29", field.getAsText(60L * 29, Locale.ENGLISH));
116         assertEquals("29", field.getAsText(60L * 29, null));
117     }
118 
119     public void test_getAsText_long() {
120         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
121         assertEquals("29", field.getAsText(60L * 29));
122     }
123 
124     public void test_getAsText_RP_int_Locale() {
125         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
126         assertEquals("20", field.getAsText(new TimeOfDay(12, 30, 40, 50), 20, Locale.ENGLISH));
127         assertEquals("20", field.getAsText(new TimeOfDay(12, 30, 40, 50), 20, null));
128     }
129 
130     public void test_getAsText_RP_Locale() {
131         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
132         assertEquals("40", field.getAsText(new TimeOfDay(12, 30, 40, 50), Locale.ENGLISH));
133         assertEquals("40", field.getAsText(new TimeOfDay(12, 30, 40, 50), null));
134     }
135 
136     public void test_getAsText_int_Locale() {
137         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
138         assertEquals("80", field.getAsText(80, Locale.ENGLISH));
139         assertEquals("80", field.getAsText(80, null));
140     }
141 
142     //-----------------------------------------------------------------------
143     public void test_getAsShortText_long_Locale() {
144         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
145         assertEquals("29", field.getAsShortText(60L * 29, Locale.ENGLISH));
146         assertEquals("29", field.getAsShortText(60L * 29, null));
147     }
148 
149     public void test_getAsShortText_long() {
150         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
151         assertEquals("29", field.getAsShortText(60L * 29));
152     }
153 
154     public void test_getAsShortText_RP_int_Locale() {
155         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
156         assertEquals("20", field.getAsShortText(new TimeOfDay(12, 30, 40, 50), 20, Locale.ENGLISH));
157         assertEquals("20", field.getAsShortText(new TimeOfDay(12, 30, 40, 50), 20, null));
158     }
159 
160     public void test_getAsShortText_RP_Locale() {
161         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
162         assertEquals("40", field.getAsShortText(new TimeOfDay(12, 30, 40, 50), Locale.ENGLISH));
163         assertEquals("40", field.getAsShortText(new TimeOfDay(12, 30, 40, 50), null));
164     }
165 
166     public void test_getAsShortText_int_Locale() {
167         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
168         assertEquals("80", field.getAsShortText(80, Locale.ENGLISH));
169         assertEquals("80", field.getAsShortText(80, null));
170     }
171 
172     //-----------------------------------------------------------------------
173     public void test_add_long_int() {
174         MockCountingDurationField.add_int = 0;
175         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
176         assertEquals(61, field.add(1L, 1));
177         assertEquals(1, MockCountingDurationField.add_int);
178     }
179 
180     public void test_add_long_long() {
181         MockCountingDurationField.add_long = 0;
182         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
183         assertEquals(61, field.add(1L, 1L));
184         assertEquals(1, MockCountingDurationField.add_long);
185     }
186 
187     public void test_add_RP_int_intarray_int() {
188         int[] values = new int[] {10, 20, 30, 40};
189         int[] expected = new int[] {10, 20, 30, 40};
190         BaseDateTimeField field = new MockStandardBaseDateTimeField();
191         int[] result = field.add(new TimeOfDay(), 2, values, 0);
192         assertEquals(true, Arrays.equals(expected, result));
193         
194         values = new int[] {10, 20, 30, 40};
195         expected = new int[] {10, 20, 31, 40};
196         result = field.add(new TimeOfDay(), 2, values, 1);
197         assertEquals(true, Arrays.equals(expected, result));
198         
199         values = new int[] {10, 20, 30, 40};
200         expected = new int[] {10, 21, 0, 40};
201         result = field.add(new TimeOfDay(), 2, values, 30);
202         assertEquals(true, Arrays.equals(expected, result));
203         
204         values = new int[] {23, 59, 30, 40};
205         try {
206             field.add(new TimeOfDay(), 2, values, 30);
207             fail();
208         } catch (IllegalArgumentException ex) {}
209         
210         values = new int[] {10, 20, 30, 40};
211         expected = new int[] {10, 20, 29, 40};
212         result = field.add(new TimeOfDay(), 2, values, -1);
213         assertEquals(true, Arrays.equals(expected, result));
214         
215         values = new int[] {10, 20, 30, 40};
216         expected = new int[] {10, 19, 59, 40};
217         result = field.add(new TimeOfDay(), 2, values, -31);
218         assertEquals(true, Arrays.equals(expected, result));
219         
220         values = new int[] {0, 0, 30, 40};
221         try {
222             field.add(new TimeOfDay(), 2, values, -31);
223             fail();
224         } catch (IllegalArgumentException ex) {}
225     }
226 
227     //-----------------------------------------------------------------------
228     public void test_addWrapField_long_int() {
229         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
230         assertEquals(29 * 60L, field.addWrapField(60L * 29, 0));
231         assertEquals(59 * 60L, field.addWrapField(60L * 29, 30));
232         assertEquals(0 * 60L, field.addWrapField(60L * 29, 31));
233     }
234 
235     public void test_addWrapField_RP_int_intarray_int() {
236         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
237         int[] values = new int[] {10, 20, 30, 40};
238         int[] expected = new int[] {10, 20, 30, 40};
239         int[] result = field.addWrapField(new TimeOfDay(), 2, values, 0);
240         assertEquals(true, Arrays.equals(result, expected));
241         
242         values = new int[] {10, 20, 30, 40};
243         expected = new int[] {10, 20, 59, 40};
244         result = field.addWrapField(new TimeOfDay(), 2, values, 29);
245         assertEquals(true, Arrays.equals(result, expected));
246         
247         values = new int[] {10, 20, 30, 40};
248         expected = new int[] {10, 20, 0, 40};
249         result = field.addWrapField(new TimeOfDay(), 2, values, 30);
250         assertEquals(true, Arrays.equals(result, expected));
251         
252         values = new int[] {10, 20, 30, 40};
253         expected = new int[] {10, 20, 1, 40};
254         result = field.addWrapField(new TimeOfDay(), 2, values, 31);
255         assertEquals(true, Arrays.equals(result, expected));
256     }
257 
258     //-----------------------------------------------------------------------
259     public void test_getDifference_long_long() {
260         MockCountingDurationField.difference_long = 0;
261         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
262         assertEquals(30, field.getDifference(0L, 0L));
263         assertEquals(1, MockCountingDurationField.difference_long);
264     }
265 
266     public void test_getDifferenceAsLong_long_long() {
267         MockCountingDurationField.difference_long = 0;
268         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
269         assertEquals(30, field.getDifferenceAsLong(0L, 0L));
270         assertEquals(1, MockCountingDurationField.difference_long);
271     }
272 
273     //-----------------------------------------------------------------------
274     public void test_set_long_int() {
275         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
276         assertEquals(0, field.set(120L, 0));
277         assertEquals(29 * 60, field.set(120L, 29));
278     }
279 
280     public void test_set_RP_int_intarray_int() {
281         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
282         int[] values = new int[] {10, 20, 30, 40};
283         int[] expected = new int[] {10, 20, 30, 40};
284         int[] result = field.set(new TimeOfDay(), 2, values, 30);
285         assertEquals(true, Arrays.equals(result, expected));
286         
287         values = new int[] {10, 20, 30, 40};
288         expected = new int[] {10, 20, 29, 40};
289         result = field.set(new TimeOfDay(), 2, values, 29);
290         assertEquals(true, Arrays.equals(result, expected));
291         
292         values = new int[] {10, 20, 30, 40};
293         expected = new int[] {10, 20, 30, 40};
294         try {
295             field.set(new TimeOfDay(), 2, values, 60);
296             fail();
297         } catch (IllegalArgumentException ex) {}
298         assertEquals(true, Arrays.equals(values, expected));
299         
300         values = new int[] {10, 20, 30, 40};
301         expected = new int[] {10, 20, 30, 40};
302         try {
303             field.set(new TimeOfDay(), 2, values, -1);
304             fail();
305         } catch (IllegalArgumentException ex) {}
306         assertEquals(true, Arrays.equals(values, expected));
307     }
308 
309     public void test_set_long_String_Locale() {
310         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
311         assertEquals(0, field.set(0L, "0", null));
312         assertEquals(29 * 60, field.set(0L, "29", Locale.ENGLISH));
313     }
314 
315     public void test_set_long_String() {
316         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
317         assertEquals(0, field.set(0L, "0"));
318         assertEquals(29 * 60, field.set(0L, "29"));
319     }
320 
321     public void test_set_RP_int_intarray_String_Locale() {
322         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
323         int[] values = new int[] {10, 20, 30, 40};
324         int[] expected = new int[] {10, 20, 30, 40};
325         int[] result = field.set(new TimeOfDay(), 2, values, "30", null);
326         assertEquals(true, Arrays.equals(result, expected));
327         
328         values = new int[] {10, 20, 30, 40};
329         expected = new int[] {10, 20, 29, 40};
330         result = field.set(new TimeOfDay(), 2, values, "29", Locale.ENGLISH);
331         assertEquals(true, Arrays.equals(result, expected));
332         
333         values = new int[] {10, 20, 30, 40};
334         expected = new int[] {10, 20, 30, 40};
335         try {
336             field.set(new TimeOfDay(), 2, values, "60", null);
337             fail();
338         } catch (IllegalArgumentException ex) {}
339         assertEquals(true, Arrays.equals(values, expected));
340         
341         values = new int[] {10, 20, 30, 40};
342         expected = new int[] {10, 20, 30, 40};
343         try {
344             field.set(new TimeOfDay(), 2, values, "-1", null);
345             fail();
346         } catch (IllegalArgumentException ex) {}
347         assertEquals(true, Arrays.equals(values, expected));
348     }
349 
350     public void test_convertText() {
351         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
352         assertEquals(0, field.convertText("0", null));
353         assertEquals(29, field.convertText("29", null));
354         try {
355             field.convertText("2A", null);
356             fail();
357         } catch (IllegalArgumentException ex) {}
358         try {
359             field.convertText(null, null);
360             fail();
361         } catch (IllegalArgumentException ex) {}
362     }
363 
364     //------------------------------------------------------------------------
365 //    public abstract DurationField getDurationField();
366 //
367 //    public abstract DurationField getRangeDurationField();
368 
369     public void test_isLeap_long() {
370         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
371         assertEquals(false, field.isLeap(0L));
372     }
373 
374     public void test_getLeapAmount_long() {
375         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
376         assertEquals(0, field.getLeapAmount(0L));
377     }
378 
379     public void test_getLeapDurationField() {
380         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
381         assertEquals(null, field.getLeapDurationField());
382     }
383 
384     //-----------------------------------------------------------------------
385     public void test_getMinimumValue() {
386         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
387         assertEquals(0, field.getMinimumValue());
388     }
389 
390     public void test_getMinimumValue_long() {
391         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
392         assertEquals(0, field.getMinimumValue(0L));
393     }
394 
395     public void test_getMinimumValue_RP() {
396         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
397         assertEquals(0, field.getMinimumValue(new TimeOfDay()));
398     }
399 
400     public void test_getMinimumValue_RP_intarray() {
401         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
402         assertEquals(0, field.getMinimumValue(new TimeOfDay(), new int[4]));
403     }
404 
405     public void test_getMaximumValue() {
406         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
407         assertEquals(59, field.getMaximumValue());
408     }
409 
410     public void test_getMaximumValue_long() {
411         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
412         assertEquals(59, field.getMaximumValue(0L));
413     }
414 
415     public void test_getMaximumValue_RP() {
416         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
417         assertEquals(59, field.getMaximumValue(new TimeOfDay()));
418     }
419 
420     public void test_getMaximumValue_RP_intarray() {
421         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
422         assertEquals(59, field.getMaximumValue(new TimeOfDay(), new int[4]));
423     }
424 
425     //-----------------------------------------------------------------------
426     public void test_getMaximumTextLength_Locale() {
427         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
428         assertEquals(2, field.getMaximumTextLength(Locale.ENGLISH));
429 
430         field = new MockPreciseDurationDateTimeField() {
431             public int getMaximumValue() {
432                 return 5;
433             }
434         };
435         assertEquals(1, field.getMaximumTextLength(Locale.ENGLISH));
436         
437         field = new MockPreciseDurationDateTimeField() {
438             public int getMaximumValue() {
439                 return 555;
440             }
441         };
442         assertEquals(3, field.getMaximumTextLength(Locale.ENGLISH));
443         
444         field = new MockPreciseDurationDateTimeField() {
445             public int getMaximumValue() {
446                 return 5555;
447             }
448         };
449         assertEquals(4, field.getMaximumTextLength(Locale.ENGLISH));
450         
451         field = new MockPreciseDurationDateTimeField() {
452             public int getMaximumValue() {
453                 return -1;
454             }
455         };
456         assertEquals(2, field.getMaximumTextLength(Locale.ENGLISH));
457     }
458 
459     public void test_getMaximumShortTextLength_Locale() {
460         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
461         assertEquals(2, field.getMaximumShortTextLength(Locale.ENGLISH));
462     }
463 
464     //------------------------------------------------------------------------
465     public void test_roundFloor_long() {
466         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
467         assertEquals(-120L, field.roundFloor(-61L));
468         assertEquals(-60L, field.roundFloor(-60L));
469         assertEquals(-60L, field.roundFloor(-59L));
470         assertEquals(-60L, field.roundFloor(-1L));
471         assertEquals(0L, field.roundFloor(0L));
472         assertEquals(0L, field.roundFloor(1L));
473         assertEquals(0L, field.roundFloor(29L));
474         assertEquals(0L, field.roundFloor(30L));
475         assertEquals(0L, field.roundFloor(31L));
476         assertEquals(60L, field.roundFloor(60L));
477     }
478 
479     public void test_roundCeiling_long() {
480         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
481         assertEquals(-60L, field.roundCeiling(-61L));
482         assertEquals(-60L, field.roundCeiling(-60L));
483         assertEquals(0L, field.roundCeiling(-59L));
484         assertEquals(0L, field.roundCeiling(-1L));
485         assertEquals(0L, field.roundCeiling(0L));
486         assertEquals(60L, field.roundCeiling(1L));
487         assertEquals(60L, field.roundCeiling(29L));
488         assertEquals(60L, field.roundCeiling(30L));
489         assertEquals(60L, field.roundCeiling(31L));
490         assertEquals(60L, field.roundCeiling(60L));
491     }
492 
493     public void test_roundHalfFloor_long() {
494         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
495         assertEquals(0L, field.roundHalfFloor(0L));
496         assertEquals(0L, field.roundHalfFloor(29L));
497         assertEquals(0L, field.roundHalfFloor(30L));
498         assertEquals(60L, field.roundHalfFloor(31L));
499         assertEquals(60L, field.roundHalfFloor(60L));
500     }
501 
502     public void test_roundHalfCeiling_long() {
503         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
504         assertEquals(0L, field.roundHalfCeiling(0L));
505         assertEquals(0L, field.roundHalfCeiling(29L));
506         assertEquals(60L, field.roundHalfCeiling(30L));
507         assertEquals(60L, field.roundHalfCeiling(31L));
508         assertEquals(60L, field.roundHalfCeiling(60L));
509     }
510 
511     public void test_roundHalfEven_long() {
512         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
513         assertEquals(0L, field.roundHalfEven(0L));
514         assertEquals(0L, field.roundHalfEven(29L));
515         assertEquals(0L, field.roundHalfEven(30L));
516         assertEquals(60L, field.roundHalfEven(31L));
517         assertEquals(60L, field.roundHalfEven(60L));
518         assertEquals(60L, field.roundHalfEven(89L));
519         assertEquals(120L, field.roundHalfEven(90L));
520         assertEquals(120L, field.roundHalfEven(91L));
521     }
522 
523     public void test_remainder_long() {
524         BaseDateTimeField field = new MockPreciseDurationDateTimeField();
525         assertEquals(0L, field.remainder(0L));
526         assertEquals(29L, field.remainder(29L));
527         assertEquals(30L, field.remainder(30L));
528         assertEquals(31L, field.remainder(31L));
529         assertEquals(0L, field.remainder(60L));
530     }
531 
532     //-----------------------------------------------------------------------
533     static class MockPreciseDurationDateTimeField extends PreciseDurationDateTimeField {
534         protected MockPreciseDurationDateTimeField() {
535             super(DateTimeFieldType.secondOfMinute(),
536                 new MockCountingDurationField(DurationFieldType.seconds()));
537         }
538         protected MockPreciseDurationDateTimeField(DateTimeFieldType type, DurationField dur) {
539             super(type, dur);
540         }
541         public int get(long instant) {
542             return (int) (instant / 60L);
543         }
544         public DurationField getRangeDurationField() {
545             return new MockCountingDurationField(DurationFieldType.minutes());
546         }
547         public int getMaximumValue() {
548             return 59;
549         }
550     }
551 
552     static class MockStandardBaseDateTimeField extends MockPreciseDurationDateTimeField {
553         protected MockStandardBaseDateTimeField() {
554             super();
555         }
556         public DurationField getDurationField() {
557             return ISOChronology.getInstanceUTC().seconds();
558         }
559         public DurationField getRangeDurationField() {
560             return ISOChronology.getInstanceUTC().minutes();
561         }
562     }
563 
564     //-----------------------------------------------------------------------
565     static class MockCountingDurationField extends BaseDurationField {
566         static int add_int = 0;
567         static int add_long = 0;
568         static int difference_long = 0;
569         
570         protected MockCountingDurationField(DurationFieldType type) {
571             super(type);
572         }
573         public boolean isPrecise() {
574             return true;
575         }
576         public long getUnitMillis() {
577             return 60;
578         }
579         public long getValueAsLong(long duration, long instant) {
580             return 0;
581         }
582         public long getMillis(int value, long instant) {
583             return 0;
584         }
585         public long getMillis(long value, long instant) {
586             return 0;
587         }
588         public long add(long instant, int value) {
589             add_int++;
590             return instant + (value * 60L);
591         }
592         public long add(long instant, long value) {
593             add_long++;
594             return instant + (value * 60L);
595         }
596         public long getDifferenceAsLong(long minuendInstant, long subtrahendInstant) {
597             difference_long++;
598             return 30;
599         }
600     }
601 
602     //-----------------------------------------------------------------------
603     static class MockZeroDurationField extends BaseDurationField {
604         protected MockZeroDurationField(DurationFieldType type) {
605             super(type);
606         }
607         public boolean isPrecise() {
608             return true;
609         }
610         public long getUnitMillis() {
611             return 0;  // this is zero
612         }
613         public long getValueAsLong(long duration, long instant) {
614             return 0;
615         }
616         public long getMillis(int value, long instant) {
617             return 0;
618         }
619         public long getMillis(long value, long instant) {
620             return 0;
621         }
622         public long add(long instant, int value) {
623             return 0;
624         }
625         public long add(long instant, long value) {
626             return 0;
627         }
628         public long getDifferenceAsLong(long minuendInstant, long subtrahendInstant) {
629             return 0;
630         }
631     }
632 
633     //-----------------------------------------------------------------------
634     static class MockImpreciseDurationField extends BaseDurationField {
635         protected MockImpreciseDurationField(DurationFieldType type) {
636             super(type);
637         }
638         public boolean isPrecise() {
639             return false;  // this is false
640         }
641         public long getUnitMillis() {
642             return 0;
643         }
644         public long getValueAsLong(long duration, long instant) {
645             return 0;
646         }
647         public long getMillis(int value, long instant) {
648             return 0;
649         }
650         public long getMillis(long value, long instant) {
651             return 0;
652         }
653         public long add(long instant, int value) {
654             return 0;
655         }
656         public long add(long instant, long value) {
657             return 0;
658         }
659         public long getDifferenceAsLong(long minuendInstant, long subtrahendInstant) {
660             return 0;
661         }
662     }
663 
664 }