< prev index next >

test/java/time/test/java/time/format/TestTextPrinter.java

Print this page


   1 /*
   2  * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


 196 
 197             {QUARTER_OF_YEAR, TextStyle.SHORT, 1, "Q1"},
 198             {QUARTER_OF_YEAR, TextStyle.SHORT, 2, "Q2"},
 199             {QUARTER_OF_YEAR, TextStyle.SHORT, 3, "Q3"},
 200             {QUARTER_OF_YEAR, TextStyle.SHORT, 4, "Q4"},
 201 
 202             {QUARTER_OF_YEAR, TextStyle.NARROW, 1, "1"},
 203             {QUARTER_OF_YEAR, TextStyle.NARROW, 2, "2"},
 204             {QUARTER_OF_YEAR, TextStyle.NARROW, 3, "3"},
 205             {QUARTER_OF_YEAR, TextStyle.NARROW, 4, "4"},
 206        };
 207     }
 208 
 209     @DataProvider(name="print_DayOfWeekData")
 210     Object[][] providerDayOfWeekData() {
 211         return new Object[][] {
 212             // Locale, pattern, expected text, input DayOfWeek
 213             {Locale.US, "e",  "1",  DayOfWeek.SUNDAY},
 214             {Locale.US, "ee", "01", DayOfWeek.SUNDAY},
 215             {Locale.US, "c",  "1",  DayOfWeek.SUNDAY},
 216 
 217             {Locale.UK, "e",  "1",  DayOfWeek.MONDAY},
 218             {Locale.UK, "ee", "01", DayOfWeek.MONDAY},
 219             {Locale.UK, "c",  "1",  DayOfWeek.MONDAY},
 220         };
 221     }
 222 
 223     @DataProvider(name="print_JapaneseChronology")
 224     Object[][] provider_japaneseEra() {
 225        return new Object[][] {
 226             {ERA,           TextStyle.FULL, 2, "Heisei"}, // Note: CLDR doesn't define "wide" Japanese era names.
 227             {ERA,           TextStyle.SHORT, 2, "Heisei"},
 228             {ERA,           TextStyle.NARROW, 2, "H"},
 229        };
 230     };
 231 
 232     // Test data is dependent on localized resources.
 233     @DataProvider(name="print_standalone")
 234     Object[][] provider_StandaloneNames() {
 235         return new Object[][] {
 236             // standalone names for 2013-01-01 (Tue)
 237             // Locale, TemporalField, TextStyle, expected text
 238             {RUSSIAN, MONTH_OF_YEAR, TextStyle.FULL_STANDALONE,  "\u044f\u043d\u0432\u0430\u0440\u044c"},
 239             {RUSSIAN, MONTH_OF_YEAR, TextStyle.SHORT_STANDALONE, "\u044f\u043d\u0432."},
 240             {FINNISH, DAY_OF_WEEK,   TextStyle.FULL_STANDALONE,  "tiistai"},
 241             {FINNISH, DAY_OF_WEEK,   TextStyle.SHORT_STANDALONE, "ti"},
 242         };
 243     }
 244 
 245     @Test(dataProvider="print")
 246     public void test_format(TemporalField field, TextStyle style, int value, String expected) throws Exception {
 247         getFormatter(field, style).formatTo(new MockFieldValue(field, value), buf);
 248         assertEquals(buf.toString(), expected);
 249     }
 250 
 251     @Test(dataProvider="print_DayOfWeekData")
 252     public void test_formatDayOfWeek(Locale locale, String pattern, String expected, DayOfWeek dayOfWeek) {
 253         DateTimeFormatter formatter = getPatternFormatter(pattern).withLocale(locale);
 254         String text = formatter.format(dayOfWeek);
 255         assertEquals(text, expected);
 256     }
 257 
 258     @Test(dataProvider="print_JapaneseChronology")
 259     public void test_formatJapaneseEra(TemporalField field, TextStyle style, int value, String expected) throws Exception {
 260         LocalDate ld = LocalDate.of(2013, 1, 31);
 261         getFormatter(field, style).withChronology(JapaneseChronology.INSTANCE).formatTo(ld, buf);
 262         assertEquals(buf.toString(), expected);
 263     }
 264 
 265     @Test(dataProvider="print_standalone")
 266     public void test_standaloneNames(Locale locale, TemporalField field, TextStyle style, String expected) {
 267         getFormatter(field, style).withLocale(locale).formatTo(LocalDate.of(2013, 1, 1), buf);
 268         assertEquals(buf.toString(), expected);
 269     }
 270 
 271     //-----------------------------------------------------------------------
 272     public void test_print_french_long() throws Exception {
 273         getFormatter(MONTH_OF_YEAR, TextStyle.FULL).withLocale(Locale.FRENCH).formatTo(LocalDate.of(2012, 1, 1), buf);
 274         assertEquals(buf.toString(), "janvier");
 275     }
 276 
 277     public void test_print_french_short() throws Exception {
 278         getFormatter(MONTH_OF_YEAR, TextStyle.SHORT).withLocale(Locale.FRENCH).formatTo(LocalDate.of(2012, 1, 1), buf);
 279         assertEquals(buf.toString(), "janv.");
 280     }
 281 
 282     //-----------------------------------------------------------------------
 283     public void test_toString1() throws Exception {
 284         assertEquals(getFormatter(MONTH_OF_YEAR, TextStyle.FULL).toString(), "Text(MonthOfYear)");
 285     }
 286 
 287     public void test_toString2() throws Exception {
 288         assertEquals(getFormatter(MONTH_OF_YEAR, TextStyle.SHORT).toString(), "Text(MonthOfYear,SHORT)");
 289     }
 290 
 291 }
   1 /*
   2  * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


 196 
 197             {QUARTER_OF_YEAR, TextStyle.SHORT, 1, "Q1"},
 198             {QUARTER_OF_YEAR, TextStyle.SHORT, 2, "Q2"},
 199             {QUARTER_OF_YEAR, TextStyle.SHORT, 3, "Q3"},
 200             {QUARTER_OF_YEAR, TextStyle.SHORT, 4, "Q4"},
 201 
 202             {QUARTER_OF_YEAR, TextStyle.NARROW, 1, "1"},
 203             {QUARTER_OF_YEAR, TextStyle.NARROW, 2, "2"},
 204             {QUARTER_OF_YEAR, TextStyle.NARROW, 3, "3"},
 205             {QUARTER_OF_YEAR, TextStyle.NARROW, 4, "4"},
 206        };
 207     }
 208 
 209     @DataProvider(name="print_DayOfWeekData")
 210     Object[][] providerDayOfWeekData() {
 211         return new Object[][] {
 212             // Locale, pattern, expected text, input DayOfWeek
 213             {Locale.US, "e",  "1",  DayOfWeek.SUNDAY},
 214             {Locale.US, "ee", "01", DayOfWeek.SUNDAY},
 215             {Locale.US, "c",  "1",  DayOfWeek.SUNDAY},




 216         };
 217     }
 218 
 219     @DataProvider(name="print_JapaneseChronology")
 220     Object[][] provider_japaneseEra() {
 221        return new Object[][] {
 222             {ERA,           TextStyle.FULL, 2, "Heisei"}, // Note: CLDR doesn't define "wide" Japanese era names.
 223             {ERA,           TextStyle.SHORT, 2, "Heisei"},
 224             {ERA,           TextStyle.NARROW, 2, "H"},
 225        };
 226     };
 227 













 228     @Test(dataProvider="print")
 229     public void test_format(TemporalField field, TextStyle style, int value, String expected) throws Exception {
 230         getFormatter(field, style).formatTo(new MockFieldValue(field, value), buf);
 231         assertEquals(buf.toString(), expected);
 232     }
 233 
 234     @Test(dataProvider="print_DayOfWeekData")
 235     public void test_formatDayOfWeek(Locale locale, String pattern, String expected, DayOfWeek dayOfWeek) {
 236         DateTimeFormatter formatter = getPatternFormatter(pattern).withLocale(locale);
 237         String text = formatter.format(dayOfWeek);
 238         assertEquals(text, expected);
 239     }
 240 
 241     @Test(dataProvider="print_JapaneseChronology")
 242     public void test_formatJapaneseEra(TemporalField field, TextStyle style, int value, String expected) throws Exception {
 243         LocalDate ld = LocalDate.of(2013, 1, 31);
 244         getFormatter(field, style).withChronology(JapaneseChronology.INSTANCE).formatTo(ld, buf);
 245         assertEquals(buf.toString(), expected);

















 246     }
 247 
 248     //-----------------------------------------------------------------------
 249     public void test_toString1() throws Exception {
 250         assertEquals(getFormatter(MONTH_OF_YEAR, TextStyle.FULL).toString(), "Text(MonthOfYear)");
 251     }
 252 
 253     public void test_toString2() throws Exception {
 254         assertEquals(getFormatter(MONTH_OF_YEAR, TextStyle.SHORT).toString(), "Text(MonthOfYear,SHORT)");
 255     }
 256 
 257 }
< prev index next >