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