Path: blob/master/test/jdk/java/util/Calendar/CalendarDisplayNamesTest.java
41149 views
/*1* Copyright (c) 2021, 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*/2223import org.testng.Assert;24import org.testng.annotations.Test;2526import java.util.Calendar;27import java.util.Locale;28import java.util.Map;2930/**31* @test32* @bug 826210833* @summary Verify the results returned by Calendar.getDisplayNames() API34* @comment Locale providers: COMPAT,SPI35* @run testng/othervm -Djava.locale.providers=COMPAT,SPI CalendarDisplayNamesTest36* @comment Locale providers: CLDR37* @run testng/othervm -Djava.locale.providers=CLDR CalendarDisplayNamesTest38*/39public class CalendarDisplayNamesTest {4041/**42* Test that the {@link Calendar#getDisplayNames(int, int, Locale)} returns valid field values43* for the {@link Calendar#AM_PM} field in various locales and styles44*/45@Test46public void testAM_PMDisplayNameValues() {47final int[] styles = new int[]{Calendar.ALL_STYLES, Calendar.SHORT_FORMAT, Calendar.LONG_FORMAT,48Calendar.SHORT_STANDALONE, Calendar.LONG_STANDALONE, Calendar.SHORT, Calendar.LONG};49for (final Locale locale : Locale.getAvailableLocales()) {50for (final int style : styles) {51final Calendar cal = Calendar.getInstance();52final Map<String, Integer> names = cal.getDisplayNames(Calendar.AM_PM, style, locale);53if (names == null) {54continue;55}56for (final Integer fieldValue : names.values()) {57Assert.assertTrue(fieldValue == Calendar.AM || fieldValue == Calendar.PM,58"Invalid field value " + fieldValue + " for calendar field AM_PM, in locale "59+ locale + " with style " + style);60}61}62}63}64}656667