OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / libcore / luni / src / test / java / libcore / java / text / OldSimpleDateFormatTest.java
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 package libcore.java.text;
18
19 import java.text.DateFormat;
20 import java.text.DateFormatSymbols;
21 import java.text.FieldPosition;
22 import java.text.ParsePosition;
23 import java.text.SimpleDateFormat;
24 import java.util.Calendar;
25 import java.util.Date;
26 import java.util.GregorianCalendar;
27 import java.util.Locale;
28 import java.util.SimpleTimeZone;
29 import java.util.TimeZone;
30
31 public class OldSimpleDateFormatTest extends junit.framework.TestCase {
32
33     SimpleDateFormat format = new SimpleDateFormat("", Locale.ENGLISH);
34
35     SimpleDateFormat pFormat = new SimpleDateFormat("", Locale.ENGLISH);
36
37     class FormatTester {
38         boolean testsFailed = false;
39
40         public void test(String pattern, Calendar cal, String expected, int field) {
41             StringBuffer buffer = new StringBuffer();
42             FieldPosition position = new FieldPosition(field);
43             format.applyPattern(pattern);
44             format.format(cal.getTime(), buffer, position);
45             String result = buffer.toString();
46             if (!result.equals(expected)) {
47                 System.out.println("Wrong format: \"" + pattern
48                                 + "\" expected: " + expected + " result: "
49                                 + result);
50                 testsFailed = true;
51             }
52         }
53
54         public void parse(String pattern, String input, Date expected, int start, int end) {
55             pFormat.applyPattern(pattern);
56             ParsePosition position = new ParsePosition(start);
57             Date result = pFormat.parse(input, position);
58             assertTrue("Wrong result: " + pattern + " input: " + input
59                     + " expected: " + expected + " result: " + result, expected
60                     .equals(result));
61             assertTrue("Wrong end position: " + pattern + " input: " + input,
62                     position.getIndex() == end);
63         }
64
65         public void verifyFormatTimezone(String timeZoneId, String expected1,
66                 String expected2, Date date) {
67             format.setTimeZone(SimpleTimeZone.getTimeZone(timeZoneId));
68             format.applyPattern("z, zzzz");
69             assertEquals("Test z for TimeZone : " + timeZoneId, expected1,
70                     format.format(date));
71
72             format.applyPattern("Z, ZZZZ");
73             assertEquals("Test Z for TimeZone : " + timeZoneId, expected2,
74                     format.format(date));
75         }
76     }
77
78     /**
79      * @tests java.text.SimpleDateFormat#SimpleDateFormat(java.lang.String,
80      *        java.text.DateFormatSymbols)
81      */
82     public void test_ConstructorLjava_lang_StringLjava_text_DateFormatSymbols() {
83         // Test for method java.text.SimpleDateFormat(java.lang.String,
84         // java.text.DateFormatSymbols)
85         DateFormatSymbols symbols = new DateFormatSymbols(Locale.ENGLISH);
86         symbols.setEras(new String[] { "Before", "After" });
87         SimpleDateFormat f2 = new SimpleDateFormat("y'y'yy", symbols);
88         assertTrue("Wrong class", f2.getClass() == SimpleDateFormat.class);
89         assertEquals("Wrong pattern", "y'y'yy", f2.toPattern());
90         assertTrue("Wrong symbols", f2.getDateFormatSymbols().equals(symbols));
91         assertTrue("Doesn't work",
92                 f2.format(new Date()).getClass() == String.class);
93
94         try {
95             new SimpleDateFormat(null, symbols);
96             fail("NullPointerException was not thrown.");
97         } catch(NullPointerException npe) {
98             //expected
99         }
100
101         try {
102             new SimpleDateFormat("eee", symbols);
103             fail("IllegalArgumentException was not thrown.");
104         } catch(IllegalArgumentException iae) {
105             //expected
106         }
107     }
108
109     public void test_ConstructorLjava_lang_StringLjava_util_Locale() {
110         // Test for method java.text.SimpleDateFormat(java.lang.String,
111         // java.util.Locale)
112         SimpleDateFormat f2 = new SimpleDateFormat("'yyyy' MM yy",
113                 Locale.GERMAN);
114         assertTrue("Wrong class", f2.getClass() == SimpleDateFormat.class);
115         assertEquals("Wrong pattern", "'yyyy' MM yy", f2.toPattern());
116         assertTrue("Wrong symbols", f2.getDateFormatSymbols().equals(
117                 new DateFormatSymbols(Locale.GERMAN)));
118         assertTrue("Doesn't work",
119                 f2.format(new Date()).getClass() == String.class);
120
121         try {
122             new SimpleDateFormat(null, Locale.GERMAN);
123             fail("NullPointerException was not thrown.");
124         } catch(NullPointerException npe) {
125             //expected
126         }
127         try {
128             new SimpleDateFormat("eee", Locale.GERMAN);
129             fail("IllegalArgumentException was not thrown.");
130         } catch(IllegalArgumentException iae) {
131             //expected
132         }
133     }
134
135     public void test_applyLocalizedPatternLjava_lang_String() {
136         // Test for method void
137         // java.text.SimpleDateFormat.applyLocalizedPattern(java.lang.String)
138         SimpleDateFormat f2 = new SimpleDateFormat("y", new Locale("de", "CH"));
139         // BEGIN android-removed
140         // This test doesn't work like this. The cause lies inside of icu
141         // that doesn't support localized pattern characters anymore. So this
142         // test fails because the pattern template contains characters that are
143         // not part of the standard pattern returned for every locale.
144         // The default pattern characters are: GyMdkHmsSEDFwWahKzZ
145         //
146         // f2.applyLocalizedPattern("GuMtkHmsSEDFwWahKz");
147         // String pattern = f2.toPattern();
148         // assertTrue("Wrong pattern: " + pattern, pattern
149         //         .equals("GyMdkHmsSEDFwWahKz"));
150         //
151         // test the new "Z" pattern char
152         // f2 = new SimpleDateFormat("y", new Locale("de", "CH"));
153         // f2.applyLocalizedPattern("G u M t Z");
154         // pattern = f2.toPattern();
155         // assertTrue("Wrong pattern: " + pattern, pattern.equals("G y M d Z"));
156         // END android-removed
157
158         // test invalid patterns
159         try {
160             f2.applyLocalizedPattern("b");
161             fail("Expected IllegalArgumentException for pattern with invalid pattern letter: b");
162         } catch (IllegalArgumentException e) {
163         }
164
165         try {
166             // ICU only! this fails on the RI
167             f2.applyLocalizedPattern("u");
168             fail("Expected IllegalArgumentException for pattern with invalid pattern letter: u");
169         } catch (IllegalArgumentException e) {
170         }
171
172         try {
173             f2.applyLocalizedPattern("a '");
174             fail("Expected IllegalArgumentException for pattern with unterminated quote: a '");
175         } catch (IllegalArgumentException e) {
176         }
177
178         try {
179             f2.applyLocalizedPattern(null);
180             fail("Expected NullPointerException for null pattern");
181         } catch (NullPointerException e) {
182         }
183     }
184
185     /**
186      * @tests java.text.SimpleDateFormat#applyPattern(java.lang.String)
187      */
188     public void test_applyPatternLjava_lang_String() {
189         // Test for method void
190         // java.text.SimpleDateFormat.applyPattern(java.lang.String)
191         SimpleDateFormat f2 = new SimpleDateFormat("y", new Locale("de", "CH"));
192         // BEGIN android-changed
193         f2.applyPattern("GyMdkHmsSEDFwWahKzZ");
194         assertEquals("Wrong pattern", "GyMdkHmsSEDFwWahKzZ", f2.toPattern());
195         // END android-changed
196
197         // test invalid patterns
198         try {
199             f2.applyPattern("u");
200             fail("Expected IllegalArgumentException for pattern with invalid patter letter: u");
201         } catch (IllegalArgumentException e) {
202         }
203     }
204
205     public void test_hashCode() {
206         SimpleDateFormat format = (SimpleDateFormat) DateFormat.getInstance();
207         SimpleDateFormat clone = (SimpleDateFormat) format.clone();
208         assertTrue("clone has not equal hash code", clone.hashCode() == format
209                 .hashCode());
210         format.format(new Date());
211         assertTrue("clone has not equal hash code after format", clone
212                 .hashCode() == format.hashCode());
213         DateFormatSymbols symbols = new DateFormatSymbols(Locale.ENGLISH);
214         symbols.setEras(new String[] { "Before", "After" });
215         SimpleDateFormat format2 = new SimpleDateFormat("y'y'yy", symbols);
216         assertFalse("objects has equal hash code", format2.hashCode() == format
217                 .hashCode());
218     }
219
220     public void test_formatLjava_util_DateLjava_lang_StringBufferLjava_text_FieldPosition() {
221         FormatTester test = new FormatTester();
222
223         Calendar cal = new GregorianCalendar(1999, Calendar.JUNE, 2, 15, 3, 6);
224         test.test(" G", cal, " AD", DateFormat.ERA_FIELD);
225         test.test(" GG", cal, " AD", DateFormat.ERA_FIELD);
226         test.test(" GGG", cal, " AD", DateFormat.ERA_FIELD);
227         test.test(" G", new GregorianCalendar(-1999, Calendar.JUNE, 2), " BC",
228                 DateFormat.ERA_FIELD);
229
230         test.test(" M", cal, " 6", DateFormat.MONTH_FIELD);
231         test.test(" M", new GregorianCalendar(1999, Calendar.NOVEMBER, 2),
232                 " 11", DateFormat.MONTH_FIELD);
233         test.test(" MM", cal, " 06", DateFormat.MONTH_FIELD);
234         test.test(" MMM", cal, " Jun", DateFormat.MONTH_FIELD);
235         test.test(" MMMM", cal, " June", DateFormat.MONTH_FIELD);
236         test.test(" MMMMM", cal, " June", DateFormat.MONTH_FIELD);
237
238         test.test(" d", cal, " 2", DateFormat.DATE_FIELD);
239         test.test(" d", new GregorianCalendar(1999, Calendar.NOVEMBER, 12),
240                 " 12", DateFormat.DATE_FIELD);
241         test.test(" dd", cal, " 02", DateFormat.DATE_FIELD);
242         test.test(" dddd", cal, " 0002", DateFormat.DATE_FIELD);
243
244         test.test(" h", cal, " 3", DateFormat.HOUR1_FIELD);
245         test.test(" h", new GregorianCalendar(1999, Calendar.NOVEMBER, 12),
246                 " 12", DateFormat.HOUR1_FIELD);
247         test.test(" hh", cal, " 03", DateFormat.HOUR1_FIELD);
248         test.test(" hhhh", cal, " 0003", DateFormat.HOUR1_FIELD);
249
250         test.test(" H", cal, " 15", DateFormat.HOUR_OF_DAY0_FIELD);
251         test.test(" H",
252                 new GregorianCalendar(1999, Calendar.NOVEMBER, 12, 4, 0), " 4",
253                 DateFormat.HOUR_OF_DAY0_FIELD);
254         test.test(" H", new GregorianCalendar(1999, Calendar.NOVEMBER, 12, 12,
255                 0), " 12", DateFormat.HOUR_OF_DAY0_FIELD);
256         test.test(" H", new GregorianCalendar(1999, Calendar.NOVEMBER, 12),
257                 " 0", DateFormat.HOUR_OF_DAY0_FIELD);
258         test.test(" HH", cal, " 15", DateFormat.HOUR_OF_DAY0_FIELD);
259         test.test(" HHHH", cal, " 0015", DateFormat.HOUR_OF_DAY0_FIELD);
260
261         test.test(" m", cal, " 3", DateFormat.MINUTE_FIELD);
262         test.test(" m", new GregorianCalendar(1999, Calendar.NOVEMBER, 12, 4,
263                 47), " 47", DateFormat.MINUTE_FIELD);
264         test.test(" mm", cal, " 03", DateFormat.MINUTE_FIELD);
265         test.test(" mmmm", cal, " 0003", DateFormat.MINUTE_FIELD);
266
267         test.test(" s", cal, " 6", DateFormat.SECOND_FIELD);
268         test.test(" s", new GregorianCalendar(1999, Calendar.NOVEMBER, 12, 4,
269                 47, 13), " 13", DateFormat.SECOND_FIELD);
270         test.test(" ss", cal, " 06", DateFormat.SECOND_FIELD);
271         test.test(" ssss", cal, " 0006", DateFormat.SECOND_FIELD);
272
273         test.test(" S", cal, " 0", DateFormat.MILLISECOND_FIELD);
274         Calendar temp = new GregorianCalendar();
275         temp.set(Calendar.MILLISECOND, 961);
276
277         test.test(" SS", temp, " 961", DateFormat.MILLISECOND_FIELD);
278         test.test(" SSSS", cal, " 0000", DateFormat.MILLISECOND_FIELD);
279
280         test.test(" SS", cal, " 00", DateFormat.MILLISECOND_FIELD);
281
282         test.test(" E", cal, " Wed", DateFormat.DAY_OF_WEEK_FIELD);
283         test.test(" EE", cal, " Wed", DateFormat.DAY_OF_WEEK_FIELD);
284         test.test(" EEE", cal, " Wed", DateFormat.DAY_OF_WEEK_FIELD);
285         test.test(" EEEE", cal, " Wednesday", DateFormat.DAY_OF_WEEK_FIELD);
286         test.test(" EEEEE", cal, " Wednesday", DateFormat.DAY_OF_WEEK_FIELD);
287
288         test.test(" D", cal, " 153", DateFormat.DAY_OF_YEAR_FIELD);
289         test.test(" DD", cal, " 153", DateFormat.DAY_OF_YEAR_FIELD);
290         test.test(" DDDD", cal, " 0153", DateFormat.DAY_OF_YEAR_FIELD);
291
292         test.test(" F", cal, " 1", DateFormat.DAY_OF_WEEK_IN_MONTH_FIELD);
293         test.test(" F", new GregorianCalendar(1999, Calendar.NOVEMBER, 14),
294                 " 2", DateFormat.DAY_OF_WEEK_IN_MONTH_FIELD);
295         test.test(" FF", cal, " 01", DateFormat.DAY_OF_WEEK_IN_MONTH_FIELD);
296         test.test(" FFFF", cal, " 0001", DateFormat.DAY_OF_WEEK_IN_MONTH_FIELD);
297
298         test.test(" a", cal, " PM", DateFormat.AM_PM_FIELD);
299         test.test(" a", new GregorianCalendar(1999, Calendar.NOVEMBER, 14),
300                 " AM", DateFormat.AM_PM_FIELD);
301         test.test(" a", new GregorianCalendar(1999, Calendar.NOVEMBER, 14, 12,
302                 0), " PM", DateFormat.AM_PM_FIELD);
303         test.test(" aa", cal, " PM", DateFormat.AM_PM_FIELD);
304         test.test(" aaa", cal, " PM", DateFormat.AM_PM_FIELD);
305         test.test(" aaaa", cal, " PM", DateFormat.AM_PM_FIELD);
306         test.test(" aaaaa", cal, " PM", DateFormat.AM_PM_FIELD);
307
308         test.test(" k", cal, " 15", DateFormat.HOUR_OF_DAY1_FIELD);
309         test.test(" k",
310                 new GregorianCalendar(1999, Calendar.NOVEMBER, 12, 4, 0), " 4",
311                 DateFormat.HOUR_OF_DAY1_FIELD);
312         test.test(" k", new GregorianCalendar(1999, Calendar.NOVEMBER, 12, 12,
313                 0), " 12", DateFormat.HOUR_OF_DAY1_FIELD);
314         test.test(" k", new GregorianCalendar(1999, Calendar.NOVEMBER, 12),
315                 " 24", DateFormat.HOUR_OF_DAY1_FIELD);
316         test.test(" kk", cal, " 15", DateFormat.HOUR_OF_DAY1_FIELD);
317         test.test(" kkkk", cal, " 0015", DateFormat.HOUR_OF_DAY1_FIELD);
318
319         test.test(" K", cal, " 3", DateFormat.HOUR0_FIELD);
320         test.test(" K", new GregorianCalendar(1999, Calendar.NOVEMBER, 12),
321                 " 0", DateFormat.HOUR0_FIELD);
322         test.test(" KK", cal, " 03", DateFormat.HOUR0_FIELD);
323         test.test(" KKKK", cal, " 0003", DateFormat.HOUR0_FIELD);
324
325         format.applyPattern("'Mkz''':.@5");
326         assertEquals("Wrong output", "Mkz':.@5", format.format(new Date()));
327
328         //assertTrue("Tests failed", !test.testsFailed());
329
330         // Test invalid args to format.
331         SimpleDateFormat dateFormat = new SimpleDateFormat();
332         try {
333             dateFormat.format(null, new StringBuffer(), new FieldPosition(1));
334             fail("Expected test to throw NPE.");
335         } catch (NullPointerException ex) {
336             // expected
337         } catch (Throwable ex) {
338             fail("Expected test to throw NPE, not " + ex.getClass().getName());
339         }
340
341         assertFalse(test.testsFailed);
342     }
343
344     /**
345      * This test assumes Unicode behavior where 'y' and 'yyy' don't truncate,
346      * which means that it will fail on the RI.
347      */
348     public void testFormattingYear() {
349         FormatTester test = new FormatTester();
350
351         Calendar cal = new GregorianCalendar(1999, Calendar.JUNE, 2, 15, 3, 6);
352         test.test(" y", cal, " 1999", DateFormat.YEAR_FIELD);
353         test.test(" yy", cal, " 99", DateFormat.YEAR_FIELD);
354         test.test(" yy", new GregorianCalendar(2001, Calendar.JUNE, 2), " 01",
355                 DateFormat.YEAR_FIELD);
356         test.test(" yy", new GregorianCalendar(2000, Calendar.JUNE, 2), " 00",
357                 DateFormat.YEAR_FIELD);
358         test.test(" yyy", new GregorianCalendar(2000, Calendar.JUNE, 2), " 2000",
359                 DateFormat.YEAR_FIELD);
360         test.test(" yyy", cal, " 1999", DateFormat.YEAR_FIELD);
361         test.test(" yyyy", cal, " 1999", DateFormat.YEAR_FIELD);
362         test.test(" yyyyy", cal, " 01999", DateFormat.YEAR_FIELD);
363
364         assertFalse(test.testsFailed);
365     }
366
367     public void testFormattingWeekOfYear() {
368         FormatTester test = new FormatTester();
369         Calendar cal = new GregorianCalendar(1999, Calendar.JUNE, 2, 15, 3, 6);
370         cal.setMinimalDaysInFirstWeek(1);
371         cal.setFirstDayOfWeek(1);
372
373         test.test(" w", cal, " 23", DateFormat.WEEK_OF_YEAR_FIELD);
374         test.test(" ww", cal, " 23", DateFormat.WEEK_OF_YEAR_FIELD);
375         test.test(" wwww", cal, " 0023", DateFormat.WEEK_OF_YEAR_FIELD);
376
377         test.test(" W", cal, " 1", DateFormat.WEEK_OF_MONTH_FIELD);
378         test.test(" W", new GregorianCalendar(1999, Calendar.NOVEMBER, 14),
379                 " 3", DateFormat.WEEK_OF_MONTH_FIELD);
380         test.test(" WW", cal, " 01", DateFormat.WEEK_OF_MONTH_FIELD);
381         test.test(" WWWW", cal, " 0001", DateFormat.WEEK_OF_MONTH_FIELD);
382
383         assertFalse(test.testsFailed);
384     }
385
386     public void testFormattingTimezones() {
387         FormatTester test = new FormatTester();
388         Calendar cal = new GregorianCalendar(1999, Calendar.JUNE, 2, 15, 3, 6);
389
390         format.setTimeZone(new SimpleTimeZone(60000, "ONE MINUTE"));
391         test.test(" z", cal, " GMT+00:01", DateFormat.TIMEZONE_FIELD);
392         test.test(" zzzz", cal, " GMT+00:01", DateFormat.TIMEZONE_FIELD);
393         format.setTimeZone(new SimpleTimeZone(5400000, "ONE HOUR, THIRTY"));
394         test.test(" z", cal, " GMT+01:30", DateFormat.TIMEZONE_FIELD);
395         format.setTimeZone(new SimpleTimeZone(-5400000, "NEG ONE HOUR, THIRTY"));
396         test.test(" z", cal, " GMT-01:30", DateFormat.TIMEZONE_FIELD);
397
398         format.setTimeZone(TimeZone.getTimeZone("America/New_York"));
399         test.test(" z", cal, " EDT", DateFormat.TIMEZONE_FIELD);
400         Calendar temp2 = new GregorianCalendar(1999, Calendar.JANUARY, 12);
401         test.test(" z", temp2, " EST", DateFormat.TIMEZONE_FIELD);
402         test.test(" zz", cal, " EDT", DateFormat.TIMEZONE_FIELD);
403         test.test(" zzz", cal, " EDT", DateFormat.TIMEZONE_FIELD);
404         test.test(" zzzz", cal, " Eastern Daylight Time", DateFormat.TIMEZONE_FIELD);
405         test.test(" zzzz", temp2, " Eastern Standard Time", DateFormat.TIMEZONE_FIELD);
406         test.test(" zzzzz", cal, " Eastern Daylight Time", DateFormat.TIMEZONE_FIELD);
407
408         assertFalse(test.testsFailed);
409     }
410
411     public void testDefaultMinimalDaysInFirstWeek() {
412         Locale.setDefault(Locale.US);
413         assertEquals(1, new GregorianCalendar().getMinimalDaysInFirstWeek());
414         assertEquals(1, new GregorianCalendar().getFirstDayOfWeek());
415     }
416
417     /**
418      * @tests java.text.SimpleDateFormat#format(java.util.Date)
419      */
420     public void test_timeZoneFormatting() {
421         // tests specific to formatting of timezones
422         Date summerDate = new GregorianCalendar(1999, Calendar.JUNE, 2, 15, 3, 6).getTime();
423         Date winterDate = new GregorianCalendar(1999, Calendar.JANUARY, 12).getTime();
424
425         FormatTester test = new FormatTester();
426         test.verifyFormatTimezone("GMT-7", "GMT-07:00, GMT-07:00", "-0700, -0700", summerDate);
427         test.verifyFormatTimezone("GMT-7", "GMT-07:00, GMT-07:00", "-0700, -0700", winterDate);
428
429         test.verifyFormatTimezone("GMT+14", "GMT+14:00, GMT+14:00", "+1400, +1400", summerDate);
430         test.verifyFormatTimezone("GMT+14", "GMT+14:00, GMT+14:00", "+1400, +1400", winterDate);
431
432         test.verifyFormatTimezone("America/Los_Angeles", "PDT, Pacific Daylight Time",
433                 "-0700, -0700", summerDate);
434         test.verifyFormatTimezone("America/Los_Angeles", "PST, Pacific Standard Time",
435                 "-0800, -0800", winterDate);
436
437         // this fails on the RI!
438         test.verifyFormatTimezone("America/Detroit", "EDT, Eastern Daylight Time",
439                 "-0400, -0400", summerDate);
440         test.verifyFormatTimezone("America/Detroit", "EST, Eastern Standard Time",
441                 "-0500, -0500", winterDate);
442
443         assertFalse(test.testsFailed);
444     }
445
446     public void test_parseLjava_lang_StringLjava_text_ParsePosition_2() {
447         try {
448             format.parse("240 11 2002 March", null);
449             fail("ParsePosition is null: NullPointerException was not thrown.");
450         } catch(NullPointerException pe) {
451             //expected
452         }
453
454         try {
455             format.parse(null, new ParsePosition(0));
456             fail("String is null: NullPointerException was not thrown.");
457         } catch(NullPointerException pe) {
458             //expected
459         }
460     }
461
462     public void test_setDateFormatSymbolsLjava_text_DateFormatSymbols() {
463         // Test for method void
464         // java.text.SimpleDateFormat.setDateFormatSymbols(java.text.DateFormatSymbols)
465         SimpleDateFormat f1 = new SimpleDateFormat("a");
466         DateFormatSymbols symbols = new DateFormatSymbols();
467         symbols.setAmPmStrings(new String[] { "morning", "night" });
468         f1.setDateFormatSymbols(symbols);
469         DateFormatSymbols newSym = f1.getDateFormatSymbols();
470         assertTrue("Set incorrectly", newSym.equals(symbols));
471         assertTrue("Not a clone", f1.getDateFormatSymbols() != symbols);
472         String result = f1.format(new GregorianCalendar(1999, Calendar.JUNE,
473                 12, 3, 0).getTime());
474         assertEquals("Incorrect symbols used", "morning", result);
475         symbols.setEras(new String[] { "before", "after" });
476         assertTrue("Identical symbols", !f1.getDateFormatSymbols().equals(
477                 symbols));
478
479         try {
480             f1.setDateFormatSymbols(null);
481             fail("NullPointerException was not thrown.");
482         } catch(NullPointerException npe) {
483             //expected
484         }
485     }
486
487     public void test_toLocalizedPattern() {
488         // BEGIN android-changed
489         // Test for method java.lang.String
490         // java.text.SimpleDateFormat.toLocalizedPattern()
491         SimpleDateFormat f2 = new SimpleDateFormat("GyMdkHmsSEDFwWahKzZ",
492                 new Locale("de", "CH"));
493         String pattern = f2.toLocalizedPattern();
494         // the default localized pattern characters are the same for all locales
495         // since icu has dropped support for this. the default pattern characters
496         // are these: GyMdkHmsSEDFwWahKz
497         // ICU only! this fails on the RI
498         assertTrue("Wrong pattern: " + pattern, pattern
499                 .equals("GyMdkHmsSEDFwWahKzZ"));
500
501
502         // test the new "Z" pattern char
503         f2 = new SimpleDateFormat("G y M d Z", new Locale("de", "CH"));
504         pattern = f2.toLocalizedPattern();
505         // assertTrue("Wrong pattern: " + pattern, pattern.equals("G u M t Z"));
506         assertTrue("Wrong pattern: " + pattern, pattern.equals("G y M d Z"));
507         // END android-changed
508     }
509
510     public void test_toPattern() {
511         String pattern = "yyyy mm dd";
512         SimpleDateFormat f = new SimpleDateFormat(pattern);
513         assertEquals("Wrong pattern: " + pattern, pattern, f.toPattern());
514
515         pattern = "GyMdkHmsSEDFwWahKz";
516         f = new SimpleDateFormat("GyMdkHmsSEDFwWahKz", new Locale("de", "CH"));
517         assertTrue("Wrong pattern: " + pattern, f.toPattern().equals(pattern));
518
519         pattern = "G y M d Z";
520         f = new SimpleDateFormat(pattern, new Locale("de", "CH"));
521         pattern = f.toPattern();
522         assertTrue("Wrong pattern: " + pattern, f.toPattern().equals(pattern));
523     }
524 }