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.convert;
017:
018: import java.lang.reflect.Constructor;
019: import java.lang.reflect.Field;
020: import java.lang.reflect.Modifier;
021: import java.util.Arrays;
022: import java.util.Locale;
023:
024: import junit.framework.TestCase;
025: import junit.framework.TestSuite;
026:
027: import org.joda.time.Chronology;
028: import org.joda.time.DateTime;
029: import org.joda.time.DateTimeZone;
030: import org.joda.time.MutableInterval;
031: import org.joda.time.MutablePeriod;
032: import org.joda.time.PeriodType;
033: import org.joda.time.TimeOfDay;
034: import org.joda.time.chrono.BuddhistChronology;
035: import org.joda.time.chrono.ISOChronology;
036: import org.joda.time.chrono.JulianChronology;
037:
038: /**
039: * This class is a Junit unit test for StringConverter.
040: *
041: * @author Stephen Colebourne
042: */
043: public class TestStringConverter extends TestCase {
044:
045: private static final DateTimeZone ONE_HOUR = DateTimeZone
046: .forOffsetHours(1);
047: private static final DateTimeZone SIX = DateTimeZone
048: .forOffsetHours(6);
049: private static final DateTimeZone SEVEN = DateTimeZone
050: .forOffsetHours(7);
051: private static final DateTimeZone EIGHT = DateTimeZone
052: .forOffsetHours(8);
053: private static final DateTimeZone UTC = DateTimeZone.UTC;
054: private static final DateTimeZone PARIS = DateTimeZone
055: .forID("Europe/Paris");
056: private static final DateTimeZone LONDON = DateTimeZone
057: .forID("Europe/London");
058: private static final Chronology ISO_EIGHT = ISOChronology
059: .getInstance(EIGHT);
060: private static final Chronology ISO_PARIS = ISOChronology
061: .getInstance(PARIS);
062: private static final Chronology ISO_LONDON = ISOChronology
063: .getInstance(LONDON);
064: private static Chronology ISO;
065: private static Chronology JULIAN;
066:
067: private DateTimeZone zone = null;
068: private Locale locale = null;
069:
070: public static void main(String[] args) {
071: junit.textui.TestRunner.run(suite());
072: }
073:
074: public static TestSuite suite() {
075: return new TestSuite(TestStringConverter.class);
076: }
077:
078: public TestStringConverter(String name) {
079: super (name);
080: }
081:
082: protected void setUp() throws Exception {
083: zone = DateTimeZone.getDefault();
084: locale = Locale.getDefault();
085: DateTimeZone.setDefault(LONDON);
086: Locale.setDefault(Locale.UK);
087:
088: JULIAN = JulianChronology.getInstance();
089: ISO = ISOChronology.getInstance();
090: }
091:
092: protected void tearDown() throws Exception {
093: DateTimeZone.setDefault(zone);
094: Locale.setDefault(locale);
095: zone = null;
096: }
097:
098: //-----------------------------------------------------------------------
099: public void testSingleton() throws Exception {
100: Class cls = StringConverter.class;
101: assertEquals(false, Modifier.isPublic(cls.getModifiers()));
102: assertEquals(false, Modifier.isProtected(cls.getModifiers()));
103: assertEquals(false, Modifier.isPrivate(cls.getModifiers()));
104:
105: Constructor con = cls.getDeclaredConstructor((Class[]) null);
106: assertEquals(1, cls.getDeclaredConstructors().length);
107: assertEquals(true, Modifier.isProtected(con.getModifiers()));
108:
109: Field fld = cls.getDeclaredField("INSTANCE");
110: assertEquals(false, Modifier.isPublic(fld.getModifiers()));
111: assertEquals(false, Modifier.isProtected(fld.getModifiers()));
112: assertEquals(false, Modifier.isPrivate(fld.getModifiers()));
113: }
114:
115: //-----------------------------------------------------------------------
116: public void testSupportedType() throws Exception {
117: assertEquals(String.class, StringConverter.INSTANCE
118: .getSupportedType());
119: }
120:
121: //-----------------------------------------------------------------------
122: public void testGetInstantMillis_Object() throws Exception {
123: DateTime dt = new DateTime(2004, 6, 9, 12, 24, 48, 501, EIGHT);
124: assertEquals(dt.getMillis(), StringConverter.INSTANCE
125: .getInstantMillis("2004-06-09T12:24:48.501+08:00",
126: ISO_EIGHT));
127:
128: dt = new DateTime(2004, 1, 1, 0, 0, 0, 0, EIGHT);
129: assertEquals(dt.getMillis(), StringConverter.INSTANCE
130: .getInstantMillis("2004T+08:00", ISO_EIGHT));
131:
132: dt = new DateTime(2004, 6, 1, 0, 0, 0, 0, EIGHT);
133: assertEquals(dt.getMillis(), StringConverter.INSTANCE
134: .getInstantMillis("2004-06T+08:00", ISO_EIGHT));
135:
136: dt = new DateTime(2004, 6, 9, 0, 0, 0, 0, EIGHT);
137: assertEquals(dt.getMillis(), StringConverter.INSTANCE
138: .getInstantMillis("2004-06-09T+08:00", ISO_EIGHT));
139:
140: dt = new DateTime(2004, 6, 9, 0, 0, 0, 0, EIGHT);
141: assertEquals(dt.getMillis(), StringConverter.INSTANCE
142: .getInstantMillis("2004-161T+08:00", ISO_EIGHT));
143:
144: dt = new DateTime(2004, 6, 9, 0, 0, 0, 0, EIGHT);
145: assertEquals(dt.getMillis(), StringConverter.INSTANCE
146: .getInstantMillis("2004-W24-3T+08:00", ISO_EIGHT));
147:
148: dt = new DateTime(2004, 6, 7, 0, 0, 0, 0, EIGHT);
149: assertEquals(dt.getMillis(), StringConverter.INSTANCE
150: .getInstantMillis("2004-W24T+08:00", ISO_EIGHT));
151:
152: dt = new DateTime(2004, 6, 9, 12, 0, 0, 0, EIGHT);
153: assertEquals(dt.getMillis(), StringConverter.INSTANCE
154: .getInstantMillis("2004-06-09T12+08:00", ISO_EIGHT));
155:
156: dt = new DateTime(2004, 6, 9, 12, 24, 0, 0, EIGHT);
157: assertEquals(dt.getMillis(), StringConverter.INSTANCE
158: .getInstantMillis("2004-06-09T12:24+08:00", ISO_EIGHT));
159:
160: dt = new DateTime(2004, 6, 9, 12, 24, 48, 0, EIGHT);
161: assertEquals(dt.getMillis(), StringConverter.INSTANCE
162: .getInstantMillis("2004-06-09T12:24:48+08:00",
163: ISO_EIGHT));
164:
165: dt = new DateTime(2004, 6, 9, 12, 30, 0, 0, EIGHT);
166: assertEquals(dt.getMillis(), StringConverter.INSTANCE
167: .getInstantMillis("2004-06-09T12.5+08:00", ISO_EIGHT));
168:
169: dt = new DateTime(2004, 6, 9, 12, 24, 30, 0, EIGHT);
170: assertEquals(dt.getMillis(),
171: StringConverter.INSTANCE.getInstantMillis(
172: "2004-06-09T12:24.5+08:00", ISO_EIGHT));
173:
174: dt = new DateTime(2004, 6, 9, 12, 24, 48, 500, EIGHT);
175: assertEquals(dt.getMillis(), StringConverter.INSTANCE
176: .getInstantMillis("2004-06-09T12:24:48.5+08:00",
177: ISO_EIGHT));
178:
179: dt = new DateTime(2004, 6, 9, 12, 24, 48, 501);
180: assertEquals(dt.getMillis(), StringConverter.INSTANCE
181: .getInstantMillis("2004-06-09T12:24:48.501", ISO));
182: }
183:
184: public void testGetInstantMillis_Object_Zone() throws Exception {
185: DateTime dt = new DateTime(2004, 6, 9, 12, 24, 48, 501, PARIS);
186: assertEquals(dt.getMillis(), StringConverter.INSTANCE
187: .getInstantMillis("2004-06-09T12:24:48.501+02:00",
188: ISO_PARIS));
189:
190: dt = new DateTime(2004, 6, 9, 12, 24, 48, 501, PARIS);
191: assertEquals(dt.getMillis(), StringConverter.INSTANCE
192: .getInstantMillis("2004-06-09T12:24:48.501", ISO_PARIS));
193:
194: dt = new DateTime(2004, 6, 9, 12, 24, 48, 501, LONDON);
195: assertEquals(dt.getMillis(), StringConverter.INSTANCE
196: .getInstantMillis("2004-06-09T12:24:48.501+01:00",
197: ISO_LONDON));
198:
199: dt = new DateTime(2004, 6, 9, 12, 24, 48, 501, LONDON);
200: assertEquals(dt.getMillis(),
201: StringConverter.INSTANCE.getInstantMillis(
202: "2004-06-09T12:24:48.501", ISO_LONDON));
203: }
204:
205: public void testGetInstantMillis_Object_Chronology()
206: throws Exception {
207: DateTime dt = new DateTime(2004, 6, 9, 12, 24, 48, 501,
208: JulianChronology.getInstance(LONDON));
209: assertEquals(dt.getMillis(), StringConverter.INSTANCE
210: .getInstantMillis("2004-06-09T12:24:48.501+01:00",
211: JULIAN));
212: }
213:
214: public void testGetInstantMillisInvalid() {
215: try {
216: StringConverter.INSTANCE.getInstantMillis("",
217: (Chronology) null);
218: fail();
219: } catch (IllegalArgumentException ex) {
220: }
221: try {
222: StringConverter.INSTANCE.getInstantMillis("X",
223: (Chronology) null);
224: fail();
225: } catch (IllegalArgumentException ex) {
226: }
227: }
228:
229: //-----------------------------------------------------------------------
230: public void testGetChronology_Object_Zone() throws Exception {
231: assertEquals(ISOChronology.getInstance(PARIS),
232: StringConverter.INSTANCE.getChronology(
233: "2004-06-09T12:24:48.501+01:00", PARIS));
234: assertEquals(ISOChronology.getInstance(PARIS),
235: StringConverter.INSTANCE.getChronology(
236: "2004-06-09T12:24:48.501", PARIS));
237: assertEquals(ISOChronology.getInstance(LONDON),
238: StringConverter.INSTANCE.getChronology(
239: "2004-06-09T12:24:48.501+01:00",
240: (DateTimeZone) null));
241: assertEquals(ISOChronology.getInstance(LONDON),
242: StringConverter.INSTANCE.getChronology(
243: "2004-06-09T12:24:48.501", (DateTimeZone) null));
244: }
245:
246: public void testGetChronology_Object_Chronology() throws Exception {
247: assertEquals(JulianChronology.getInstance(LONDON),
248: StringConverter.INSTANCE.getChronology(
249: "2004-06-09T12:24:48.501+01:00", JULIAN));
250: assertEquals(JulianChronology.getInstance(LONDON),
251: StringConverter.INSTANCE.getChronology(
252: "2004-06-09T12:24:48.501", JULIAN));
253: assertEquals(ISOChronology.getInstance(LONDON),
254: StringConverter.INSTANCE.getChronology(
255: "2004-06-09T12:24:48.501+01:00",
256: (Chronology) null));
257: assertEquals(ISOChronology.getInstance(LONDON),
258: StringConverter.INSTANCE.getChronology(
259: "2004-06-09T12:24:48.501", (Chronology) null));
260: }
261:
262: //-----------------------------------------------------------------------
263: public void testGetPartialValues() throws Exception {
264: TimeOfDay tod = new TimeOfDay();
265: int[] expected = new int[] { 3, 4, 5, 6 };
266: int[] actual = StringConverter.INSTANCE.getPartialValues(tod,
267: "T03:04:05.006", ISOChronology.getInstance());
268: assertEquals(true, Arrays.equals(expected, actual));
269: }
270:
271: //-----------------------------------------------------------------------
272: public void testGetDateTime() throws Exception {
273: DateTime base = new DateTime(2004, 6, 9, 12, 24, 48, 501, PARIS);
274: DateTime test = new DateTime(base.toString(), PARIS);
275: assertEquals(base, test);
276: }
277:
278: public void testGetDateTime1() throws Exception {
279: DateTime test = new DateTime("2004-06-09T12:24:48.501+01:00");
280: assertEquals(2004, test.getYear());
281: assertEquals(6, test.getMonthOfYear());
282: assertEquals(9, test.getDayOfMonth());
283: assertEquals(12, test.getHourOfDay());
284: assertEquals(24, test.getMinuteOfHour());
285: assertEquals(48, test.getSecondOfMinute());
286: assertEquals(501, test.getMillisOfSecond());
287: assertEquals(LONDON, test.getZone());
288: }
289:
290: public void testGetDateTime2() throws Exception {
291: DateTime test = new DateTime("2004-06-09T12:24:48.501");
292: assertEquals(2004, test.getYear());
293: assertEquals(6, test.getMonthOfYear());
294: assertEquals(9, test.getDayOfMonth());
295: assertEquals(12, test.getHourOfDay());
296: assertEquals(24, test.getMinuteOfHour());
297: assertEquals(48, test.getSecondOfMinute());
298: assertEquals(501, test.getMillisOfSecond());
299: assertEquals(LONDON, test.getZone());
300: }
301:
302: public void testGetDateTime3() throws Exception {
303: DateTime test = new DateTime("2004-06-09T12:24:48.501+02:00",
304: PARIS);
305: assertEquals(2004, test.getYear());
306: assertEquals(6, test.getMonthOfYear());
307: assertEquals(9, test.getDayOfMonth());
308: assertEquals(12, test.getHourOfDay());
309: assertEquals(24, test.getMinuteOfHour());
310: assertEquals(48, test.getSecondOfMinute());
311: assertEquals(501, test.getMillisOfSecond());
312: assertEquals(PARIS, test.getZone());
313: }
314:
315: public void testGetDateTime4() throws Exception {
316: DateTime test = new DateTime("2004-06-09T12:24:48.501", PARIS);
317: assertEquals(2004, test.getYear());
318: assertEquals(6, test.getMonthOfYear());
319: assertEquals(9, test.getDayOfMonth());
320: assertEquals(12, test.getHourOfDay());
321: assertEquals(24, test.getMinuteOfHour());
322: assertEquals(48, test.getSecondOfMinute());
323: assertEquals(501, test.getMillisOfSecond());
324: assertEquals(PARIS, test.getZone());
325: }
326:
327: public void testGetDateTime5() throws Exception {
328: DateTime test = new DateTime("2004-06-09T12:24:48.501+02:00",
329: JulianChronology.getInstance(PARIS));
330: assertEquals(2004, test.getYear());
331: assertEquals(6, test.getMonthOfYear());
332: assertEquals(9, test.getDayOfMonth());
333: assertEquals(12, test.getHourOfDay());
334: assertEquals(24, test.getMinuteOfHour());
335: assertEquals(48, test.getSecondOfMinute());
336: assertEquals(501, test.getMillisOfSecond());
337: assertEquals(PARIS, test.getZone());
338: }
339:
340: public void testGetDateTime6() throws Exception {
341: DateTime test = new DateTime("2004-06-09T12:24:48.501",
342: JulianChronology.getInstance(PARIS));
343: assertEquals(2004, test.getYear());
344: assertEquals(6, test.getMonthOfYear());
345: assertEquals(9, test.getDayOfMonth());
346: assertEquals(12, test.getHourOfDay());
347: assertEquals(24, test.getMinuteOfHour());
348: assertEquals(48, test.getSecondOfMinute());
349: assertEquals(501, test.getMillisOfSecond());
350: assertEquals(PARIS, test.getZone());
351: }
352:
353: //-----------------------------------------------------------------------
354: public void testGetDurationMillis_Object1() throws Exception {
355: long millis = StringConverter.INSTANCE
356: .getDurationMillis("PT12.345S");
357: assertEquals(12345, millis);
358:
359: millis = StringConverter.INSTANCE
360: .getDurationMillis("pt12.345s");
361: assertEquals(12345, millis);
362:
363: millis = StringConverter.INSTANCE.getDurationMillis("pt12s");
364: assertEquals(12000, millis);
365:
366: millis = StringConverter.INSTANCE.getDurationMillis("pt12.s");
367: assertEquals(12000, millis);
368:
369: millis = StringConverter.INSTANCE
370: .getDurationMillis("pt-12.32s");
371: assertEquals(-12320, millis);
372:
373: millis = StringConverter.INSTANCE
374: .getDurationMillis("pt12.3456s");
375: assertEquals(12345, millis);
376: }
377:
378: public void testGetDurationMillis_Object2() throws Exception {
379: try {
380: StringConverter.INSTANCE.getDurationMillis("P2Y6M9DXYZ");
381: fail();
382: } catch (IllegalArgumentException ex) {
383: }
384: try {
385: StringConverter.INSTANCE.getDurationMillis("PTS");
386: fail();
387: } catch (IllegalArgumentException ex) {
388: }
389: try {
390: StringConverter.INSTANCE.getDurationMillis("XT0S");
391: fail();
392: } catch (IllegalArgumentException ex) {
393: }
394: try {
395: StringConverter.INSTANCE.getDurationMillis("PX0S");
396: fail();
397: } catch (IllegalArgumentException ex) {
398: }
399: try {
400: StringConverter.INSTANCE.getDurationMillis("PT0X");
401: fail();
402: } catch (IllegalArgumentException ex) {
403: }
404: try {
405: StringConverter.INSTANCE.getDurationMillis("PTXS");
406: fail();
407: } catch (IllegalArgumentException ex) {
408: }
409: try {
410: StringConverter.INSTANCE.getDurationMillis("PT0.0.0S");
411: fail();
412: } catch (IllegalArgumentException ex) {
413: }
414: try {
415: StringConverter.INSTANCE.getDurationMillis("PT0-00S");
416: fail();
417: } catch (IllegalArgumentException ex) {
418: }
419: }
420:
421: //-----------------------------------------------------------------------
422: public void testGetPeriodType_Object() throws Exception {
423: assertEquals(PeriodType.standard(), StringConverter.INSTANCE
424: .getPeriodType("P2Y6M9D"));
425: }
426:
427: public void testSetIntoPeriod_Object1() throws Exception {
428: MutablePeriod m = new MutablePeriod(PeriodType
429: .yearMonthDayTime());
430: StringConverter.INSTANCE.setInto(m, "P2Y6M9DT12H24M48S", null);
431: assertEquals(2, m.getYears());
432: assertEquals(6, m.getMonths());
433: assertEquals(9, m.getDays());
434: assertEquals(12, m.getHours());
435: assertEquals(24, m.getMinutes());
436: assertEquals(48, m.getSeconds());
437: assertEquals(0, m.getMillis());
438: }
439:
440: public void testSetIntoPeriod_Object2() throws Exception {
441: MutablePeriod m = new MutablePeriod(PeriodType
442: .yearWeekDayTime());
443: StringConverter.INSTANCE.setInto(m, "P2Y4W3DT12H24M48S", null);
444: assertEquals(2, m.getYears());
445: assertEquals(4, m.getWeeks());
446: assertEquals(3, m.getDays());
447: assertEquals(12, m.getHours());
448: assertEquals(24, m.getMinutes());
449: assertEquals(48, m.getSeconds());
450: assertEquals(0, m.getMillis());
451: }
452:
453: public void testSetIntoPeriod_Object3() throws Exception {
454: MutablePeriod m = new MutablePeriod(PeriodType
455: .yearWeekDayTime());
456: StringConverter.INSTANCE.setInto(m, "P2Y4W3DT12H24M48.034S",
457: null);
458: assertEquals(2, m.getYears());
459: assertEquals(4, m.getWeeks());
460: assertEquals(3, m.getDays());
461: assertEquals(12, m.getHours());
462: assertEquals(24, m.getMinutes());
463: assertEquals(48, m.getSeconds());
464: assertEquals(34, m.getMillis());
465: }
466:
467: public void testSetIntoPeriod_Object4() throws Exception {
468: MutablePeriod m = new MutablePeriod(PeriodType
469: .yearWeekDayTime());
470: StringConverter.INSTANCE
471: .setInto(m, "P2Y4W3DT12H24M.056S", null);
472: assertEquals(2, m.getYears());
473: assertEquals(4, m.getWeeks());
474: assertEquals(3, m.getDays());
475: assertEquals(12, m.getHours());
476: assertEquals(24, m.getMinutes());
477: assertEquals(0, m.getSeconds());
478: assertEquals(56, m.getMillis());
479: }
480:
481: public void testSetIntoPeriod_Object5() throws Exception {
482: MutablePeriod m = new MutablePeriod(PeriodType
483: .yearWeekDayTime());
484: StringConverter.INSTANCE.setInto(m, "P2Y4W3DT12H24M56.S", null);
485: assertEquals(2, m.getYears());
486: assertEquals(4, m.getWeeks());
487: assertEquals(3, m.getDays());
488: assertEquals(12, m.getHours());
489: assertEquals(24, m.getMinutes());
490: assertEquals(56, m.getSeconds());
491: assertEquals(0, m.getMillis());
492: }
493:
494: public void testSetIntoPeriod_Object6() throws Exception {
495: MutablePeriod m = new MutablePeriod(PeriodType
496: .yearWeekDayTime());
497: StringConverter.INSTANCE.setInto(m,
498: "P2Y4W3DT12H24M56.1234567S", null);
499: assertEquals(2, m.getYears());
500: assertEquals(4, m.getWeeks());
501: assertEquals(3, m.getDays());
502: assertEquals(12, m.getHours());
503: assertEquals(24, m.getMinutes());
504: assertEquals(56, m.getSeconds());
505: assertEquals(123, m.getMillis());
506: }
507:
508: public void testSetIntoPeriod_Object7() throws Exception {
509: MutablePeriod m = new MutablePeriod(1, 0, 1, 1, 1, 1, 1, 1,
510: PeriodType.yearWeekDayTime());
511: StringConverter.INSTANCE.setInto(m, "P2Y4W3D", null);
512: assertEquals(2, m.getYears());
513: assertEquals(4, m.getWeeks());
514: assertEquals(3, m.getDays());
515: assertEquals(0, m.getHours());
516: assertEquals(0, m.getMinutes());
517: assertEquals(0, m.getSeconds());
518: assertEquals(0, m.getMillis());
519: }
520:
521: public void testSetIntoPeriod_Object8() throws Exception {
522: MutablePeriod m = new MutablePeriod();
523: try {
524: StringConverter.INSTANCE.setInto(m, "", null);
525: fail();
526: } catch (IllegalArgumentException ex) {
527: }
528:
529: try {
530: StringConverter.INSTANCE.setInto(m, "PXY", null);
531: fail();
532: } catch (IllegalArgumentException ex) {
533: }
534:
535: try {
536: StringConverter.INSTANCE.setInto(m, "PT0SXY", null);
537: fail();
538: } catch (IllegalArgumentException ex) {
539: }
540: try {
541: StringConverter.INSTANCE.setInto(m, "P2Y4W3DT12H24M48SX",
542: null);
543: fail();
544: } catch (IllegalArgumentException ex) {
545: }
546: }
547:
548: //-----------------------------------------------------------------------
549: public void testIsReadableInterval_Object_Chronology()
550: throws Exception {
551: assertEquals(false, StringConverter.INSTANCE
552: .isReadableInterval("", null));
553: }
554:
555: public void testSetIntoInterval_Object_Chronology1()
556: throws Exception {
557: MutableInterval m = new MutableInterval(-1000L, 1000L);
558: StringConverter.INSTANCE.setInto(m, "2004-06-09/P1Y2M", null);
559: assertEquals(new DateTime(2004, 6, 9, 0, 0, 0, 0), m.getStart());
560: assertEquals(new DateTime(2005, 8, 9, 0, 0, 0, 0), m.getEnd());
561: assertEquals(ISOChronology.getInstance(), m.getChronology());
562: }
563:
564: public void testSetIntoInterval_Object_Chronology2()
565: throws Exception {
566: MutableInterval m = new MutableInterval(-1000L, 1000L);
567: StringConverter.INSTANCE.setInto(m, "P1Y2M/2004-06-09", null);
568: assertEquals(new DateTime(2003, 4, 9, 0, 0, 0, 0), m.getStart());
569: assertEquals(new DateTime(2004, 6, 9, 0, 0, 0, 0), m.getEnd());
570: assertEquals(ISOChronology.getInstance(), m.getChronology());
571: }
572:
573: public void testSetIntoInterval_Object_Chronology3()
574: throws Exception {
575: MutableInterval m = new MutableInterval(-1000L, 1000L);
576: StringConverter.INSTANCE.setInto(m, "2003-08-09/2004-06-09",
577: null);
578: assertEquals(new DateTime(2003, 8, 9, 0, 0, 0, 0), m.getStart());
579: assertEquals(new DateTime(2004, 6, 9, 0, 0, 0, 0), m.getEnd());
580: assertEquals(ISOChronology.getInstance(), m.getChronology());
581: }
582:
583: public void testSetIntoInterval_Object_Chronology4()
584: throws Exception {
585: MutableInterval m = new MutableInterval(-1000L, 1000L);
586: StringConverter.INSTANCE.setInto(m, "2004-06-09T+06:00/P1Y2M",
587: null);
588: assertEquals(new DateTime(2004, 6, 9, 0, 0, 0, 0, SIX)
589: .withChronology(null), m.getStart());
590: assertEquals(new DateTime(2005, 8, 9, 0, 0, 0, 0, SIX)
591: .withChronology(null), m.getEnd());
592: assertEquals(ISOChronology.getInstance(), m.getChronology());
593: }
594:
595: public void testSetIntoInterval_Object_Chronology5()
596: throws Exception {
597: MutableInterval m = new MutableInterval(-1000L, 1000L);
598: StringConverter.INSTANCE.setInto(m, "P1Y2M/2004-06-09T+06:00",
599: null);
600: assertEquals(new DateTime(2003, 4, 9, 0, 0, 0, 0, SIX)
601: .withChronology(null), m.getStart());
602: assertEquals(new DateTime(2004, 6, 9, 0, 0, 0, 0, SIX)
603: .withChronology(null), m.getEnd());
604: assertEquals(ISOChronology.getInstance(), m.getChronology());
605: }
606:
607: public void testSetIntoInterval_Object_Chronology6()
608: throws Exception {
609: MutableInterval m = new MutableInterval(-1000L, 1000L);
610: StringConverter.INSTANCE.setInto(m,
611: "2003-08-09T+06:00/2004-06-09T+07:00", null);
612: assertEquals(new DateTime(2003, 8, 9, 0, 0, 0, 0, SIX)
613: .withChronology(null), m.getStart());
614: assertEquals(new DateTime(2004, 6, 9, 0, 0, 0, 0, SEVEN)
615: .withChronology(null), m.getEnd());
616: assertEquals(ISOChronology.getInstance(), m.getChronology());
617: }
618:
619: public void testSetIntoInterval_Object_Chronology7()
620: throws Exception {
621: MutableInterval m = new MutableInterval(-1000L, 1000L);
622: StringConverter.INSTANCE.setInto(m, "2003-08-09/2004-06-09",
623: BuddhistChronology.getInstance());
624: assertEquals(new DateTime(2003, 8, 9, 0, 0, 0, 0,
625: BuddhistChronology.getInstance()), m.getStart());
626: assertEquals(new DateTime(2004, 6, 9, 0, 0, 0, 0,
627: BuddhistChronology.getInstance()), m.getEnd());
628: assertEquals(BuddhistChronology.getInstance(), m
629: .getChronology());
630: }
631:
632: public void testSetIntoInterval_Object_Chronology8()
633: throws Exception {
634: MutableInterval m = new MutableInterval(-1000L, 1000L);
635: StringConverter.INSTANCE.setInto(m,
636: "2003-08-09T+06:00/2004-06-09T+07:00",
637: BuddhistChronology.getInstance(EIGHT));
638: assertEquals(new DateTime(2003, 8, 9, 0, 0, 0, 0,
639: BuddhistChronology.getInstance(SIX)).withZone(EIGHT), m
640: .getStart());
641: assertEquals(new DateTime(2004, 6, 9, 0, 0, 0, 0,
642: BuddhistChronology.getInstance(SEVEN)).withZone(EIGHT),
643: m.getEnd());
644: assertEquals(BuddhistChronology.getInstance(EIGHT), m
645: .getChronology());
646: }
647:
648: public void testSetIntoIntervalEx_Object_Chronology1()
649: throws Exception {
650: MutableInterval m = new MutableInterval(-1000L, 1000L);
651: try {
652: StringConverter.INSTANCE.setInto(m, "", null);
653: fail();
654: } catch (IllegalArgumentException ex) {
655: }
656: }
657:
658: public void testSetIntoIntervalEx_Object_Chronology2()
659: throws Exception {
660: MutableInterval m = new MutableInterval(-1000L, 1000L);
661: try {
662: StringConverter.INSTANCE.setInto(m, "/", null);
663: fail();
664: } catch (IllegalArgumentException ex) {
665: }
666: }
667:
668: public void testSetIntoIntervalEx_Object_Chronology3()
669: throws Exception {
670: MutableInterval m = new MutableInterval(-1000L, 1000L);
671: try {
672: StringConverter.INSTANCE.setInto(m, "P1Y/", null);
673: fail();
674: } catch (IllegalArgumentException ex) {
675: }
676: }
677:
678: public void testSetIntoIntervalEx_Object_Chronology4()
679: throws Exception {
680: MutableInterval m = new MutableInterval(-1000L, 1000L);
681: try {
682: StringConverter.INSTANCE.setInto(m, "/P1Y", null);
683: fail();
684: } catch (IllegalArgumentException ex) {
685: }
686: }
687:
688: public void testSetIntoIntervalEx_Object_Chronology5()
689: throws Exception {
690: MutableInterval m = new MutableInterval(-1000L, 1000L);
691: try {
692: StringConverter.INSTANCE.setInto(m, "P1Y/P2Y", null);
693: fail();
694: } catch (IllegalArgumentException ex) {
695: }
696: }
697:
698: //-----------------------------------------------------------------------
699: public void testToString() {
700: assertEquals("Converter[java.lang.String]",
701: StringConverter.INSTANCE.toString());
702: }
703:
704: }
|