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.forOffsetHours(1);
046        private static final DateTimeZone SIX = DateTimeZone.forOffsetHours(6);
047        private static final DateTimeZone SEVEN = DateTimeZone.forOffsetHours(7);
048        private static final DateTimeZone EIGHT = DateTimeZone.forOffsetHours(8);
049        private static final DateTimeZone UTC = DateTimeZone.UTC;
050        private static final DateTimeZone PARIS = DateTimeZone.forID("Europe/Paris");
051        private static final DateTimeZone LONDON = DateTimeZone.forID("Europe/London");
052        private static final Chronology ISO_EIGHT = ISOChronology.getInstance(EIGHT);
053        private static final Chronology ISO_PARIS = ISOChronology.getInstance(PARIS);
054        private static final Chronology ISO_LONDON = ISOChronology.getInstance(LONDON);
055        private static Chronology ISO;
056        private static Chronology JULIAN;
057        
058        private DateTimeZone zone = null;
059        private Locale locale = null;
060    
061        public static void main(String[] args) {
062            junit.textui.TestRunner.run(suite());
063        }
064    
065        public static TestSuite suite() {
066            return new TestSuite(TestStringConverter.class);
067        }
068    
069        public TestStringConverter(String name) {
070            super(name);
071        }
072    
073        protected void setUp() throws Exception {
074            zone = DateTimeZone.getDefault();
075            locale = Locale.getDefault();
076            DateTimeZone.setDefault(LONDON);
077            Locale.setDefault(Locale.UK);
078            
079            JULIAN = JulianChronology.getInstance();
080            ISO = ISOChronology.getInstance();
081        }
082    
083        protected void tearDown() throws Exception {
084            DateTimeZone.setDefault(zone);
085            Locale.setDefault(locale);
086            zone = null;
087        }
088    
089        //-----------------------------------------------------------------------
090        public void testSingleton() throws Exception {
091            Class cls = StringConverter.class;
092            assertEquals(false, Modifier.isPublic(cls.getModifiers()));
093            assertEquals(false, Modifier.isProtected(cls.getModifiers()));
094            assertEquals(false, Modifier.isPrivate(cls.getModifiers()));
095            
096            Constructor con = cls.getDeclaredConstructor((Class[]) null);
097            assertEquals(1, cls.getDeclaredConstructors().length);
098            assertEquals(true, Modifier.isProtected(con.getModifiers()));
099            
100            Field 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 {
108            assertEquals(String.class, StringConverter.INSTANCE.getSupportedType());
109        }
110    
111        //-----------------------------------------------------------------------
112        public void testGetInstantMillis_Object() throws Exception {
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 {
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 {
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 ex) {}
180            try {
181                StringConverter.INSTANCE.getInstantMillis("X", (Chronology) null);
182                fail();
183            } catch (IllegalArgumentException ex) {}
184        }
185    
186        //-----------------------------------------------------------------------
187        public void testGetChronology_Object_Zone() throws Exception {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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("pt-0.32s");
306            assertEquals(-320, millis);
307    
308            millis = StringConverter.INSTANCE.getDurationMillis("pt-0.0s");
309            assertEquals(0, millis);
310    
311            millis = StringConverter.INSTANCE.getDurationMillis("pt0.0s");
312            assertEquals(0, millis);
313    
314            millis = StringConverter.INSTANCE.getDurationMillis("pt12.3456s");
315            assertEquals(12345, millis);
316        }
317    
318        public void testGetDurationMillis_Object2() throws Exception {
319            try {
320                StringConverter.INSTANCE.getDurationMillis("P2Y6M9DXYZ");
321                fail();
322            } catch (IllegalArgumentException ex) {}
323            try {
324                StringConverter.INSTANCE.getDurationMillis("PTS");
325                fail();
326            } catch (IllegalArgumentException ex) {}
327            try {
328                StringConverter.INSTANCE.getDurationMillis("XT0S");
329                fail();
330            } catch (IllegalArgumentException ex) {}
331            try {
332                StringConverter.INSTANCE.getDurationMillis("PX0S");
333                fail();
334            } catch (IllegalArgumentException ex) {}
335            try {
336                StringConverter.INSTANCE.getDurationMillis("PT0X");
337                fail();
338            } catch (IllegalArgumentException ex) {}
339            try {
340                StringConverter.INSTANCE.getDurationMillis("PTXS");
341                fail();
342            } catch (IllegalArgumentException ex) {}
343            try {
344                StringConverter.INSTANCE.getDurationMillis("PT0.0.0S");
345                fail();
346            } catch (IllegalArgumentException ex) {}
347            try {
348                StringConverter.INSTANCE.getDurationMillis("PT0-00S");
349                fail();
350            } catch (IllegalArgumentException ex) {}
351            try {
352                StringConverter.INSTANCE.getDurationMillis("PT-.001S");
353                fail();
354            } catch (IllegalArgumentException ex) {}
355        }
356    
357        //-----------------------------------------------------------------------
358        public void testGetPeriodType_Object() throws Exception {
359            assertEquals(PeriodType.standard(),
360                StringConverter.INSTANCE.getPeriodType("P2Y6M9D"));
361        }
362    
363        public void testSetIntoPeriod_Object1() throws Exception {
364            MutablePeriod m = new MutablePeriod(PeriodType.yearMonthDayTime());
365            StringConverter.INSTANCE.setInto(m, "P2Y6M9DT12H24M48S", null);
366            assertEquals(2, m.getYears());
367            assertEquals(6, m.getMonths());
368            assertEquals(9, m.getDays());
369            assertEquals(12, m.getHours());
370            assertEquals(24, m.getMinutes());
371            assertEquals(48, m.getSeconds());
372            assertEquals(0, m.getMillis());
373        }
374    
375        public void testSetIntoPeriod_Object2() throws Exception {
376            MutablePeriod m = new MutablePeriod(PeriodType.yearWeekDayTime());
377            StringConverter.INSTANCE.setInto(m, "P2Y4W3DT12H24M48S", null);
378            assertEquals(2, m.getYears());
379            assertEquals(4, m.getWeeks());
380            assertEquals(3, m.getDays());
381            assertEquals(12, m.getHours());
382            assertEquals(24, m.getMinutes());
383            assertEquals(48, m.getSeconds());
384            assertEquals(0, m.getMillis());
385        }        
386    
387        public void testSetIntoPeriod_Object3() throws Exception {
388            MutablePeriod m = new MutablePeriod(PeriodType.yearWeekDayTime());
389            StringConverter.INSTANCE.setInto(m, "P2Y4W3DT12H24M48.034S", null);
390            assertEquals(2, m.getYears());
391            assertEquals(4, m.getWeeks());
392            assertEquals(3, m.getDays());
393            assertEquals(12, m.getHours());
394            assertEquals(24, m.getMinutes());
395            assertEquals(48, m.getSeconds());
396            assertEquals(34, m.getMillis());
397        }        
398    
399        public void testSetIntoPeriod_Object4() throws Exception {
400            MutablePeriod m = new MutablePeriod(PeriodType.yearWeekDayTime());
401            StringConverter.INSTANCE.setInto(m, "P2Y4W3DT12H24M.056S", null);
402            assertEquals(2, m.getYears());
403            assertEquals(4, m.getWeeks());
404            assertEquals(3, m.getDays());
405            assertEquals(12, m.getHours());
406            assertEquals(24, m.getMinutes());
407            assertEquals(0, m.getSeconds());
408            assertEquals(56, m.getMillis());
409        }        
410    
411        public void testSetIntoPeriod_Object5() throws Exception {
412            MutablePeriod m = new MutablePeriod(PeriodType.yearWeekDayTime());
413            StringConverter.INSTANCE.setInto(m, "P2Y4W3DT12H24M56.S", null);
414            assertEquals(2, m.getYears());
415            assertEquals(4, m.getWeeks());
416            assertEquals(3, m.getDays());
417            assertEquals(12, m.getHours());
418            assertEquals(24, m.getMinutes());
419            assertEquals(56, m.getSeconds());
420            assertEquals(0, m.getMillis());
421        }        
422    
423        public void testSetIntoPeriod_Object6() throws Exception {
424            MutablePeriod m = new MutablePeriod(PeriodType.yearWeekDayTime());
425            StringConverter.INSTANCE.setInto(m, "P2Y4W3DT12H24M56.1234567S", null);
426            assertEquals(2, m.getYears());
427            assertEquals(4, m.getWeeks());
428            assertEquals(3, m.getDays());
429            assertEquals(12, m.getHours());
430            assertEquals(24, m.getMinutes());
431            assertEquals(56, m.getSeconds());
432            assertEquals(123, m.getMillis());
433        }        
434    
435        public void testSetIntoPeriod_Object7() throws Exception {
436            MutablePeriod m = new MutablePeriod(1, 0, 1, 1, 1, 1, 1, 1, PeriodType.yearWeekDayTime());
437            StringConverter.INSTANCE.setInto(m, "P2Y4W3D", null);
438            assertEquals(2, m.getYears());
439            assertEquals(4, m.getWeeks());
440            assertEquals(3, m.getDays());
441            assertEquals(0, m.getHours());
442            assertEquals(0, m.getMinutes());
443            assertEquals(0, m.getSeconds());
444            assertEquals(0, m.getMillis());
445        }        
446    
447        public void testSetIntoPeriod_Object8() throws Exception {
448            MutablePeriod m = new MutablePeriod();
449            try {
450                StringConverter.INSTANCE.setInto(m, "", null);
451                fail();
452            } catch (IllegalArgumentException ex) {}
453            
454            try {
455                StringConverter.INSTANCE.setInto(m, "PXY", null);
456                fail();
457            } catch (IllegalArgumentException ex) {}
458            
459            try {
460                StringConverter.INSTANCE.setInto(m, "PT0SXY", null);
461                fail();
462            } catch (IllegalArgumentException ex) {}
463            try {
464                StringConverter.INSTANCE.setInto(m, "P2Y4W3DT12H24M48SX", null);
465                fail();
466            } catch (IllegalArgumentException ex) {}
467        }
468    
469        //-----------------------------------------------------------------------
470        public void testIsReadableInterval_Object_Chronology() throws Exception {
471            assertEquals(false, StringConverter.INSTANCE.isReadableInterval("", null));
472        }
473    
474        public void testSetIntoInterval_Object_Chronology1() throws Exception {
475            MutableInterval m = new MutableInterval(-1000L, 1000L);
476            StringConverter.INSTANCE.setInto(m, "2004-06-09/P1Y2M", null);
477            assertEquals(new DateTime(2004, 6, 9, 0, 0, 0, 0), m.getStart());
478            assertEquals(new DateTime(2005, 8, 9, 0, 0, 0, 0), m.getEnd());
479            assertEquals(ISOChronology.getInstance(), m.getChronology());
480        }
481    
482        public void testSetIntoInterval_Object_Chronology2() throws Exception {
483            MutableInterval m = new MutableInterval(-1000L, 1000L);
484            StringConverter.INSTANCE.setInto(m, "P1Y2M/2004-06-09", null);
485            assertEquals(new DateTime(2003, 4, 9, 0, 0, 0, 0), m.getStart());
486            assertEquals(new DateTime(2004, 6, 9, 0, 0, 0, 0), m.getEnd());
487            assertEquals(ISOChronology.getInstance(), m.getChronology());
488        }
489    
490        public void testSetIntoInterval_Object_Chronology3() throws Exception {
491            MutableInterval m = new MutableInterval(-1000L, 1000L);
492            StringConverter.INSTANCE.setInto(m, "2003-08-09/2004-06-09", null);
493            assertEquals(new DateTime(2003, 8, 9, 0, 0, 0, 0), m.getStart());
494            assertEquals(new DateTime(2004, 6, 9, 0, 0, 0, 0), m.getEnd());
495            assertEquals(ISOChronology.getInstance(), m.getChronology());
496        }
497    
498        public void testSetIntoInterval_Object_Chronology4() throws Exception {
499            MutableInterval m = new MutableInterval(-1000L, 1000L);
500            StringConverter.INSTANCE.setInto(m, "2004-06-09T+06:00/P1Y2M", null);
501            assertEquals(new DateTime(2004, 6, 9, 0, 0, 0, 0, SIX).withChronology(null), m.getStart());
502            assertEquals(new DateTime(2005, 8, 9, 0, 0, 0, 0, SIX).withChronology(null), m.getEnd());
503            assertEquals(ISOChronology.getInstance(), m.getChronology());
504        }
505    
506        public void testSetIntoInterval_Object_Chronology5() throws Exception {
507            MutableInterval m = new MutableInterval(-1000L, 1000L);
508            StringConverter.INSTANCE.setInto(m, "P1Y2M/2004-06-09T+06:00", null);
509            assertEquals(new DateTime(2003, 4, 9, 0, 0, 0, 0, SIX).withChronology(null), m.getStart());
510            assertEquals(new DateTime(2004, 6, 9, 0, 0, 0, 0, SIX).withChronology(null), m.getEnd());
511            assertEquals(ISOChronology.getInstance(), m.getChronology());
512        }
513    
514        public void testSetIntoInterval_Object_Chronology6() throws Exception {
515            MutableInterval m = new MutableInterval(-1000L, 1000L);
516            StringConverter.INSTANCE.setInto(m, "2003-08-09T+06:00/2004-06-09T+07:00", null);
517            assertEquals(new DateTime(2003, 8, 9, 0, 0, 0, 0, SIX).withChronology(null), m.getStart());
518            assertEquals(new DateTime(2004, 6, 9, 0, 0, 0, 0, SEVEN).withChronology(null), m.getEnd());
519            assertEquals(ISOChronology.getInstance(), m.getChronology());
520        }
521    
522        public void testSetIntoInterval_Object_Chronology7() throws Exception {
523            MutableInterval m = new MutableInterval(-1000L, 1000L);
524            StringConverter.INSTANCE.setInto(m, "2003-08-09/2004-06-09", BuddhistChronology.getInstance());
525            assertEquals(new DateTime(2003, 8, 9, 0, 0, 0, 0, BuddhistChronology.getInstance()), m.getStart());
526            assertEquals(new DateTime(2004, 6, 9, 0, 0, 0, 0, BuddhistChronology.getInstance()), m.getEnd());
527            assertEquals(BuddhistChronology.getInstance(), m.getChronology());
528        }
529    
530        public void testSetIntoInterval_Object_Chronology8() throws Exception {
531            MutableInterval m = new MutableInterval(-1000L, 1000L);
532            StringConverter.INSTANCE.setInto(m, "2003-08-09T+06:00/2004-06-09T+07:00", BuddhistChronology.getInstance(EIGHT));
533            assertEquals(new DateTime(2003, 8, 9, 0, 0, 0, 0, BuddhistChronology.getInstance(SIX)).withZone(EIGHT), m.getStart());
534            assertEquals(new DateTime(2004, 6, 9, 0, 0, 0, 0, BuddhistChronology.getInstance(SEVEN)).withZone(EIGHT), m.getEnd());
535            assertEquals(BuddhistChronology.getInstance(EIGHT), m.getChronology());
536        }
537    
538        public void testSetIntoIntervalEx_Object_Chronology1() throws Exception {
539            MutableInterval m = new MutableInterval(-1000L, 1000L);
540            try {
541                StringConverter.INSTANCE.setInto(m, "", null);
542                fail();
543            } catch (IllegalArgumentException ex) {}
544        }
545    
546        public void testSetIntoIntervalEx_Object_Chronology2() throws Exception {
547            MutableInterval m = new MutableInterval(-1000L, 1000L);
548            try {
549                StringConverter.INSTANCE.setInto(m, "/", null);
550                fail();
551            } catch (IllegalArgumentException ex) {}
552        }
553    
554        public void testSetIntoIntervalEx_Object_Chronology3() throws Exception {
555            MutableInterval m = new MutableInterval(-1000L, 1000L);
556            try {
557                StringConverter.INSTANCE.setInto(m, "P1Y/", null);
558                fail();
559            } catch (IllegalArgumentException ex) {}
560        }
561    
562        public void testSetIntoIntervalEx_Object_Chronology4() throws Exception {
563            MutableInterval m = new MutableInterval(-1000L, 1000L);
564            try {
565                StringConverter.INSTANCE.setInto(m, "/P1Y", null);
566                fail();
567            } catch (IllegalArgumentException ex) {}
568        }
569    
570        public void testSetIntoIntervalEx_Object_Chronology5() throws Exception {
571            MutableInterval m = new MutableInterval(-1000L, 1000L);
572            try {
573                StringConverter.INSTANCE.setInto(m, "P1Y/P2Y", null);
574                fail();
575            } catch (IllegalArgumentException ex) {}
576        }
577    
578        //-----------------------------------------------------------------------
579        public void testToString() {
580            assertEquals("Converter[java.lang.String]", StringConverter.INSTANCE.toString());
581        }
582    
583    }