Path: blob/master/test/jdk/java/text/Format/DateFormat/Bug8139572.java
41152 views
/*1* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 813957226* @summary SimpleDateFormat parse month stand-alone format bug27* @compile -encoding utf-8 Bug8139572.java28* @modules jdk.localedata29* @run main Bug813957230*/31import java.text.ParseException;32import java.text.SimpleDateFormat;33import java.util.Calendar;34import java.util.Date;35import java.util.GregorianCalendar;36import java.util.Locale;3738public class Bug8139572 {3940private static final Locale RUSSIAN = new Locale("ru");41private static final Date SEPT12 = new GregorianCalendar(2015, Calendar.SEPTEMBER, 12).getTime();4243private static final String[] PATTERNS = {44"L",45"dd L",46"dd L yy",47"dd L yyyy",48"LL",49"dd LL",50"dd LL yy",51"dd LL yyyy",52"LLL",53"dd LLL",54"dd LLL yy",55"dd LLL yyyy",56"LLLL",57"dd LLLL",58"dd LLLL yy",59"dd LLLL yyyy"60};6162private static final String[] APPLIED = {63"9",64"12 09",65"12 09 15",66"12 09 2015",67"09",68"12 09",69"12 09 15",70"12 09 2015",71"сентября",72"12 сентября",73"12 сентября 15",74"12 сентября 2015",75"сентября",76"12 сентября",77"12 сентября 15",78"12 сентября 2015"79};8081private static final String[] EXPECTED = {82"9",83"12 9",84"12 9 15",85"12 9 2015",86"09",87"12 09",88"12 09 15",89"12 09 2015",90"сент.",91"12 сент.",92"12 сент. 15",93"12 сент. 2015",94"сентябрь",95"12 сентябрь",96"12 сентябрь 15",97"12 сентябрь 2015"98};99100public static void main(String[] args) throws ParseException {101102for (int i = 0; i < PATTERNS.length; i++) {103SimpleDateFormat fmt = new SimpleDateFormat(PATTERNS[i], RUSSIAN);104Date standAloneDate = fmt.parse(APPLIED[i]);105String str = fmt.format(standAloneDate);106if (!EXPECTED[i].equals(str)) {107throw new RuntimeException("bad result: got '" + str + "', expected '" + EXPECTED[i] + "'");108}109}110111SimpleDateFormat fmt = new SimpleDateFormat("", RUSSIAN);112for (int j = 0; j < PATTERNS.length; j++) {113fmt.applyPattern(PATTERNS[j]);114String str = fmt.format(SEPT12);115if (!EXPECTED[j].equals(str)) {116throw new RuntimeException("bad result: got '" + str + "', expected '" + EXPECTED[j] + "'");117}118}119}120}121122123