Path: blob/master/test/jdk/sun/util/resources/TimeZone/Bug8139107.java
41154 views
/*1* Copyright (c) 2015, 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 813910726* @summary Test that date parsing with DateTimeFormatter pattern27* that contains timezone field doesn't trigger NPE. All supported28* locales are tested.29* @run testng/othervm -Djava.locale.providers=JRE,SPI Bug813910730*/31import java.time.format.DateTimeFormatter;32import java.util.Locale;33import org.testng.annotations.Test;3435public class Bug8139107 {3637@Test38public void testSupportedLocales() {39for (Locale loc:Locale.getAvailableLocales()) {40testLocale(loc);41}42}4344//Test one locale45void testLocale(Locale tl) {46System.out.println("Locale:" + tl);47DateTimeFormatter inputDateTimeFormat = DateTimeFormatter48.ofPattern(pattern)49.withLocale(tl);50System.out.println("Parse result: " + inputDateTimeFormat.parse(inputDate));51}5253// Input date time string with short time zone name54static final String inputDate = "06-10-2015 18:58:04 MSK";55// Pattern with time zone field56static final String pattern = "dd-MM-yyyy HH:mm:ss z";57}58596061