Path: blob/master/test/jdk/java/text/Format/DateFormat/CaseInsensitiveParseTest.java
41152 views
/*1* Copyright (c) 2020, 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 824843426* @modules jdk.localedata27* @run testng/othervm CaseInsensitiveParseTest28* @summary Checks format/parse round trip in case-insensitive manner.29*/3031import java.text.DateFormat;32import java.text.ParseException;33import java.text.SimpleDateFormat;34import java.util.Arrays;35import java.util.Date;36import java.util.Locale;37import java.util.stream.Stream;3839import static org.testng.Assert.assertEquals;40import org.testng.annotations.DataProvider;41import org.testng.annotations.Test;4243public class CaseInsensitiveParseTest {4445private final static String PATTERN = "GGGG/yyyy/MMMM/dddd/hhhh/mmmm/ss/aaaa";46private final static Date EPOCH = new Date(0L);4748@DataProvider49private Object[][] locales() {50return (Object[][])Arrays.stream(DateFormat.getAvailableLocales())51.map(Stream::of)52.map(Stream::toArray)53.toArray(Object[][]::new);54}5556@Test(dataProvider = "locales")57public void testUpperCase(Locale loc) throws ParseException {58SimpleDateFormat sdf = new SimpleDateFormat(PATTERN, loc);59String formatted = sdf.format(EPOCH);60assertEquals(sdf.parse(formatted.toUpperCase(Locale.ROOT)), EPOCH,61"roundtrip failed for string '" + formatted + "', locale: " + loc);62}6364@Test(dataProvider = "locales")65public void testLowerCase(Locale loc) throws ParseException {66SimpleDateFormat sdf = new SimpleDateFormat(PATTERN, loc);67String formatted = sdf.format(EPOCH);68assertEquals(sdf.parse(formatted.toLowerCase(Locale.ROOT)), EPOCH,69"roundtrip failed for string '" + formatted + "', locale: " + loc);70}71}727374