Source Code Cross Referenced for TestPreciseDurationDateTimeField.java in  » Development » Joda-Time » org » joda » time » field » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Development » Joda Time » org.joda.time.field 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.field;
017:
018:        import java.util.Arrays;
019:        import java.util.Locale;
020:
021:        import junit.framework.TestCase;
022:        import junit.framework.TestSuite;
023:
024:        import org.joda.time.DateTimeFieldType;
025:        import org.joda.time.DurationField;
026:        import org.joda.time.DurationFieldType;
027:        import org.joda.time.TimeOfDay;
028:        import org.joda.time.chrono.ISOChronology;
029:
030:        /**
031:         * This class is a Junit unit test for PreciseDurationDateTimeField.
032:         *
033:         * @author Stephen Colebourne
034:         */
035:        public class TestPreciseDurationDateTimeField extends TestCase {
036:
037:            public static void main(String[] args) {
038:                junit.textui.TestRunner.run(suite());
039:            }
040:
041:            public static TestSuite suite() {
042:                return new TestSuite(TestPreciseDurationDateTimeField.class);
043:            }
044:
045:            public TestPreciseDurationDateTimeField(String name) {
046:                super (name);
047:            }
048:
049:            protected void setUp() throws Exception {
050:            }
051:
052:            protected void tearDown() throws Exception {
053:            }
054:
055:            //-----------------------------------------------------------------------
056:            public void test_constructor() {
057:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
058:                assertEquals(DateTimeFieldType.secondOfMinute(), field
059:                        .getType());
060:                try {
061:                    field = new MockPreciseDurationDateTimeField(null, null);
062:                    fail();
063:                } catch (IllegalArgumentException ex) {
064:                }
065:                try {
066:                    field = new MockPreciseDurationDateTimeField(
067:                            DateTimeFieldType.minuteOfHour(),
068:                            new MockImpreciseDurationField(DurationFieldType
069:                                    .minutes()));
070:                    fail();
071:                } catch (IllegalArgumentException ex) {
072:                }
073:                try {
074:                    field = new MockPreciseDurationDateTimeField(
075:                            DateTimeFieldType.minuteOfHour(),
076:                            new MockZeroDurationField(DurationFieldType
077:                                    .minutes()));
078:                    fail();
079:                } catch (IllegalArgumentException ex) {
080:                }
081:            }
082:
083:            public void test_getType() {
084:                BaseDateTimeField field = new MockPreciseDurationDateTimeField(
085:                        DateTimeFieldType.secondOfDay(),
086:                        new MockCountingDurationField(DurationFieldType
087:                                .minutes()));
088:                assertEquals(DateTimeFieldType.secondOfDay(), field.getType());
089:            }
090:
091:            public void test_getName() {
092:                BaseDateTimeField field = new MockPreciseDurationDateTimeField(
093:                        DateTimeFieldType.secondOfDay(),
094:                        new MockCountingDurationField(DurationFieldType
095:                                .minutes()));
096:                assertEquals("secondOfDay", field.getName());
097:            }
098:
099:            public void test_toString() {
100:                BaseDateTimeField field = new MockPreciseDurationDateTimeField(
101:                        DateTimeFieldType.secondOfDay(),
102:                        new MockCountingDurationField(DurationFieldType
103:                                .minutes()));
104:                assertEquals("DateTimeField[secondOfDay]", field.toString());
105:            }
106:
107:            public void test_isSupported() {
108:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
109:                assertEquals(true, field.isSupported());
110:            }
111:
112:            public void test_isLenient() {
113:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
114:                assertEquals(false, field.isLenient());
115:            }
116:
117:            public void test_get() {
118:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
119:                assertEquals(0, field.get(0));
120:                assertEquals(1, field.get(60));
121:                assertEquals(2, field.get(123));
122:            }
123:
124:            //-----------------------------------------------------------------------
125:            public void test_getAsText_long_Locale() {
126:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
127:                assertEquals("29", field.getAsText(60L * 29, Locale.ENGLISH));
128:                assertEquals("29", field.getAsText(60L * 29, null));
129:            }
130:
131:            public void test_getAsText_long() {
132:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
133:                assertEquals("29", field.getAsText(60L * 29));
134:            }
135:
136:            public void test_getAsText_RP_int_Locale() {
137:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
138:                assertEquals("20", field.getAsText(
139:                        new TimeOfDay(12, 30, 40, 50), 20, Locale.ENGLISH));
140:                assertEquals("20", field.getAsText(
141:                        new TimeOfDay(12, 30, 40, 50), 20, null));
142:            }
143:
144:            public void test_getAsText_RP_Locale() {
145:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
146:                assertEquals("40", field.getAsText(
147:                        new TimeOfDay(12, 30, 40, 50), Locale.ENGLISH));
148:                assertEquals("40", field.getAsText(
149:                        new TimeOfDay(12, 30, 40, 50), null));
150:            }
151:
152:            public void test_getAsText_int_Locale() {
153:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
154:                assertEquals("80", field.getAsText(80, Locale.ENGLISH));
155:                assertEquals("80", field.getAsText(80, null));
156:            }
157:
158:            //-----------------------------------------------------------------------
159:            public void test_getAsShortText_long_Locale() {
160:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
161:                assertEquals("29", field.getAsShortText(60L * 29,
162:                        Locale.ENGLISH));
163:                assertEquals("29", field.getAsShortText(60L * 29, null));
164:            }
165:
166:            public void test_getAsShortText_long() {
167:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
168:                assertEquals("29", field.getAsShortText(60L * 29));
169:            }
170:
171:            public void test_getAsShortText_RP_int_Locale() {
172:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
173:                assertEquals("20", field.getAsShortText(new TimeOfDay(12, 30,
174:                        40, 50), 20, Locale.ENGLISH));
175:                assertEquals("20", field.getAsShortText(new TimeOfDay(12, 30,
176:                        40, 50), 20, null));
177:            }
178:
179:            public void test_getAsShortText_RP_Locale() {
180:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
181:                assertEquals("40", field.getAsShortText(new TimeOfDay(12, 30,
182:                        40, 50), Locale.ENGLISH));
183:                assertEquals("40", field.getAsShortText(new TimeOfDay(12, 30,
184:                        40, 50), null));
185:            }
186:
187:            public void test_getAsShortText_int_Locale() {
188:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
189:                assertEquals("80", field.getAsShortText(80, Locale.ENGLISH));
190:                assertEquals("80", field.getAsShortText(80, null));
191:            }
192:
193:            //-----------------------------------------------------------------------
194:            public void test_add_long_int() {
195:                MockCountingDurationField.add_int = 0;
196:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
197:                assertEquals(61, field.add(1L, 1));
198:                assertEquals(1, MockCountingDurationField.add_int);
199:            }
200:
201:            public void test_add_long_long() {
202:                MockCountingDurationField.add_long = 0;
203:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
204:                assertEquals(61, field.add(1L, 1L));
205:                assertEquals(1, MockCountingDurationField.add_long);
206:            }
207:
208:            public void test_add_RP_int_intarray_int() {
209:                int[] values = new int[] { 10, 20, 30, 40 };
210:                int[] expected = new int[] { 10, 20, 30, 40 };
211:                BaseDateTimeField field = new MockStandardBaseDateTimeField();
212:                int[] result = field.add(new TimeOfDay(), 2, values, 0);
213:                assertEquals(true, Arrays.equals(expected, result));
214:
215:                values = new int[] { 10, 20, 30, 40 };
216:                expected = new int[] { 10, 20, 31, 40 };
217:                result = field.add(new TimeOfDay(), 2, values, 1);
218:                assertEquals(true, Arrays.equals(expected, result));
219:
220:                values = new int[] { 10, 20, 30, 40 };
221:                expected = new int[] { 10, 21, 0, 40 };
222:                result = field.add(new TimeOfDay(), 2, values, 30);
223:                assertEquals(true, Arrays.equals(expected, result));
224:
225:                values = new int[] { 23, 59, 30, 40 };
226:                try {
227:                    field.add(new TimeOfDay(), 2, values, 30);
228:                    fail();
229:                } catch (IllegalArgumentException ex) {
230:                }
231:
232:                values = new int[] { 10, 20, 30, 40 };
233:                expected = new int[] { 10, 20, 29, 40 };
234:                result = field.add(new TimeOfDay(), 2, values, -1);
235:                assertEquals(true, Arrays.equals(expected, result));
236:
237:                values = new int[] { 10, 20, 30, 40 };
238:                expected = new int[] { 10, 19, 59, 40 };
239:                result = field.add(new TimeOfDay(), 2, values, -31);
240:                assertEquals(true, Arrays.equals(expected, result));
241:
242:                values = new int[] { 0, 0, 30, 40 };
243:                try {
244:                    field.add(new TimeOfDay(), 2, values, -31);
245:                    fail();
246:                } catch (IllegalArgumentException ex) {
247:                }
248:            }
249:
250:            //-----------------------------------------------------------------------
251:            public void test_addWrapField_long_int() {
252:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
253:                assertEquals(29 * 60L, field.addWrapField(60L * 29, 0));
254:                assertEquals(59 * 60L, field.addWrapField(60L * 29, 30));
255:                assertEquals(0 * 60L, field.addWrapField(60L * 29, 31));
256:            }
257:
258:            public void test_addWrapField_RP_int_intarray_int() {
259:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
260:                int[] values = new int[] { 10, 20, 30, 40 };
261:                int[] expected = new int[] { 10, 20, 30, 40 };
262:                int[] result = field
263:                        .addWrapField(new TimeOfDay(), 2, values, 0);
264:                assertEquals(true, Arrays.equals(result, expected));
265:
266:                values = new int[] { 10, 20, 30, 40 };
267:                expected = new int[] { 10, 20, 59, 40 };
268:                result = field.addWrapField(new TimeOfDay(), 2, values, 29);
269:                assertEquals(true, Arrays.equals(result, expected));
270:
271:                values = new int[] { 10, 20, 30, 40 };
272:                expected = new int[] { 10, 20, 0, 40 };
273:                result = field.addWrapField(new TimeOfDay(), 2, values, 30);
274:                assertEquals(true, Arrays.equals(result, expected));
275:
276:                values = new int[] { 10, 20, 30, 40 };
277:                expected = new int[] { 10, 20, 1, 40 };
278:                result = field.addWrapField(new TimeOfDay(), 2, values, 31);
279:                assertEquals(true, Arrays.equals(result, expected));
280:            }
281:
282:            //-----------------------------------------------------------------------
283:            public void test_getDifference_long_long() {
284:                MockCountingDurationField.difference_long = 0;
285:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
286:                assertEquals(30, field.getDifference(0L, 0L));
287:                assertEquals(1, MockCountingDurationField.difference_long);
288:            }
289:
290:            public void test_getDifferenceAsLong_long_long() {
291:                MockCountingDurationField.difference_long = 0;
292:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
293:                assertEquals(30, field.getDifferenceAsLong(0L, 0L));
294:                assertEquals(1, MockCountingDurationField.difference_long);
295:            }
296:
297:            //-----------------------------------------------------------------------
298:            public void test_set_long_int() {
299:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
300:                assertEquals(0, field.set(120L, 0));
301:                assertEquals(29 * 60, field.set(120L, 29));
302:            }
303:
304:            public void test_set_RP_int_intarray_int() {
305:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
306:                int[] values = new int[] { 10, 20, 30, 40 };
307:                int[] expected = new int[] { 10, 20, 30, 40 };
308:                int[] result = field.set(new TimeOfDay(), 2, values, 30);
309:                assertEquals(true, Arrays.equals(result, expected));
310:
311:                values = new int[] { 10, 20, 30, 40 };
312:                expected = new int[] { 10, 20, 29, 40 };
313:                result = field.set(new TimeOfDay(), 2, values, 29);
314:                assertEquals(true, Arrays.equals(result, expected));
315:
316:                values = new int[] { 10, 20, 30, 40 };
317:                expected = new int[] { 10, 20, 30, 40 };
318:                try {
319:                    field.set(new TimeOfDay(), 2, values, 60);
320:                    fail();
321:                } catch (IllegalArgumentException ex) {
322:                }
323:                assertEquals(true, Arrays.equals(values, expected));
324:
325:                values = new int[] { 10, 20, 30, 40 };
326:                expected = new int[] { 10, 20, 30, 40 };
327:                try {
328:                    field.set(new TimeOfDay(), 2, values, -1);
329:                    fail();
330:                } catch (IllegalArgumentException ex) {
331:                }
332:                assertEquals(true, Arrays.equals(values, expected));
333:            }
334:
335:            public void test_set_long_String_Locale() {
336:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
337:                assertEquals(0, field.set(0L, "0", null));
338:                assertEquals(29 * 60, field.set(0L, "29", Locale.ENGLISH));
339:            }
340:
341:            public void test_set_long_String() {
342:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
343:                assertEquals(0, field.set(0L, "0"));
344:                assertEquals(29 * 60, field.set(0L, "29"));
345:            }
346:
347:            public void test_set_RP_int_intarray_String_Locale() {
348:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
349:                int[] values = new int[] { 10, 20, 30, 40 };
350:                int[] expected = new int[] { 10, 20, 30, 40 };
351:                int[] result = field
352:                        .set(new TimeOfDay(), 2, values, "30", null);
353:                assertEquals(true, Arrays.equals(result, expected));
354:
355:                values = new int[] { 10, 20, 30, 40 };
356:                expected = new int[] { 10, 20, 29, 40 };
357:                result = field.set(new TimeOfDay(), 2, values, "29",
358:                        Locale.ENGLISH);
359:                assertEquals(true, Arrays.equals(result, expected));
360:
361:                values = new int[] { 10, 20, 30, 40 };
362:                expected = new int[] { 10, 20, 30, 40 };
363:                try {
364:                    field.set(new TimeOfDay(), 2, values, "60", null);
365:                    fail();
366:                } catch (IllegalArgumentException ex) {
367:                }
368:                assertEquals(true, Arrays.equals(values, expected));
369:
370:                values = new int[] { 10, 20, 30, 40 };
371:                expected = new int[] { 10, 20, 30, 40 };
372:                try {
373:                    field.set(new TimeOfDay(), 2, values, "-1", null);
374:                    fail();
375:                } catch (IllegalArgumentException ex) {
376:                }
377:                assertEquals(true, Arrays.equals(values, expected));
378:            }
379:
380:            public void test_convertText() {
381:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
382:                assertEquals(0, field.convertText("0", null));
383:                assertEquals(29, field.convertText("29", null));
384:                try {
385:                    field.convertText("2A", null);
386:                    fail();
387:                } catch (IllegalArgumentException ex) {
388:                }
389:                try {
390:                    field.convertText(null, null);
391:                    fail();
392:                } catch (IllegalArgumentException ex) {
393:                }
394:            }
395:
396:            //------------------------------------------------------------------------
397:            //    public abstract DurationField getDurationField();
398:            //
399:            //    public abstract DurationField getRangeDurationField();
400:
401:            public void test_isLeap_long() {
402:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
403:                assertEquals(false, field.isLeap(0L));
404:            }
405:
406:            public void test_getLeapAmount_long() {
407:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
408:                assertEquals(0, field.getLeapAmount(0L));
409:            }
410:
411:            public void test_getLeapDurationField() {
412:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
413:                assertEquals(null, field.getLeapDurationField());
414:            }
415:
416:            //-----------------------------------------------------------------------
417:            public void test_getMinimumValue() {
418:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
419:                assertEquals(0, field.getMinimumValue());
420:            }
421:
422:            public void test_getMinimumValue_long() {
423:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
424:                assertEquals(0, field.getMinimumValue(0L));
425:            }
426:
427:            public void test_getMinimumValue_RP() {
428:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
429:                assertEquals(0, field.getMinimumValue(new TimeOfDay()));
430:            }
431:
432:            public void test_getMinimumValue_RP_intarray() {
433:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
434:                assertEquals(0, field.getMinimumValue(new TimeOfDay(),
435:                        new int[4]));
436:            }
437:
438:            public void test_getMaximumValue() {
439:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
440:                assertEquals(59, field.getMaximumValue());
441:            }
442:
443:            public void test_getMaximumValue_long() {
444:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
445:                assertEquals(59, field.getMaximumValue(0L));
446:            }
447:
448:            public void test_getMaximumValue_RP() {
449:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
450:                assertEquals(59, field.getMaximumValue(new TimeOfDay()));
451:            }
452:
453:            public void test_getMaximumValue_RP_intarray() {
454:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
455:                assertEquals(59, field.getMaximumValue(new TimeOfDay(),
456:                        new int[4]));
457:            }
458:
459:            //-----------------------------------------------------------------------
460:            public void test_getMaximumTextLength_Locale() {
461:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
462:                assertEquals(2, field.getMaximumTextLength(Locale.ENGLISH));
463:
464:                field = new MockPreciseDurationDateTimeField() {
465:                    public int getMaximumValue() {
466:                        return 5;
467:                    }
468:                };
469:                assertEquals(1, field.getMaximumTextLength(Locale.ENGLISH));
470:
471:                field = new MockPreciseDurationDateTimeField() {
472:                    public int getMaximumValue() {
473:                        return 555;
474:                    }
475:                };
476:                assertEquals(3, field.getMaximumTextLength(Locale.ENGLISH));
477:
478:                field = new MockPreciseDurationDateTimeField() {
479:                    public int getMaximumValue() {
480:                        return 5555;
481:                    }
482:                };
483:                assertEquals(4, field.getMaximumTextLength(Locale.ENGLISH));
484:
485:                field = new MockPreciseDurationDateTimeField() {
486:                    public int getMaximumValue() {
487:                        return -1;
488:                    }
489:                };
490:                assertEquals(2, field.getMaximumTextLength(Locale.ENGLISH));
491:            }
492:
493:            public void test_getMaximumShortTextLength_Locale() {
494:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
495:                assertEquals(2, field.getMaximumShortTextLength(Locale.ENGLISH));
496:            }
497:
498:            //------------------------------------------------------------------------
499:            public void test_roundFloor_long() {
500:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
501:                assertEquals(-120L, field.roundFloor(-61L));
502:                assertEquals(-60L, field.roundFloor(-60L));
503:                assertEquals(-60L, field.roundFloor(-59L));
504:                assertEquals(-60L, field.roundFloor(-1L));
505:                assertEquals(0L, field.roundFloor(0L));
506:                assertEquals(0L, field.roundFloor(1L));
507:                assertEquals(0L, field.roundFloor(29L));
508:                assertEquals(0L, field.roundFloor(30L));
509:                assertEquals(0L, field.roundFloor(31L));
510:                assertEquals(60L, field.roundFloor(60L));
511:            }
512:
513:            public void test_roundCeiling_long() {
514:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
515:                assertEquals(-60L, field.roundCeiling(-61L));
516:                assertEquals(-60L, field.roundCeiling(-60L));
517:                assertEquals(0L, field.roundCeiling(-59L));
518:                assertEquals(0L, field.roundCeiling(-1L));
519:                assertEquals(0L, field.roundCeiling(0L));
520:                assertEquals(60L, field.roundCeiling(1L));
521:                assertEquals(60L, field.roundCeiling(29L));
522:                assertEquals(60L, field.roundCeiling(30L));
523:                assertEquals(60L, field.roundCeiling(31L));
524:                assertEquals(60L, field.roundCeiling(60L));
525:            }
526:
527:            public void test_roundHalfFloor_long() {
528:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
529:                assertEquals(0L, field.roundHalfFloor(0L));
530:                assertEquals(0L, field.roundHalfFloor(29L));
531:                assertEquals(0L, field.roundHalfFloor(30L));
532:                assertEquals(60L, field.roundHalfFloor(31L));
533:                assertEquals(60L, field.roundHalfFloor(60L));
534:            }
535:
536:            public void test_roundHalfCeiling_long() {
537:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
538:                assertEquals(0L, field.roundHalfCeiling(0L));
539:                assertEquals(0L, field.roundHalfCeiling(29L));
540:                assertEquals(60L, field.roundHalfCeiling(30L));
541:                assertEquals(60L, field.roundHalfCeiling(31L));
542:                assertEquals(60L, field.roundHalfCeiling(60L));
543:            }
544:
545:            public void test_roundHalfEven_long() {
546:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
547:                assertEquals(0L, field.roundHalfEven(0L));
548:                assertEquals(0L, field.roundHalfEven(29L));
549:                assertEquals(0L, field.roundHalfEven(30L));
550:                assertEquals(60L, field.roundHalfEven(31L));
551:                assertEquals(60L, field.roundHalfEven(60L));
552:                assertEquals(60L, field.roundHalfEven(89L));
553:                assertEquals(120L, field.roundHalfEven(90L));
554:                assertEquals(120L, field.roundHalfEven(91L));
555:            }
556:
557:            public void test_remainder_long() {
558:                BaseDateTimeField field = new MockPreciseDurationDateTimeField();
559:                assertEquals(0L, field.remainder(0L));
560:                assertEquals(29L, field.remainder(29L));
561:                assertEquals(30L, field.remainder(30L));
562:                assertEquals(31L, field.remainder(31L));
563:                assertEquals(0L, field.remainder(60L));
564:            }
565:
566:            //-----------------------------------------------------------------------
567:            static class MockPreciseDurationDateTimeField extends
568:                    PreciseDurationDateTimeField {
569:                protected MockPreciseDurationDateTimeField() {
570:                    super (DateTimeFieldType.secondOfMinute(),
571:                            new MockCountingDurationField(DurationFieldType
572:                                    .seconds()));
573:                }
574:
575:                protected MockPreciseDurationDateTimeField(
576:                        DateTimeFieldType type, DurationField dur) {
577:                    super (type, dur);
578:                }
579:
580:                public int get(long instant) {
581:                    return (int) (instant / 60L);
582:                }
583:
584:                public DurationField getRangeDurationField() {
585:                    return new MockCountingDurationField(DurationFieldType
586:                            .minutes());
587:                }
588:
589:                public int getMaximumValue() {
590:                    return 59;
591:                }
592:            }
593:
594:            static class MockStandardBaseDateTimeField extends
595:                    MockPreciseDurationDateTimeField {
596:                protected MockStandardBaseDateTimeField() {
597:                    super ();
598:                }
599:
600:                public DurationField getDurationField() {
601:                    return ISOChronology.getInstanceUTC().seconds();
602:                }
603:
604:                public DurationField getRangeDurationField() {
605:                    return ISOChronology.getInstanceUTC().minutes();
606:                }
607:            }
608:
609:            //-----------------------------------------------------------------------
610:            static class MockCountingDurationField extends BaseDurationField {
611:                static int add_int = 0;
612:                static int add_long = 0;
613:                static int difference_long = 0;
614:
615:                protected MockCountingDurationField(DurationFieldType type) {
616:                    super (type);
617:                }
618:
619:                public boolean isPrecise() {
620:                    return true;
621:                }
622:
623:                public long getUnitMillis() {
624:                    return 60;
625:                }
626:
627:                public long getValueAsLong(long duration, long instant) {
628:                    return 0;
629:                }
630:
631:                public long getMillis(int value, long instant) {
632:                    return 0;
633:                }
634:
635:                public long getMillis(long value, long instant) {
636:                    return 0;
637:                }
638:
639:                public long add(long instant, int value) {
640:                    add_int++;
641:                    return instant + (value * 60L);
642:                }
643:
644:                public long add(long instant, long value) {
645:                    add_long++;
646:                    return instant + (value * 60L);
647:                }
648:
649:                public long getDifferenceAsLong(long minuendInstant,
650:                        long subtrahendInstant) {
651:                    difference_long++;
652:                    return 30;
653:                }
654:            }
655:
656:            //-----------------------------------------------------------------------
657:            static class MockZeroDurationField extends BaseDurationField {
658:                protected MockZeroDurationField(DurationFieldType type) {
659:                    super (type);
660:                }
661:
662:                public boolean isPrecise() {
663:                    return true;
664:                }
665:
666:                public long getUnitMillis() {
667:                    return 0; // this is zero
668:                }
669:
670:                public long getValueAsLong(long duration, long instant) {
671:                    return 0;
672:                }
673:
674:                public long getMillis(int value, long instant) {
675:                    return 0;
676:                }
677:
678:                public long getMillis(long value, long instant) {
679:                    return 0;
680:                }
681:
682:                public long add(long instant, int value) {
683:                    return 0;
684:                }
685:
686:                public long add(long instant, long value) {
687:                    return 0;
688:                }
689:
690:                public long getDifferenceAsLong(long minuendInstant,
691:                        long subtrahendInstant) {
692:                    return 0;
693:                }
694:            }
695:
696:            //-----------------------------------------------------------------------
697:            static class MockImpreciseDurationField extends BaseDurationField {
698:                protected MockImpreciseDurationField(DurationFieldType type) {
699:                    super (type);
700:                }
701:
702:                public boolean isPrecise() {
703:                    return false; // this is false
704:                }
705:
706:                public long getUnitMillis() {
707:                    return 0;
708:                }
709:
710:                public long getValueAsLong(long duration, long instant) {
711:                    return 0;
712:                }
713:
714:                public long getMillis(int value, long instant) {
715:                    return 0;
716:                }
717:
718:                public long getMillis(long value, long instant) {
719:                    return 0;
720:                }
721:
722:                public long add(long instant, int value) {
723:                    return 0;
724:                }
725:
726:                public long add(long instant, long value) {
727:                    return 0;
728:                }
729:
730:                public long getDifferenceAsLong(long minuendInstant,
731:                        long subtrahendInstant) {
732:                    return 0;
733:                }
734:            }
735:
736:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.