KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > joda > time > convert > TestStringConverter


1 /*
2  * Copyright 2001-2005 Stephen Colebourne
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.joda.time.convert;
17
18 import java.lang.reflect.Constructor JavaDoc;
19 import java.lang.reflect.Field JavaDoc;
20 import java.lang.reflect.Modifier JavaDoc;
21 import java.util.Arrays JavaDoc;
22 import java.util.Locale JavaDoc;
23
24 import junit.framework.TestCase;
25 import junit.framework.TestSuite;
26
27 import org.joda.time.Chronology;
28 import org.joda.time.DateTime;
29 import org.joda.time.DateTimeZone;
30 import org.joda.time.MutableInterval;
31 import org.joda.time.MutablePeriod;
32 import org.joda.time.PeriodType;
33 import org.joda.time.TimeOfDay;
34 import org.joda.time.chrono.BuddhistChronology;
35 import org.joda.time.chrono.ISOChronology;
36 import org.joda.time.chrono.JulianChronology;
37
38 /**
39  * This class is a Junit unit test for StringConverter.
40  *
41  * @author Stephen Colebourne
42  */

43 public class TestStringConverter extends TestCase {
44
45     private static final DateTimeZone ONE_HOUR = DateTimeZone.forOffsetHours(1);
46     private static final DateTimeZone SIX = DateTimeZone.forOffsetHours(6);
47     private static final DateTimeZone SEVEN = DateTimeZone.forOffsetHours(7);
48     private static final DateTimeZone EIGHT = DateTimeZone.forOffsetHours(8);
49     private static final DateTimeZone UTC = DateTimeZone.UTC;
50     private static final DateTimeZone PARIS = DateTimeZone.forID("Europe/Paris");
51     private static final DateTimeZone LONDON = DateTimeZone.forID("Europe/London");
52     private static final Chronology ISO_EIGHT = ISOChronology.getInstance(EIGHT);
53     private static final Chronology ISO_PARIS = ISOChronology.getInstance(PARIS);
54     private static final Chronology ISO_LONDON = ISOChronology.getInstance(LONDON);
55     private static Chronology ISO;
56     private static Chronology JULIAN;
57     
58     private DateTimeZone zone = null;
59     private Locale JavaDoc locale = null;
60
61     public static void main(String JavaDoc[] args) {
62         junit.textui.TestRunner.run(suite());
63     }
64
65     public static TestSuite suite() {
66         return new TestSuite(TestStringConverter.class);
67     }
68
69     public TestStringConverter(String JavaDoc name) {
70         super(name);
71     }
72
73     protected void setUp() throws Exception JavaDoc {
74         zone = DateTimeZone.getDefault();
75         locale = Locale.getDefault();
76         DateTimeZone.setDefault(LONDON);
77         Locale.setDefault(Locale.UK);
78         
79         JULIAN = JulianChronology.getInstance();
80         ISO = ISOChronology.getInstance();
81     }
82
83     protected void tearDown() throws Exception JavaDoc {
84         DateTimeZone.setDefault(zone);
85         Locale.setDefault(locale);
86         zone = null;
87     }
88
89     //-----------------------------------------------------------------------
90
public void testSingleton() throws Exception JavaDoc {
91         Class JavaDoc cls = StringConverter.class;
92         assertEquals(false, Modifier.isPublic(cls.getModifiers()));
93         assertEquals(false, Modifier.isProtected(cls.getModifiers()));
94         assertEquals(false, Modifier.isPrivate(cls.getModifiers()));
95         
96         Constructor JavaDoc con = cls.getDeclaredConstructor((Class JavaDoc[]) null);
97         assertEquals(1, cls.getDeclaredConstructors().length);
98         assertEquals(true, Modifier.isProtected(con.getModifiers()));
99         
100         Field JavaDoc fld = cls.getDeclaredField("INSTANCE");
101         assertEquals(false, Modifier.isPublic(fld.getModifiers()));
102         assertEquals(false, Modifier.isProtected(fld.getModifiers()));
103         assertEquals(false, Modifier.isPrivate(fld.getModifiers()));
104     }
105
106     //-----------------------------------------------------------------------
107
public void testSupportedType() throws Exception JavaDoc {
108         assertEquals(String JavaDoc.class, StringConverter.INSTANCE.getSupportedType());
109     }
110
111     //-----------------------------------------------------------------------
112
public void testGetInstantMillis_Object() throws Exception JavaDoc {
113         DateTime dt = new DateTime(2004, 6, 9, 12, 24, 48, 501, EIGHT);
114         assertEquals(dt.getMillis(), StringConverter.INSTANCE.getInstantMillis("2004-06-09T12:24:48.501+08:00", ISO_EIGHT));
115         
116         dt = new DateTime(2004, 1, 1, 0, 0, 0, 0, EIGHT);
117         assertEquals(dt.getMillis(), StringConverter.INSTANCE.getInstantMillis("2004T+08:00", ISO_EIGHT));
118         
119         dt = new DateTime(2004, 6, 1, 0, 0, 0, 0, EIGHT);
120         assertEquals(dt.getMillis(), StringConverter.INSTANCE.getInstantMillis("2004-06T+08:00", ISO_EIGHT));
121         
122         dt = new DateTime(2004, 6, 9, 0, 0, 0, 0, EIGHT);
123         assertEquals(dt.getMillis(), StringConverter.INSTANCE.getInstantMillis("2004-06-09T+08:00", ISO_EIGHT));
124         
125         dt = new DateTime(2004, 6, 9, 0, 0, 0, 0, EIGHT);
126         assertEquals(dt.getMillis(), StringConverter.INSTANCE.getInstantMillis("2004-161T+08:00", ISO_EIGHT));
127         
128         dt = new DateTime(2004, 6, 9, 0, 0, 0, 0, EIGHT);
129         assertEquals(dt.getMillis(), StringConverter.INSTANCE.getInstantMillis("2004-W24-3T+08:00", ISO_EIGHT));
130         
131         dt = new DateTime(2004, 6, 7, 0, 0, 0, 0, EIGHT);
132         assertEquals(dt.getMillis(), StringConverter.INSTANCE.getInstantMillis("2004-W24T+08:00", ISO_EIGHT));
133         
134         dt = new DateTime(2004, 6, 9, 12, 0, 0, 0, EIGHT);
135         assertEquals(dt.getMillis(), StringConverter.INSTANCE.getInstantMillis("2004-06-09T12+08:00", ISO_EIGHT));
136         
137         dt = new DateTime(2004, 6, 9, 12, 24, 0, 0, EIGHT);
138         assertEquals(dt.getMillis(), StringConverter.INSTANCE.getInstantMillis("2004-06-09T12:24+08:00", ISO_EIGHT));
139         
140         dt = new DateTime(2004, 6, 9, 12, 24, 48, 0, EIGHT);
141         assertEquals(dt.getMillis(), StringConverter.INSTANCE.getInstantMillis("2004-06-09T12:24:48+08:00", ISO_EIGHT));
142         
143         dt = new DateTime(2004, 6, 9, 12, 30, 0, 0, EIGHT);
144         assertEquals(dt.getMillis(), StringConverter.INSTANCE.getInstantMillis("2004-06-09T12.5+08:00", ISO_EIGHT));
145         
146         dt = new DateTime(2004, 6, 9, 12, 24, 30, 0, EIGHT);
147         assertEquals(dt.getMillis(), StringConverter.INSTANCE.getInstantMillis("2004-06-09T12:24.5+08:00", ISO_EIGHT));
148         
149         dt = new DateTime(2004, 6, 9, 12, 24, 48, 500, EIGHT);
150         assertEquals(dt.getMillis(), StringConverter.INSTANCE.getInstantMillis("2004-06-09T12:24:48.5+08:00", ISO_EIGHT));
151         
152         dt = new DateTime(2004, 6, 9, 12, 24, 48, 501);
153         assertEquals(dt.getMillis(), StringConverter.INSTANCE.getInstantMillis("2004-06-09T12:24:48.501", ISO));
154     }
155
156     public void testGetInstantMillis_Object_Zone() throws Exception JavaDoc {
157         DateTime dt = new DateTime(2004, 6, 9, 12, 24, 48, 501, PARIS);
158         assertEquals(dt.getMillis(), StringConverter.INSTANCE.getInstantMillis("2004-06-09T12:24:48.501+02:00", ISO_PARIS));
159         
160         dt = new DateTime(2004, 6, 9, 12, 24, 48, 501, PARIS);
161         assertEquals(dt.getMillis(), StringConverter.INSTANCE.getInstantMillis("2004-06-09T12:24:48.501", ISO_PARIS));
162         
163         dt = new DateTime(2004, 6, 9, 12, 24, 48, 501, LONDON);
164         assertEquals(dt.getMillis(), StringConverter.INSTANCE.getInstantMillis("2004-06-09T12:24:48.501+01:00", ISO_LONDON));
165         
166         dt = new DateTime(2004, 6, 9, 12, 24, 48, 501, LONDON);
167         assertEquals(dt.getMillis(), StringConverter.INSTANCE.getInstantMillis("2004-06-09T12:24:48.501", ISO_LONDON));
168     }
169
170     public void testGetInstantMillis_Object_Chronology() throws Exception JavaDoc {
171         DateTime dt = new DateTime(2004, 6, 9, 12, 24, 48, 501, JulianChronology.getInstance(LONDON));
172         assertEquals(dt.getMillis(), StringConverter.INSTANCE.getInstantMillis("2004-06-09T12:24:48.501+01:00", JULIAN));
173     }
174
175     public void testGetInstantMillisInvalid() {
176         try {
177             StringConverter.INSTANCE.getInstantMillis("", (Chronology) null);
178             fail();
179         } catch (IllegalArgumentException JavaDoc ex) {}
180         try {
181             StringConverter.INSTANCE.getInstantMillis("X", (Chronology) null);
182             fail();
183         } catch (IllegalArgumentException JavaDoc ex) {}
184     }
185
186     //-----------------------------------------------------------------------
187
public void testGetChronology_Object_Zone() throws Exception JavaDoc {
188         assertEquals(ISOChronology.getInstance(PARIS), StringConverter.INSTANCE.getChronology("2004-06-09T12:24:48.501+01:00", PARIS));
189         assertEquals(ISOChronology.getInstance(PARIS), StringConverter.INSTANCE.getChronology("2004-06-09T12:24:48.501", PARIS));
190         assertEquals(ISOChronology.getInstance(LONDON), StringConverter.INSTANCE.getChronology("2004-06-09T12:24:48.501+01:00", (DateTimeZone) null));
191         assertEquals(ISOChronology.getInstance(LONDON), StringConverter.INSTANCE.getChronology("2004-06-09T12:24:48.501", (DateTimeZone) null));
192     }
193
194     public void testGetChronology_Object_Chronology() throws Exception JavaDoc {
195         assertEquals(JulianChronology.getInstance(LONDON), StringConverter.INSTANCE.getChronology("2004-06-09T12:24:48.501+01:00", JULIAN));
196         assertEquals(JulianChronology.getInstance(LONDON), StringConverter.INSTANCE.getChronology("2004-06-09T12:24:48.501", JULIAN));
197         assertEquals(ISOChronology.getInstance(LONDON), StringConverter.INSTANCE.getChronology("2004-06-09T12:24:48.501+01:00", (Chronology) null));
198         assertEquals(ISOChronology.getInstance(LONDON), StringConverter.INSTANCE.getChronology("2004-06-09T12:24:48.501", (Chronology) null));
199     }
200
201     //-----------------------------------------------------------------------
202
public void testGetPartialValues() throws Exception JavaDoc {
203         TimeOfDay tod = new TimeOfDay();
204         int[] expected = new int[] {3, 4, 5, 6};
205         int[] actual = StringConverter.INSTANCE.getPartialValues(tod, "T03:04:05.006", ISOChronology.getInstance());
206         assertEquals(true, Arrays.equals(expected, actual));
207     }
208
209     //-----------------------------------------------------------------------
210
public void testGetDateTime() throws Exception JavaDoc {
211         DateTime base = new DateTime(2004, 6, 9, 12, 24, 48, 501, PARIS);
212         DateTime test = new DateTime(base.toString(), PARIS);
213         assertEquals(base, test);
214     }
215
216     public void testGetDateTime1() throws Exception JavaDoc {
217         DateTime test = new DateTime("2004-06-09T12:24:48.501+01:00");
218         assertEquals(2004, test.getYear());
219         assertEquals(6, test.getMonthOfYear());
220         assertEquals(9, test.getDayOfMonth());
221         assertEquals(12, test.getHourOfDay());
222         assertEquals(24, test.getMinuteOfHour());
223         assertEquals(48, test.getSecondOfMinute());
224         assertEquals(501, test.getMillisOfSecond());
225         assertEquals(LONDON, test.getZone());
226     }
227
228     public void testGetDateTime2() throws Exception JavaDoc {
229         DateTime test = new DateTime("2004-06-09T12:24:48.501");
230         assertEquals(2004, test.getYear());
231         assertEquals(6, test.getMonthOfYear());
232         assertEquals(9, test.getDayOfMonth());
233         assertEquals(12, test.getHourOfDay());
234         assertEquals(24, test.getMinuteOfHour());
235         assertEquals(48, test.getSecondOfMinute());
236         assertEquals(501, test.getMillisOfSecond());
237         assertEquals(LONDON, test.getZone());
238     }
239
240     public void testGetDateTime3() throws Exception JavaDoc {
241         DateTime test = new DateTime("2004-06-09T12:24:48.501+02:00", PARIS);
242         assertEquals(2004, test.getYear());
243         assertEquals(6, test.getMonthOfYear());
244         assertEquals(9, test.getDayOfMonth());
245         assertEquals(12, test.getHourOfDay());
246         assertEquals(24, test.getMinuteOfHour());
247         assertEquals(48, test.getSecondOfMinute());
248         assertEquals(501, test.getMillisOfSecond());
249         assertEquals(PARIS, test.getZone());
250     }
251
252     public void testGetDateTime4() throws Exception JavaDoc {
253         DateTime test = new DateTime("2004-06-09T12:24:48.501", PARIS);
254         assertEquals(2004, test.getYear());
255         assertEquals(6, test.getMonthOfYear());
256         assertEquals(9, test.getDayOfMonth());
257         assertEquals(12, test.getHourOfDay());
258         assertEquals(24, test.getMinuteOfHour());
259         assertEquals(48, test.getSecondOfMinute());
260         assertEquals(501, test.getMillisOfSecond());
261         assertEquals(PARIS, test.getZone());
262     }
263
264     public void testGetDateTime5() throws Exception JavaDoc {
265         DateTime test = new DateTime("2004-06-09T12:24:48.501+02:00", JulianChronology.getInstance(PARIS));
266         assertEquals(2004, test.getYear());
267         assertEquals(6, test.getMonthOfYear());
268         assertEquals(9, test.getDayOfMonth());
269         assertEquals(12, test.getHourOfDay());
270         assertEquals(24, test.getMinuteOfHour());
271         assertEquals(48, test.getSecondOfMinute());
272         assertEquals(501, test.getMillisOfSecond());
273         assertEquals(PARIS, test.getZone());
274     }
275
276     public void testGetDateTime6() throws Exception JavaDoc {
277         DateTime test = new DateTime("2004-06-09T12:24:48.501", JulianChronology.getInstance(PARIS));
278         assertEquals(2004, test.getYear());
279         assertEquals(6, test.getMonthOfYear());
280         assertEquals(9, test.getDayOfMonth());
281         assertEquals(12, test.getHourOfDay());
282         assertEquals(24, test.getMinuteOfHour());
283         assertEquals(48, test.getSecondOfMinute());
284         assertEquals(501, test.getMillisOfSecond());
285         assertEquals(PARIS, test.getZone());
286     }
287
288     //-----------------------------------------------------------------------
289
public void testGetDurationMillis_Object1() throws Exception JavaDoc {
290         long millis = StringConverter.INSTANCE.getDurationMillis("PT12.345S");
291         assertEquals(12345, millis);
292         
293         millis = StringConverter.INSTANCE.getDurationMillis("pt12.345s");
294         assertEquals(12345, millis);
295         
296         millis = StringConverter.INSTANCE.getDurationMillis("pt12s");
297         assertEquals(12000, millis);
298         
299         millis = StringConverter.INSTANCE.getDurationMillis("pt12.s");
300         assertEquals(12000, millis);
301         
302         millis = StringConverter.INSTANCE.getDurationMillis("pt-12.32s");
303         assertEquals(-12320, millis);
304         
305         millis = StringConverter.INSTANCE.getDurationMillis("pt12.3456s");
306         assertEquals(12345, millis);
307     }
308
309     public void testGetDurationMillis_Object2() throws Exception JavaDoc {
310         try {
311             StringConverter.INSTANCE.getDurationMillis("P2Y6M9DXYZ");
312             fail();
313         } catch (IllegalArgumentException JavaDoc ex) {}
314         try {
315             StringConverter.INSTANCE.getDurationMillis("PTS");
316             fail();
317         } catch (IllegalArgumentException JavaDoc ex) {}
318         try {
319             StringConverter.INSTANCE.getDurationMillis("XT0S");
320             fail();
321         } catch (IllegalArgumentException JavaDoc ex) {}
322         try {
323             StringConverter.INSTANCE.getDurationMillis("PX0S");
324             fail();
325         } catch (IllegalArgumentException JavaDoc ex) {}
326         try {
327             StringConverter.INSTANCE.getDurationMillis("PT0X");
328             fail();
329         } catch (IllegalArgumentException JavaDoc ex) {}
330         try {
331             StringConverter.INSTANCE.getDurationMillis("PTXS");
332             fail();
333         } catch (IllegalArgumentException JavaDoc ex) {}
334         try {
335             StringConverter.INSTANCE.getDurationMillis("PT0.0.0S");
336             fail();
337         } catch (IllegalArgumentException JavaDoc ex) {}
338         try {
339             StringConverter.INSTANCE.getDurationMillis("PT0-00S");
340             fail();
341         } catch (IllegalArgumentException JavaDoc ex) {}
342     }
343
344     //-----------------------------------------------------------------------
345
public void testGetPeriodType_Object() throws Exception JavaDoc {
346         assertEquals(PeriodType.standard(),
347             StringConverter.INSTANCE.getPeriodType("P2Y6M9D"));
348     }
349
350     public void testSetIntoPeriod_Object1() throws Exception JavaDoc {
351         MutablePeriod m = new MutablePeriod(PeriodType.yearMonthDayTime());
352         StringConverter.INSTANCE.setInto(m, "P2Y6M9DT12H24M48S", null);
353         assertEquals(2, m.getYears());
354         assertEquals(6, m.getMonths());
355         assertEquals(9, m.getDays());
356         assertEquals(12, m.getHours());
357         assertEquals(24, m.getMinutes());
358         assertEquals(48, m.getSeconds());
359         assertEquals(0, m.getMillis());
360     }
361
362     public void testSetIntoPeriod_Object2() throws Exception JavaDoc {
363         MutablePeriod m = new MutablePeriod(PeriodType.yearWeekDayTime());
364         StringConverter.INSTANCE.setInto(m, "P2Y4W3DT12H24M48S", null);
365         assertEquals(2, m.getYears());
366         assertEquals(4, m.getWeeks());
367         assertEquals(3, m.getDays());
368         assertEquals(12, m.getHours());
369         assertEquals(24, m.getMinutes());
370         assertEquals(48, m.getSeconds());
371         assertEquals(0, m.getMillis());
372     }
373
374     public void testSetIntoPeriod_Object3() throws Exception JavaDoc {
375         MutablePeriod m = new MutablePeriod(PeriodType.yearWeekDayTime());
376         StringConverter.INSTANCE.setInto(m, "P2Y4W3DT12H24M48.034S", null);
377         assertEquals(2, m.getYears());
378         assertEquals(4, m.getWeeks());
379         assertEquals(3, m.getDays());
380         assertEquals(12, m.getHours());
381         assertEquals(24, m.getMinutes());
382         assertEquals(48, m.getSeconds());
383         assertEquals(34, m.getMillis());
384     }
385
386     public void testSetIntoPeriod_Object4() throws Exception JavaDoc {
387         MutablePeriod m = new MutablePeriod(PeriodType.yearWeekDayTime());
388         StringConverter.INSTANCE.setInto(m, "P2Y4W3DT12H24M.056S", null);
389         assertEquals(2, m.getYears());
390         assertEquals(4, m.getWeeks());
391         assertEquals(3, m.getDays());
392         assertEquals(12, m.getHours());
393         assertEquals(24, m.getMinutes());
394         assertEquals(0, m.getSeconds());
395         assertEquals(56, m.getMillis());
396     }
397
398     public void testSetIntoPeriod_Object5() throws Exception JavaDoc {
399         MutablePeriod m = new MutablePeriod(PeriodType.yearWeekDayTime());
400         StringConverter.INSTANCE.setInto(m, "P2Y4W3DT12H24M56.S", null);
401         assertEquals(2, m.getYears());
402         assertEquals(4, m.getWeeks());
403         assertEquals(3, m.getDays());
404         assertEquals(12, m.getHours());
405         assertEquals(24, m.getMinutes());
406         assertEquals(56, m.getSeconds());
407         assertEquals(0, m.getMillis());
408     }
409
410     public void testSetIntoPeriod_Object6() throws Exception JavaDoc {
411         MutablePeriod m = new MutablePeriod(PeriodType.yearWeekDayTime());
412         StringConverter.INSTANCE.setInto(m, "P2Y4W3DT12H24M56.1234567S", null);
413         assertEquals(2, m.getYears());
414         assertEquals(4, m.getWeeks());
415         assertEquals(3, m.getDays());
416         assertEquals(12, m.getHours());
417         assertEquals(24, m.getMinutes());
418         assertEquals(56, m.getSeconds());
419         assertEquals(123, m.getMillis());
420     }
421
422     public void testSetIntoPeriod_Object7() throws Exception JavaDoc {
423         MutablePeriod m = new MutablePeriod(1, 0, 1, 1, 1, 1, 1, 1, PeriodType.yearWeekDayTime());
424         StringConverter.INSTANCE.setInto(m, "P2Y4W3D", null);
425         assertEquals(2, m.getYears());
426         assertEquals(4, m.getWeeks());
427         assertEquals(3, m.getDays());
428         assertEquals(0, m.getHours());
429         assertEquals(0, m.getMinutes());
430         assertEquals(0, m.getSeconds());
431         assertEquals(0, m.getMillis());
432     }
433
434     public void testSetIntoPeriod_Object8() throws Exception JavaDoc {
435         MutablePeriod m = new MutablePeriod();
436         try {
437             StringConverter.INSTANCE.setInto(m, "", null);
438             fail();
439         } catch (IllegalArgumentException JavaDoc ex) {}
440         
441         try {
442             StringConverter.INSTANCE.setInto(m, "PXY", null);
443             fail();
444         } catch (IllegalArgumentException JavaDoc ex) {}
445         
446         try {
447             StringConverter.INSTANCE.setInto(m, "PT0SXY", null);
448             fail();
449         } catch (IllegalArgumentException JavaDoc ex) {}
450         try {
451             StringConverter.INSTANCE.setInto(m, "P2Y4W3DT12H24M48SX", null);
452             fail();
453         } catch (IllegalArgumentException JavaDoc ex) {}
454     }
455
456     //-----------------------------------------------------------------------
457
public void testIsReadableInterval_Object_Chronology() throws Exception JavaDoc {
458         assertEquals(false, StringConverter.INSTANCE.isReadableInterval("", null));
459     }
460
461     public void testSetIntoInterval_Object_Chronology1() throws Exception JavaDoc {
462         MutableInterval m = new MutableInterval(-1000L, 1000L);
463         StringConverter.INSTANCE.setInto(m, "2004-06-09/P1Y2M", null);
464         assertEquals(new DateTime(2004, 6, 9, 0, 0, 0, 0), m.getStart());
465         assertEquals(new DateTime(2005, 8, 9, 0, 0, 0, 0), m.getEnd());
466         assertEquals(ISOChronology.getInstance(), m.getChronology());
467     }
468
469     public void testSetIntoInterval_Object_Chronology2() throws Exception JavaDoc {
470         MutableInterval m = new MutableInterval(-1000L, 1000L);
471         StringConverter.INSTANCE.setInto(m, "P1Y2M/2004-06-09", null);
472         assertEquals(new DateTime(2003, 4, 9, 0, 0, 0, 0), m.getStart());
473         assertEquals(new DateTime(2004, 6, 9, 0, 0, 0, 0), m.getEnd());
474         assertEquals(ISOChronology.getInstance(), m.getChronology());
475     }
476
477     public void testSetIntoInterval_Object_Chronology3() throws Exception JavaDoc {
478         MutableInterval m = new MutableInterval(-1000L, 1000L);
479         StringConverter.INSTANCE.setInto(m, "2003-08-09/2004-06-09", null);
480         assertEquals(new DateTime(2003, 8, 9, 0, 0, 0, 0), m.getStart());
481         assertEquals(new DateTime(2004, 6, 9, 0, 0, 0, 0), m.getEnd());
482         assertEquals(ISOChronology.getInstance(), m.getChronology());
483     }
484
485     public void testSetIntoInterval_Object_Chronology4() throws Exception JavaDoc {
486         MutableInterval m = new MutableInterval(-1000L, 1000L);
487         StringConverter.INSTANCE.setInto(m, "2004-06-09T+06:00/P1Y2M", null);
488         assertEquals(new DateTime(2004, 6, 9, 0, 0, 0, 0, SIX).withChronology(null), m.getStart());
489         assertEquals(new DateTime(2005, 8, 9, 0, 0, 0, 0, SIX).withChronology(null), m.getEnd());
490         assertEquals(ISOChronology.getInstance(), m.getChronology());
491     }
492
493     public void testSetIntoInterval_Object_Chronology5() throws Exception JavaDoc {
494         MutableInterval m = new MutableInterval(-1000L, 1000L);
495         StringConverter.INSTANCE.setInto(m, "P1Y2M/2004-06-09T+06:00", null);
496         assertEquals(new DateTime(2003, 4, 9, 0, 0, 0, 0, SIX).withChronology(null), m.getStart());
497         assertEquals(new DateTime(2004, 6, 9, 0, 0, 0, 0, SIX).withChronology(null), m.getEnd());
498         assertEquals(ISOChronology.getInstance(), m.getChronology());
499     }
500
501     public void testSetIntoInterval_Object_Chronology6() throws Exception JavaDoc {
502         MutableInterval m = new MutableInterval(-1000L, 1000L);
503         StringConverter.INSTANCE.setInto(m, "2003-08-09T+06:00/2004-06-09T+07:00", null);
504         assertEquals(new DateTime(2003, 8, 9, 0, 0, 0, 0, SIX).withChronology(null), m.getStart());
505         assertEquals(new DateTime(2004, 6, 9, 0, 0, 0, 0, SEVEN).withChronology(null), m.getEnd());
506         assertEquals(ISOChronology.getInstance(), m.getChronology());
507     }
508
509     public void testSetIntoInterval_Object_Chronology7() throws Exception JavaDoc {
510         MutableInterval m = new MutableInterval(-1000L, 1000L);
511         StringConverter.INSTANCE.setInto(m, "2003-08-09/2004-06-09", BuddhistChronology.getInstance());
512         assertEquals(new DateTime(2003, 8, 9, 0, 0, 0, 0, BuddhistChronology.getInstance()), m.getStart());
513         assertEquals(new DateTime(2004, 6, 9, 0, 0, 0, 0, BuddhistChronology.getInstance()), m.getEnd());
514         assertEquals(BuddhistChronology.getInstance(), m.getChronology());
515     }
516
517     public void testSetIntoInterval_Object_Chronology8() throws Exception JavaDoc {
518         MutableInterval m = new MutableInterval(-1000L, 1000L);
519         StringConverter.INSTANCE.setInto(m, "2003-08-09T+06:00/2004-06-09T+07:00", BuddhistChronology.getInstance(EIGHT));
520         assertEquals(new DateTime(2003, 8, 9, 0, 0, 0, 0, BuddhistChronology.getInstance(SIX)).withZone(EIGHT), m.getStart());
521         assertEquals(new DateTime(2004, 6, 9, 0, 0, 0, 0, BuddhistChronology.getInstance(SEVEN)).withZone(EIGHT), m.getEnd());
522         assertEquals(BuddhistChronology.getInstance(EIGHT), m.getChronology());
523     }
524
525     public void testSetIntoIntervalEx_Object_Chronology1() throws Exception JavaDoc {
526         MutableInterval m = new MutableInterval(-1000L, 1000L);
527         try {
528             StringConverter.INSTANCE.setInto(m, "", null);
529             fail();
530         } catch (IllegalArgumentException JavaDoc ex) {}
531     }
532
533     public void testSetIntoIntervalEx_Object_Chronology2() throws Exception JavaDoc {
534         MutableInterval m = new MutableInterval(-1000L, 1000L);
535         try {
536             StringConverter.INSTANCE.setInto(m, "/", null);
537             fail();
538         } catch (IllegalArgumentException JavaDoc ex) {}
539     }
540
541     public void testSetIntoIntervalEx_Object_Chronology3() throws Exception JavaDoc {
542         MutableInterval m = new MutableInterval(-1000L, 1000L);
543         try {
544             StringConverter.INSTANCE.setInto(m, "P1Y/", null);
545             fail();
546         } catch (IllegalArgumentException JavaDoc ex) {}
547     }
548
549     public void testSetIntoIntervalEx_Object_Chronology4() throws Exception JavaDoc {
550         MutableInterval m = new MutableInterval(-1000L, 1000L);
551         try {
552             StringConverter.INSTANCE.setInto(m, "/P1Y", null);
553             fail();
554         } catch (IllegalArgumentException JavaDoc ex) {}
555     }
556
557     public void testSetIntoIntervalEx_Object_Chronology5() throws Exception JavaDoc {
558         MutableInterval m = new MutableInterval(-1000L, 1000L);
559         try {
560             StringConverter.INSTANCE.setInto(m, "P1Y/P2Y", null);
561             fail();
562         } catch (IllegalArgumentException JavaDoc ex) {}
563     }
564
565     //-----------------------------------------------------------------------
566
public void testToString() {
567         assertEquals("Converter[java.lang.String]", StringConverter.INSTANCE.toString());
568     }
569
570 }
571
Popular Tags