1 /* 2 * Copyright (c) 2015, 2016, 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 */ 23 24 /** 25 * @test 26 * @bug 8080774 27 * @modules jdk.localedata 28 * @run testng/othervm -Djava.locale.providers=JRE,CLDR LocaleDateFormats 29 * @summary This file contains tests for JRE locales date formats 30 */ 31 32 import java.text.DateFormat; 33 import java.util.Calendar; 34 import java.util.Locale; 35 import static org.testng.Assert.assertEquals; 36 import org.testng.annotations.DataProvider; 37 import org.testng.annotations.Test; 38 39 public class LocaleDateFormats { 40 41 @Test(dataProvider = "dateFormats") 42 public void testDateFormat(Locale loc, int style, int year, int month, int date, String expectedString) { 43 Calendar cal = Calendar.getInstance(loc); 44 cal.set(year, month-1, date); 45 // Create date formatter based on requested style and test locale 46 DateFormat df = DateFormat.getDateInstance(style, loc); 47 // Test the date format 48 assertEquals(df.format(cal.getTime()), expectedString); 49 } 50 51 @DataProvider(name = "dateFormats" ) 52 private Object[][] dateFormats() { 53 return new Object[][] { 54 //8080774 55 //Locale, Format type, year, month, date, expected result 56 {localeEnSG, DateFormat.SHORT, 2015, 5, 6, "6/5/15"}, 57 {localeEnSG, DateFormat.MEDIUM, 2015, 5, 6, "6 May, 2015"}, 58 {localeEnSG, DateFormat.LONG, 2015, 5, 6, "6 May, 2015"}, 59 {localeEnSG, DateFormat.FULL, 2015, 5, 6, "Wednesday, 6 May, 2015"} 60 }; 61 } 62 // en_SG Locale instance 63 private static final Locale localeEnSG = new Locale("en", "SG"); 64 }