< prev index next >

test/jdk/java/time/tck/java/time/format/TCKLocalizedPrinterParser.java

Print this page
8247706: Unintentional use of new Date(year...) with absolute year
Reviewed-by: naoto, rriggs, scolebourne
   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  */


 163                 {LocalTime.of(11, 30), FormatStyle.MEDIUM, DateFormat.MEDIUM, Locale.FRANCE},
 164                 {LocalTime.of(11, 30), FormatStyle.MEDIUM, DateFormat.MEDIUM, Locale.JAPAN},
 165 
 166                 // these localized patterns include "z" which isn't available from LocalTime
 167 //                {LocalTime.of(11, 30), FormatStyle.LONG, DateFormat.LONG, Locale.UK},
 168 //                {LocalTime.of(11, 30), FormatStyle.LONG, DateFormat.LONG, Locale.US},
 169 //                {LocalTime.of(11, 30), FormatStyle.LONG, DateFormat.LONG, Locale.FRANCE},
 170 //                {LocalTime.of(11, 30), FormatStyle.LONG, DateFormat.LONG, Locale.JAPAN},
 171 //
 172 //                {LocalTime.of(11, 30), FormatStyle.FULL, DateFormat.FULL, Locale.UK},
 173 //                {LocalTime.of(11, 30), FormatStyle.FULL, DateFormat.FULL, Locale.US},
 174 //                {LocalTime.of(11, 30), FormatStyle.FULL, DateFormat.FULL, Locale.FRANCE},
 175 //                {LocalTime.of(11, 30), FormatStyle.FULL, DateFormat.FULL, Locale.JAPAN},
 176         };
 177     }
 178 
 179     @SuppressWarnings("deprecation")
 180     @Test(dataProvider="time")
 181     public void test_time_print(LocalTime time, FormatStyle timeStyle, int timeStyleOld, Locale locale) {
 182         DateFormat old = DateFormat.getTimeInstance(timeStyleOld, locale);
 183         Date oldDate = new Date(1970, 0, 0, time.getHour(), time.getMinute(), time.getSecond());
 184         String text = old.format(oldDate);
 185 
 186         DateTimeFormatter f = builder.appendLocalized(null, timeStyle).toFormatter(locale);
 187         String formatted = f.format(time);
 188         assertEquals(formatted, text);
 189     }
 190 
 191     @SuppressWarnings("deprecation")
 192     @Test(dataProvider="time")
 193     public void test_time_parse(LocalTime time, FormatStyle timeStyle, int timeStyleOld, Locale locale) {
 194         DateFormat old = DateFormat.getTimeInstance(timeStyleOld, locale);
 195         Date oldDate = new Date(1970, 0, 0, time.getHour(), time.getMinute(), time.getSecond());
 196         String text = old.format(oldDate);
 197 
 198         DateTimeFormatter f = builder.appendLocalized(null, timeStyle).toFormatter(locale);
 199         TemporalAccessor parsed = f.parse(text, pos);
 200         assertEquals(pos.getIndex(), text.length());
 201         assertEquals(pos.getErrorIndex(), -1);
 202         assertEquals(LocalTime.from(parsed), time);
 203     }
 204 
 205 }
   1 /*
   2  * Copyright (c) 2012, 2020, 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  */


 163                 {LocalTime.of(11, 30), FormatStyle.MEDIUM, DateFormat.MEDIUM, Locale.FRANCE},
 164                 {LocalTime.of(11, 30), FormatStyle.MEDIUM, DateFormat.MEDIUM, Locale.JAPAN},
 165 
 166                 // these localized patterns include "z" which isn't available from LocalTime
 167 //                {LocalTime.of(11, 30), FormatStyle.LONG, DateFormat.LONG, Locale.UK},
 168 //                {LocalTime.of(11, 30), FormatStyle.LONG, DateFormat.LONG, Locale.US},
 169 //                {LocalTime.of(11, 30), FormatStyle.LONG, DateFormat.LONG, Locale.FRANCE},
 170 //                {LocalTime.of(11, 30), FormatStyle.LONG, DateFormat.LONG, Locale.JAPAN},
 171 //
 172 //                {LocalTime.of(11, 30), FormatStyle.FULL, DateFormat.FULL, Locale.UK},
 173 //                {LocalTime.of(11, 30), FormatStyle.FULL, DateFormat.FULL, Locale.US},
 174 //                {LocalTime.of(11, 30), FormatStyle.FULL, DateFormat.FULL, Locale.FRANCE},
 175 //                {LocalTime.of(11, 30), FormatStyle.FULL, DateFormat.FULL, Locale.JAPAN},
 176         };
 177     }
 178 
 179     @SuppressWarnings("deprecation")
 180     @Test(dataProvider="time")
 181     public void test_time_print(LocalTime time, FormatStyle timeStyle, int timeStyleOld, Locale locale) {
 182         DateFormat old = DateFormat.getTimeInstance(timeStyleOld, locale);
 183         Date oldDate = new Date(1970 - 1900, 0, 0, time.getHour(), time.getMinute(), time.getSecond());
 184         String text = old.format(oldDate);
 185 
 186         DateTimeFormatter f = builder.appendLocalized(null, timeStyle).toFormatter(locale);
 187         String formatted = f.format(time);
 188         assertEquals(formatted, text);
 189     }
 190 
 191     @SuppressWarnings("deprecation")
 192     @Test(dataProvider="time")
 193     public void test_time_parse(LocalTime time, FormatStyle timeStyle, int timeStyleOld, Locale locale) {
 194         DateFormat old = DateFormat.getTimeInstance(timeStyleOld, locale);
 195         Date oldDate = new Date(1970 - 1900, 0, 0, time.getHour(), time.getMinute(), time.getSecond());
 196         String text = old.format(oldDate);
 197 
 198         DateTimeFormatter f = builder.appendLocalized(null, timeStyle).toFormatter(locale);
 199         TemporalAccessor parsed = f.parse(text, pos);
 200         assertEquals(pos.getIndex(), text.length());
 201         assertEquals(pos.getErrorIndex(), -1);
 202         assertEquals(LocalTime.from(parsed), time);
 203     }
 204 
 205 }
< prev index next >