8171958: Several tests from java/time/test/java/time/format requiring jdk.localedata for execution
Reviewed-by: naoto
This commit is contained in:
parent
4cd655c1f6
commit
60a77d0b84
@ -1,7 +1,6 @@
|
||||
# Threeten test uses TestNG
|
||||
TestNG.dirs = .
|
||||
othervm.dirs = tck/java/time/chrono test/java/time/chrono test/java/time/format
|
||||
modules = jdk.localedata
|
||||
lib.dirs = ../../lib/testlibrary
|
||||
lib.build = jdk.testlibrary.RandomFactory
|
||||
modules = java.base/java.time:open java.base/java.time.chrono:open java.base/java.time.zone:open
|
||||
|
@ -879,25 +879,6 @@ public class TestDateTimeFormatterBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="patternPrint")
|
||||
Object[][] data_patternPrint() {
|
||||
return new Object[][] {
|
||||
{"Q", date(2012, 2, 10), "1"},
|
||||
{"QQ", date(2012, 2, 10), "01"},
|
||||
{"QQQ", date(2012, 2, 10), "Q1"},
|
||||
{"QQQQ", date(2012, 2, 10), "1st quarter"},
|
||||
{"QQQQQ", date(2012, 2, 10), "1"},
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="patternPrint")
|
||||
public void test_appendPattern_patternPrint(String input, Temporal temporal, String expected) throws Exception {
|
||||
DateTimeFormatter f = builder.appendPattern(input).toFormatter(Locale.UK);
|
||||
String test = f.format(temporal);
|
||||
assertEquals(test, expected);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="localePatterns")
|
||||
Object[][] localizedDateTimePatterns() {
|
||||
@ -914,48 +895,6 @@ public class TestDateTimeFormatterBuilder {
|
||||
{null, FormatStyle.LONG, IsoChronology.INSTANCE, Locale.US, "h:mm:ss a z"},
|
||||
{null, FormatStyle.MEDIUM, IsoChronology.INSTANCE, Locale.US, "h:mm:ss a"},
|
||||
{null, FormatStyle.SHORT, IsoChronology.INSTANCE, Locale.US, "h:mm a"},
|
||||
|
||||
// French Locale and ISO Chronology
|
||||
{FormatStyle.FULL, FormatStyle.FULL, IsoChronology.INSTANCE, Locale.FRENCH, "EEEE d MMMM y '\u00e0' HH:mm:ss zzzz"},
|
||||
{FormatStyle.LONG, FormatStyle.LONG, IsoChronology.INSTANCE, Locale.FRENCH, "d MMMM y '\u00e0' HH:mm:ss z"},
|
||||
{FormatStyle.MEDIUM, FormatStyle.MEDIUM, IsoChronology.INSTANCE, Locale.FRENCH, "d MMM y '\u00e0' HH:mm:ss"},
|
||||
{FormatStyle.SHORT, FormatStyle.SHORT, IsoChronology.INSTANCE, Locale.FRENCH, "dd/MM/y HH:mm"},
|
||||
{FormatStyle.FULL, null, IsoChronology.INSTANCE, Locale.FRENCH, "EEEE d MMMM y"},
|
||||
{FormatStyle.LONG, null, IsoChronology.INSTANCE, Locale.FRENCH, "d MMMM y"},
|
||||
{FormatStyle.MEDIUM, null, IsoChronology.INSTANCE, Locale.FRENCH, "d MMM y"},
|
||||
{FormatStyle.SHORT, null, IsoChronology.INSTANCE, Locale.FRENCH, "dd/MM/y"},
|
||||
{null, FormatStyle.FULL, IsoChronology.INSTANCE, Locale.FRENCH, "HH:mm:ss zzzz"},
|
||||
{null, FormatStyle.LONG, IsoChronology.INSTANCE, Locale.FRENCH, "HH:mm:ss z"},
|
||||
{null, FormatStyle.MEDIUM, IsoChronology.INSTANCE, Locale.FRENCH, "HH:mm:ss"},
|
||||
{null, FormatStyle.SHORT, IsoChronology.INSTANCE, Locale.FRENCH, "HH:mm"},
|
||||
|
||||
// Japanese Locale and JapaneseChronology
|
||||
{FormatStyle.FULL, FormatStyle.FULL, JapaneseChronology.INSTANCE, Locale.JAPANESE, "Gy\u5e74M\u6708d\u65e5EEEE H\u6642mm\u5206ss\u79d2 zzzz"},
|
||||
{FormatStyle.LONG, FormatStyle.LONG, JapaneseChronology.INSTANCE, Locale.JAPANESE, "Gy\u5e74M\u6708d\u65e5 H:mm:ss z"},
|
||||
{FormatStyle.MEDIUM, FormatStyle.MEDIUM, JapaneseChronology.INSTANCE, Locale.JAPANESE, "Gy\u5e74M\u6708d\u65e5 H:mm:ss"},
|
||||
{FormatStyle.SHORT, FormatStyle.SHORT, JapaneseChronology.INSTANCE, Locale.JAPANESE, "GGGGGy/M/d H:mm"},
|
||||
{FormatStyle.FULL, null, JapaneseChronology.INSTANCE, Locale.JAPANESE, "Gy\u5e74M\u6708d\u65e5EEEE"},
|
||||
{FormatStyle.LONG, null, JapaneseChronology.INSTANCE, Locale.JAPANESE, "Gy\u5e74M\u6708d\u65e5"},
|
||||
{FormatStyle.MEDIUM, null, JapaneseChronology.INSTANCE, Locale.JAPANESE, "Gy\u5e74M\u6708d\u65e5"},
|
||||
{FormatStyle.SHORT, null, JapaneseChronology.INSTANCE, Locale.JAPANESE, "GGGGGy/M/d"},
|
||||
{null, FormatStyle.FULL, JapaneseChronology.INSTANCE, Locale.JAPANESE, "H\u6642mm\u5206ss\u79d2 zzzz"},
|
||||
{null, FormatStyle.LONG, JapaneseChronology.INSTANCE, Locale.JAPANESE, "H:mm:ss z"},
|
||||
{null, FormatStyle.MEDIUM, JapaneseChronology.INSTANCE, Locale.JAPANESE, "H:mm:ss"},
|
||||
{null, FormatStyle.SHORT, JapaneseChronology.INSTANCE, Locale.JAPANESE, "H:mm"},
|
||||
|
||||
// Chinese Local and Chronology
|
||||
{FormatStyle.FULL, FormatStyle.FULL, MinguoChronology.INSTANCE, Locale.CHINESE, "Gy\u5e74M\u6708d\u65e5EEEE zzzz ah:mm:ss"},
|
||||
{FormatStyle.LONG, FormatStyle.LONG, MinguoChronology.INSTANCE, Locale.CHINESE, "Gy\u5e74M\u6708d\u65e5 z ah:mm:ss"},
|
||||
{FormatStyle.MEDIUM, FormatStyle.MEDIUM, MinguoChronology.INSTANCE, Locale.CHINESE, "Gy\u5e74M\u6708d\u65e5 ah:mm:ss"},
|
||||
{FormatStyle.SHORT, FormatStyle.SHORT, MinguoChronology.INSTANCE, Locale.CHINESE, "Gyy/M/d ah:mm"},
|
||||
{FormatStyle.FULL, null, MinguoChronology.INSTANCE, Locale.CHINESE, "Gy\u5e74M\u6708d\u65e5EEEE"},
|
||||
{FormatStyle.LONG, null, MinguoChronology.INSTANCE, Locale.CHINESE, "Gy\u5e74M\u6708d\u65e5"},
|
||||
{FormatStyle.MEDIUM, null, MinguoChronology.INSTANCE, Locale.CHINESE, "Gy\u5e74M\u6708d\u65e5"},
|
||||
{FormatStyle.SHORT, null, MinguoChronology.INSTANCE, Locale.CHINESE, "Gyy/M/d"},
|
||||
{null, FormatStyle.FULL, MinguoChronology.INSTANCE, Locale.CHINESE, "zzzz ah:mm:ss"},
|
||||
{null, FormatStyle.LONG, MinguoChronology.INSTANCE, Locale.CHINESE, "z ah:mm:ss"},
|
||||
{null, FormatStyle.MEDIUM, MinguoChronology.INSTANCE, Locale.CHINESE, "ah:mm:ss"},
|
||||
{null, FormatStyle.SHORT, MinguoChronology.INSTANCE, Locale.CHINESE, "ah:mm"},
|
||||
};
|
||||
}
|
||||
|
||||
@ -1004,5 +943,4 @@ public class TestDateTimeFormatterBuilder {
|
||||
private static Temporal date(int y, int m, int d) {
|
||||
return LocalDate.of(y, m, d);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,195 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is available under and governed by the GNU General Public
|
||||
* License version 2 only, as published by the Free Software Foundation.
|
||||
* However, the following notice accompanied the original version of this
|
||||
* file:
|
||||
*
|
||||
* Copyright (c) 2009-2012, Stephen Colebourne & Michael Nascimento Santos
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of JSR-310 nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @modules jdk.localedata
|
||||
*/
|
||||
package test.java.time.format;
|
||||
|
||||
import java.time.chrono.Chronology;
|
||||
import java.time.chrono.IsoChronology;
|
||||
import java.time.chrono.JapaneseChronology;
|
||||
import java.time.chrono.MinguoChronology;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeFormatterBuilder;
|
||||
import java.time.format.FormatStyle;
|
||||
import java.time.LocalDate;
|
||||
import java.time.temporal.Temporal;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Test DateTimeFormatterBuilder.
|
||||
*/
|
||||
@Test
|
||||
public class TestDateTimeFormatterBuilderWithLocale {
|
||||
|
||||
private DateTimeFormatterBuilder builder;
|
||||
|
||||
@BeforeMethod
|
||||
public void setUp() {
|
||||
builder = new DateTimeFormatterBuilder();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="patternPrint")
|
||||
Object[][] data_patternPrint() {
|
||||
return new Object[][] {
|
||||
{"Q", date(2012, 2, 10), "1"},
|
||||
{"QQ", date(2012, 2, 10), "01"},
|
||||
{"QQQ", date(2012, 2, 10), "Q1"},
|
||||
{"QQQQ", date(2012, 2, 10), "1st quarter"},
|
||||
{"QQQQQ", date(2012, 2, 10), "1"},
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="patternPrint")
|
||||
public void test_appendPattern_patternPrint(String input, Temporal temporal, String expected) throws Exception {
|
||||
DateTimeFormatter f = builder.appendPattern(input).toFormatter(Locale.UK);
|
||||
String test = f.format(temporal);
|
||||
assertEquals(test, expected);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="localePatterns")
|
||||
Object[][] localizedDateTimePatterns() {
|
||||
return new Object[][] {
|
||||
// French Locale and ISO Chronology
|
||||
{FormatStyle.FULL, FormatStyle.FULL, IsoChronology.INSTANCE, Locale.FRENCH, "EEEE d MMMM y '\u00e0' HH:mm:ss zzzz"},
|
||||
{FormatStyle.LONG, FormatStyle.LONG, IsoChronology.INSTANCE, Locale.FRENCH, "d MMMM y '\u00e0' HH:mm:ss z"},
|
||||
{FormatStyle.MEDIUM, FormatStyle.MEDIUM, IsoChronology.INSTANCE, Locale.FRENCH, "d MMM y '\u00e0' HH:mm:ss"},
|
||||
{FormatStyle.SHORT, FormatStyle.SHORT, IsoChronology.INSTANCE, Locale.FRENCH, "dd/MM/y HH:mm"},
|
||||
{FormatStyle.FULL, null, IsoChronology.INSTANCE, Locale.FRENCH, "EEEE d MMMM y"},
|
||||
{FormatStyle.LONG, null, IsoChronology.INSTANCE, Locale.FRENCH, "d MMMM y"},
|
||||
{FormatStyle.MEDIUM, null, IsoChronology.INSTANCE, Locale.FRENCH, "d MMM y"},
|
||||
{FormatStyle.SHORT, null, IsoChronology.INSTANCE, Locale.FRENCH, "dd/MM/y"},
|
||||
{null, FormatStyle.FULL, IsoChronology.INSTANCE, Locale.FRENCH, "HH:mm:ss zzzz"},
|
||||
{null, FormatStyle.LONG, IsoChronology.INSTANCE, Locale.FRENCH, "HH:mm:ss z"},
|
||||
{null, FormatStyle.MEDIUM, IsoChronology.INSTANCE, Locale.FRENCH, "HH:mm:ss"},
|
||||
{null, FormatStyle.SHORT, IsoChronology.INSTANCE, Locale.FRENCH, "HH:mm"},
|
||||
|
||||
// Japanese Locale and JapaneseChronology
|
||||
{FormatStyle.FULL, FormatStyle.FULL, JapaneseChronology.INSTANCE, Locale.JAPANESE, "Gy\u5e74M\u6708d\u65e5EEEE H\u6642mm\u5206ss\u79d2 zzzz"},
|
||||
{FormatStyle.LONG, FormatStyle.LONG, JapaneseChronology.INSTANCE, Locale.JAPANESE, "Gy\u5e74M\u6708d\u65e5 H:mm:ss z"},
|
||||
{FormatStyle.MEDIUM, FormatStyle.MEDIUM, JapaneseChronology.INSTANCE, Locale.JAPANESE, "Gy\u5e74M\u6708d\u65e5 H:mm:ss"},
|
||||
{FormatStyle.SHORT, FormatStyle.SHORT, JapaneseChronology.INSTANCE, Locale.JAPANESE, "GGGGGy/M/d H:mm"},
|
||||
{FormatStyle.FULL, null, JapaneseChronology.INSTANCE, Locale.JAPANESE, "Gy\u5e74M\u6708d\u65e5EEEE"},
|
||||
{FormatStyle.LONG, null, JapaneseChronology.INSTANCE, Locale.JAPANESE, "Gy\u5e74M\u6708d\u65e5"},
|
||||
{FormatStyle.MEDIUM, null, JapaneseChronology.INSTANCE, Locale.JAPANESE, "Gy\u5e74M\u6708d\u65e5"},
|
||||
{FormatStyle.SHORT, null, JapaneseChronology.INSTANCE, Locale.JAPANESE, "GGGGGy/M/d"},
|
||||
{null, FormatStyle.FULL, JapaneseChronology.INSTANCE, Locale.JAPANESE, "H\u6642mm\u5206ss\u79d2 zzzz"},
|
||||
{null, FormatStyle.LONG, JapaneseChronology.INSTANCE, Locale.JAPANESE, "H:mm:ss z"},
|
||||
{null, FormatStyle.MEDIUM, JapaneseChronology.INSTANCE, Locale.JAPANESE, "H:mm:ss"},
|
||||
{null, FormatStyle.SHORT, JapaneseChronology.INSTANCE, Locale.JAPANESE, "H:mm"},
|
||||
|
||||
// Chinese Local and Chronology
|
||||
{FormatStyle.FULL, FormatStyle.FULL, MinguoChronology.INSTANCE, Locale.CHINESE, "Gy\u5e74M\u6708d\u65e5EEEE zzzz ah:mm:ss"},
|
||||
{FormatStyle.LONG, FormatStyle.LONG, MinguoChronology.INSTANCE, Locale.CHINESE, "Gy\u5e74M\u6708d\u65e5 z ah:mm:ss"},
|
||||
{FormatStyle.MEDIUM, FormatStyle.MEDIUM, MinguoChronology.INSTANCE, Locale.CHINESE, "Gy\u5e74M\u6708d\u65e5 ah:mm:ss"},
|
||||
{FormatStyle.SHORT, FormatStyle.SHORT, MinguoChronology.INSTANCE, Locale.CHINESE, "Gyy/M/d ah:mm"},
|
||||
{FormatStyle.FULL, null, MinguoChronology.INSTANCE, Locale.CHINESE, "Gy\u5e74M\u6708d\u65e5EEEE"},
|
||||
{FormatStyle.LONG, null, MinguoChronology.INSTANCE, Locale.CHINESE, "Gy\u5e74M\u6708d\u65e5"},
|
||||
{FormatStyle.MEDIUM, null, MinguoChronology.INSTANCE, Locale.CHINESE, "Gy\u5e74M\u6708d\u65e5"},
|
||||
{FormatStyle.SHORT, null, MinguoChronology.INSTANCE, Locale.CHINESE, "Gyy/M/d"},
|
||||
{null, FormatStyle.FULL, MinguoChronology.INSTANCE, Locale.CHINESE, "zzzz ah:mm:ss"},
|
||||
{null, FormatStyle.LONG, MinguoChronology.INSTANCE, Locale.CHINESE, "z ah:mm:ss"},
|
||||
{null, FormatStyle.MEDIUM, MinguoChronology.INSTANCE, Locale.CHINESE, "ah:mm:ss"},
|
||||
{null, FormatStyle.SHORT, MinguoChronology.INSTANCE, Locale.CHINESE, "ah:mm"},
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="localePatterns")
|
||||
public void test_getLocalizedDateTimePattern(FormatStyle dateStyle, FormatStyle timeStyle,
|
||||
Chronology chrono, Locale locale, String expected) {
|
||||
String actual = DateTimeFormatterBuilder.getLocalizedDateTimePattern(dateStyle, timeStyle, chrono, locale);
|
||||
assertEquals(actual, expected, "Pattern " + convertNonAscii(actual));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string that includes non-ascii characters after expanding
|
||||
* the non-ascii characters to their Java language \\uxxxx form.
|
||||
* @param input an input string
|
||||
* @return the encoded string.
|
||||
*/
|
||||
private String convertNonAscii(String input) {
|
||||
StringBuilder sb = new StringBuilder(input.length() * 6);
|
||||
for (int i = 0; i < input.length(); i++) {
|
||||
char ch = input.charAt(i);
|
||||
if (ch < 255) {
|
||||
sb.append(ch);
|
||||
} else {
|
||||
sb.append("\\u");
|
||||
sb.append(Integer.toHexString(ch));
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static Temporal date(int y, int m, int d) {
|
||||
return LocalDate.of(y, m, d);
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -80,7 +80,6 @@ import org.testng.annotations.Test;
|
||||
public class TestDateTimeTextProvider extends AbstractTestPrinterParser {
|
||||
|
||||
Locale enUS = new Locale("en", "US");
|
||||
Locale ptBR = new Locale("pt", "BR");
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "Text")
|
||||
@ -94,14 +93,6 @@ public class TestDateTimeTextProvider extends AbstractTestPrinterParser {
|
||||
{DAY_OF_WEEK, 6, TextStyle.SHORT, enUS, "Sat"},
|
||||
{DAY_OF_WEEK, 7, TextStyle.SHORT, enUS, "Sun"},
|
||||
|
||||
{DAY_OF_WEEK, 1, TextStyle.SHORT, ptBR, "seg"},
|
||||
{DAY_OF_WEEK, 2, TextStyle.SHORT, ptBR, "ter"},
|
||||
{DAY_OF_WEEK, 3, TextStyle.SHORT, ptBR, "qua"},
|
||||
{DAY_OF_WEEK, 4, TextStyle.SHORT, ptBR, "qui"},
|
||||
{DAY_OF_WEEK, 5, TextStyle.SHORT, ptBR, "sex"},
|
||||
{DAY_OF_WEEK, 6, TextStyle.SHORT, ptBR, "s\u00E1b"},
|
||||
{DAY_OF_WEEK, 7, TextStyle.SHORT, ptBR, "dom"},
|
||||
|
||||
{DAY_OF_WEEK, 1, TextStyle.FULL, enUS, "Monday"},
|
||||
{DAY_OF_WEEK, 2, TextStyle.FULL, enUS, "Tuesday"},
|
||||
{DAY_OF_WEEK, 3, TextStyle.FULL, enUS, "Wednesday"},
|
||||
@ -110,14 +101,6 @@ public class TestDateTimeTextProvider extends AbstractTestPrinterParser {
|
||||
{DAY_OF_WEEK, 6, TextStyle.FULL, enUS, "Saturday"},
|
||||
{DAY_OF_WEEK, 7, TextStyle.FULL, enUS, "Sunday"},
|
||||
|
||||
{DAY_OF_WEEK, 1, TextStyle.FULL, ptBR, "segunda-feira"},
|
||||
{DAY_OF_WEEK, 2, TextStyle.FULL, ptBR, "ter\u00E7a-feira"},
|
||||
{DAY_OF_WEEK, 3, TextStyle.FULL, ptBR, "quarta-feira"},
|
||||
{DAY_OF_WEEK, 4, TextStyle.FULL, ptBR, "quinta-feira"},
|
||||
{DAY_OF_WEEK, 5, TextStyle.FULL, ptBR, "sexta-feira"},
|
||||
{DAY_OF_WEEK, 6, TextStyle.FULL, ptBR, "s\u00E1bado"},
|
||||
{DAY_OF_WEEK, 7, TextStyle.FULL, ptBR, "domingo"},
|
||||
|
||||
{MONTH_OF_YEAR, 1, TextStyle.SHORT, enUS, "Jan"},
|
||||
{MONTH_OF_YEAR, 2, TextStyle.SHORT, enUS, "Feb"},
|
||||
{MONTH_OF_YEAR, 3, TextStyle.SHORT, enUS, "Mar"},
|
||||
@ -131,19 +114,6 @@ public class TestDateTimeTextProvider extends AbstractTestPrinterParser {
|
||||
{MONTH_OF_YEAR, 11, TextStyle.SHORT, enUS, "Nov"},
|
||||
{MONTH_OF_YEAR, 12, TextStyle.SHORT, enUS, "Dec"},
|
||||
|
||||
{MONTH_OF_YEAR, 1, TextStyle.SHORT, ptBR, "jan"},
|
||||
{MONTH_OF_YEAR, 2, TextStyle.SHORT, ptBR, "fev"},
|
||||
{MONTH_OF_YEAR, 3, TextStyle.SHORT, ptBR, "mar"},
|
||||
{MONTH_OF_YEAR, 4, TextStyle.SHORT, ptBR, "abr"},
|
||||
{MONTH_OF_YEAR, 5, TextStyle.SHORT, ptBR, "mai"},
|
||||
{MONTH_OF_YEAR, 6, TextStyle.SHORT, ptBR, "jun"},
|
||||
{MONTH_OF_YEAR, 7, TextStyle.SHORT, ptBR, "jul"},
|
||||
{MONTH_OF_YEAR, 8, TextStyle.SHORT, ptBR, "ago"},
|
||||
{MONTH_OF_YEAR, 9, TextStyle.SHORT, ptBR, "set"},
|
||||
{MONTH_OF_YEAR, 10, TextStyle.SHORT, ptBR, "out"},
|
||||
{MONTH_OF_YEAR, 11, TextStyle.SHORT, ptBR, "nov"},
|
||||
{MONTH_OF_YEAR, 12, TextStyle.SHORT, ptBR, "dez"},
|
||||
|
||||
{MONTH_OF_YEAR, 1, TextStyle.FULL, enUS, "January"},
|
||||
{MONTH_OF_YEAR, 2, TextStyle.FULL, enUS, "February"},
|
||||
{MONTH_OF_YEAR, 3, TextStyle.FULL, enUS, "March"},
|
||||
@ -157,19 +127,6 @@ public class TestDateTimeTextProvider extends AbstractTestPrinterParser {
|
||||
{MONTH_OF_YEAR, 11, TextStyle.FULL, enUS, "November"},
|
||||
{MONTH_OF_YEAR, 12, TextStyle.FULL, enUS, "December"},
|
||||
|
||||
{MONTH_OF_YEAR, 1, TextStyle.FULL, ptBR, "janeiro"},
|
||||
{MONTH_OF_YEAR, 2, TextStyle.FULL, ptBR, "fevereiro"},
|
||||
{MONTH_OF_YEAR, 3, TextStyle.FULL, ptBR, "mar\u00E7o"},
|
||||
{MONTH_OF_YEAR, 4, TextStyle.FULL, ptBR, "abril"},
|
||||
{MONTH_OF_YEAR, 5, TextStyle.FULL, ptBR, "maio"},
|
||||
{MONTH_OF_YEAR, 6, TextStyle.FULL, ptBR, "junho"},
|
||||
{MONTH_OF_YEAR, 7, TextStyle.FULL, ptBR, "julho"},
|
||||
{MONTH_OF_YEAR, 8, TextStyle.FULL, ptBR, "agosto"},
|
||||
{MONTH_OF_YEAR, 9, TextStyle.FULL, ptBR, "setembro"},
|
||||
{MONTH_OF_YEAR, 10, TextStyle.FULL, ptBR, "outubro"},
|
||||
{MONTH_OF_YEAR, 11, TextStyle.FULL, ptBR, "novembro"},
|
||||
{MONTH_OF_YEAR, 12, TextStyle.FULL, ptBR, "dezembro"},
|
||||
|
||||
{AMPM_OF_DAY, 0, TextStyle.SHORT, enUS, "AM"},
|
||||
{AMPM_OF_DAY, 1, TextStyle.SHORT, enUS, "PM"},
|
||||
|
||||
|
@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is available under and governed by the GNU General Public
|
||||
* License version 2 only, as published by the Free Software Foundation.
|
||||
* However, the following notice accompanied the original version of this
|
||||
* file:
|
||||
*
|
||||
* Copyright (c) 2011-2012, Stephen Colebourne & Michael Nascimento Santos
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of JSR-310 nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @modules jdk.localedata
|
||||
*/
|
||||
|
||||
package test.java.time.format;
|
||||
|
||||
import static java.time.temporal.ChronoField.AMPM_OF_DAY;
|
||||
import static java.time.temporal.ChronoField.DAY_OF_WEEK;
|
||||
import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.TextStyle;
|
||||
import java.time.temporal.TemporalField;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Test SimpleDateTimeTextProviderWithLocale.
|
||||
*/
|
||||
@Test
|
||||
public class TestDateTimeTextProviderWithLocale extends AbstractTestPrinterParser {
|
||||
|
||||
Locale enUS = new Locale("en", "US");
|
||||
Locale ptBR = new Locale("pt", "BR");
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "Text")
|
||||
Object[][] data_text() {
|
||||
return new Object[][] {
|
||||
{DAY_OF_WEEK, 1, TextStyle.SHORT, ptBR, "seg"},
|
||||
{DAY_OF_WEEK, 2, TextStyle.SHORT, ptBR, "ter"},
|
||||
{DAY_OF_WEEK, 3, TextStyle.SHORT, ptBR, "qua"},
|
||||
{DAY_OF_WEEK, 4, TextStyle.SHORT, ptBR, "qui"},
|
||||
{DAY_OF_WEEK, 5, TextStyle.SHORT, ptBR, "sex"},
|
||||
{DAY_OF_WEEK, 6, TextStyle.SHORT, ptBR, "s\u00E1b"},
|
||||
{DAY_OF_WEEK, 7, TextStyle.SHORT, ptBR, "dom"},
|
||||
|
||||
{DAY_OF_WEEK, 1, TextStyle.FULL, ptBR, "segunda-feira"},
|
||||
{DAY_OF_WEEK, 2, TextStyle.FULL, ptBR, "ter\u00E7a-feira"},
|
||||
{DAY_OF_WEEK, 3, TextStyle.FULL, ptBR, "quarta-feira"},
|
||||
{DAY_OF_WEEK, 4, TextStyle.FULL, ptBR, "quinta-feira"},
|
||||
{DAY_OF_WEEK, 5, TextStyle.FULL, ptBR, "sexta-feira"},
|
||||
{DAY_OF_WEEK, 6, TextStyle.FULL, ptBR, "s\u00E1bado"},
|
||||
{DAY_OF_WEEK, 7, TextStyle.FULL, ptBR, "domingo"},
|
||||
|
||||
{MONTH_OF_YEAR, 1, TextStyle.SHORT, ptBR, "jan"},
|
||||
{MONTH_OF_YEAR, 2, TextStyle.SHORT, ptBR, "fev"},
|
||||
{MONTH_OF_YEAR, 3, TextStyle.SHORT, ptBR, "mar"},
|
||||
{MONTH_OF_YEAR, 4, TextStyle.SHORT, ptBR, "abr"},
|
||||
{MONTH_OF_YEAR, 5, TextStyle.SHORT, ptBR, "mai"},
|
||||
{MONTH_OF_YEAR, 6, TextStyle.SHORT, ptBR, "jun"},
|
||||
{MONTH_OF_YEAR, 7, TextStyle.SHORT, ptBR, "jul"},
|
||||
{MONTH_OF_YEAR, 8, TextStyle.SHORT, ptBR, "ago"},
|
||||
{MONTH_OF_YEAR, 9, TextStyle.SHORT, ptBR, "set"},
|
||||
{MONTH_OF_YEAR, 10, TextStyle.SHORT, ptBR, "out"},
|
||||
{MONTH_OF_YEAR, 11, TextStyle.SHORT, ptBR, "nov"},
|
||||
{MONTH_OF_YEAR, 12, TextStyle.SHORT, ptBR, "dez"},
|
||||
|
||||
{MONTH_OF_YEAR, 1, TextStyle.FULL, ptBR, "janeiro"},
|
||||
{MONTH_OF_YEAR, 2, TextStyle.FULL, ptBR, "fevereiro"},
|
||||
{MONTH_OF_YEAR, 3, TextStyle.FULL, ptBR, "mar\u00E7o"},
|
||||
{MONTH_OF_YEAR, 4, TextStyle.FULL, ptBR, "abril"},
|
||||
{MONTH_OF_YEAR, 5, TextStyle.FULL, ptBR, "maio"},
|
||||
{MONTH_OF_YEAR, 6, TextStyle.FULL, ptBR, "junho"},
|
||||
{MONTH_OF_YEAR, 7, TextStyle.FULL, ptBR, "julho"},
|
||||
{MONTH_OF_YEAR, 8, TextStyle.FULL, ptBR, "agosto"},
|
||||
{MONTH_OF_YEAR, 9, TextStyle.FULL, ptBR, "setembro"},
|
||||
{MONTH_OF_YEAR, 10, TextStyle.FULL, ptBR, "outubro"},
|
||||
{MONTH_OF_YEAR, 11, TextStyle.FULL, ptBR, "novembro"},
|
||||
{MONTH_OF_YEAR, 12, TextStyle.FULL, ptBR, "dezembro"},
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "Text")
|
||||
public void test_getText(TemporalField field, Number value, TextStyle style, Locale locale, String expected) {
|
||||
DateTimeFormatter fmt = getFormatter(field, style).withLocale(locale);
|
||||
assertEquals(fmt.format(ZonedDateTime.now().with(field, value.longValue())), expected);
|
||||
}
|
||||
|
||||
}
|
@ -20,13 +20,14 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package test.java.time.format;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @modules jdk.localedata
|
||||
* @bug 8146750
|
||||
* @summary Test Narrow and NarrowStandalone month names are retrieved correctly.
|
||||
*/
|
||||
package test.java.time.format;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.time.DayOfWeek;
|
||||
|
@ -20,6 +20,13 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* @test
|
||||
* @modules jdk.localedata
|
||||
*/
|
||||
|
||||
package test.java.time.format;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -68,16 +68,9 @@ import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.text.ParsePosition;
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.chrono.ChronoLocalDate;
|
||||
import java.time.chrono.JapaneseChronology;
|
||||
import java.time.chrono.HijrahDate;
|
||||
import java.time.chrono.JapaneseDate;
|
||||
import java.time.chrono.MinguoDate;
|
||||
import java.time.chrono.ThaiBuddhistDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeFormatterBuilder;
|
||||
import java.time.format.TextStyle;
|
||||
import java.time.format.SignStyle;
|
||||
import java.time.temporal.TemporalAccessor;
|
||||
import java.time.temporal.TemporalField;
|
||||
import java.time.temporal.TemporalQueries;
|
||||
@ -92,8 +85,6 @@ import org.testng.annotations.Test;
|
||||
*/
|
||||
@Test
|
||||
public class TestTextParser extends AbstractTestPrinterParser {
|
||||
static final Locale RUSSIAN = new Locale("ru");
|
||||
static final Locale FINNISH = new Locale("fi");
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="error")
|
||||
@ -213,20 +204,6 @@ public class TestTextParser extends AbstractTestPrinterParser {
|
||||
};
|
||||
}
|
||||
|
||||
// Test data is dependent on localized resources.
|
||||
@DataProvider(name="parseStandaloneText")
|
||||
Object[][] providerStandaloneText() {
|
||||
// Locale, TemporalField, TextStyle, expected value, input text
|
||||
return new Object[][] {
|
||||
{RUSSIAN, MONTH_OF_YEAR, TextStyle.FULL_STANDALONE, 1, "\u044f\u043d\u0432\u0430\u0440\u044c"},
|
||||
{RUSSIAN, MONTH_OF_YEAR, TextStyle.FULL_STANDALONE, 12, "\u0434\u0435\u043a\u0430\u0431\u0440\u044c"},
|
||||
{RUSSIAN, MONTH_OF_YEAR, TextStyle.SHORT_STANDALONE, 1, "\u044f\u043d\u0432."},
|
||||
{RUSSIAN, MONTH_OF_YEAR, TextStyle.SHORT_STANDALONE, 12, "\u0434\u0435\u043a."},
|
||||
{FINNISH, DAY_OF_WEEK, TextStyle.FULL_STANDALONE, 2, "tiistai"},
|
||||
{FINNISH, DAY_OF_WEEK, TextStyle.SHORT_STANDALONE, 2, "ti"},
|
||||
};
|
||||
}
|
||||
|
||||
@DataProvider(name="parseDayOfWeekText")
|
||||
Object[][] providerDayOfWeekData() {
|
||||
return new Object[][] {
|
||||
@ -234,26 +211,9 @@ public class TestTextParser extends AbstractTestPrinterParser {
|
||||
{Locale.US, "e", "1", DayOfWeek.SUNDAY},
|
||||
{Locale.US, "ee", "01", DayOfWeek.SUNDAY},
|
||||
{Locale.US, "c", "1", DayOfWeek.SUNDAY},
|
||||
|
||||
{Locale.UK, "e", "1", DayOfWeek.MONDAY},
|
||||
{Locale.UK, "ee", "01", DayOfWeek.MONDAY},
|
||||
{Locale.UK, "c", "1", DayOfWeek.MONDAY},
|
||||
};
|
||||
}
|
||||
|
||||
// Test data is dependent on localized resources.
|
||||
@DataProvider(name="parseLenientText")
|
||||
Object[][] providerLenientText() {
|
||||
// Locale, TemporalField, expected value, input text
|
||||
return new Object[][] {
|
||||
{RUSSIAN, MONTH_OF_YEAR, 1, "\u044f\u043d\u0432\u0430\u0440\u044f"}, // full format
|
||||
{RUSSIAN, MONTH_OF_YEAR, 1, "\u044f\u043d\u0432\u0430\u0440\u044c"}, // full standalone
|
||||
{RUSSIAN, MONTH_OF_YEAR, 1, "\u044f\u043d\u0432."}, // short format
|
||||
{RUSSIAN, MONTH_OF_YEAR, 1, "\u044f\u043d\u0432."}, // short standalone
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test(dataProvider="parseText")
|
||||
public void test_parseText(TemporalField field, TextStyle style, int value, String input) throws Exception {
|
||||
@ -269,14 +229,6 @@ public class TestTextParser extends AbstractTestPrinterParser {
|
||||
assertEquals(pos.getIndex(), input.length());
|
||||
}
|
||||
|
||||
@Test(dataProvider="parseStandaloneText")
|
||||
public void test_parseStandaloneText(Locale locale, TemporalField field, TextStyle style, int expectedValue, String input) {
|
||||
DateTimeFormatter formatter = getFormatter(field, style).withLocale(locale);
|
||||
ParsePosition pos = new ParsePosition(0);
|
||||
assertEquals(formatter.parseUnresolved(input, pos).getLong(field), (long) expectedValue);
|
||||
assertEquals(pos.getIndex(), input.length());
|
||||
}
|
||||
|
||||
@Test(dataProvider="parseDayOfWeekText")
|
||||
public void test_parseDayOfWeekText(Locale locale, String pattern, String input, DayOfWeek expected) {
|
||||
DateTimeFormatter formatter = getPatternFormatter(pattern).withLocale(locale);
|
||||
@ -373,25 +325,6 @@ public class TestTextParser extends AbstractTestPrinterParser {
|
||||
assertEquals(pos.getErrorIndex(), 0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
public void test_parse_french_short_strict_full_noMatch() throws Exception {
|
||||
setStrict(true);
|
||||
ParsePosition pos = new ParsePosition(0);
|
||||
getFormatter(MONTH_OF_YEAR, TextStyle.SHORT).withLocale(Locale.FRENCH)
|
||||
.parseUnresolved("janvier", pos);
|
||||
assertEquals(pos.getErrorIndex(), 0);
|
||||
}
|
||||
|
||||
public void test_parse_french_short_strict_short_match() throws Exception {
|
||||
setStrict(true);
|
||||
ParsePosition pos = new ParsePosition(0);
|
||||
assertEquals(getFormatter(MONTH_OF_YEAR, TextStyle.SHORT).withLocale(Locale.FRENCH)
|
||||
.parseUnresolved("janv.", pos)
|
||||
.getLong(MONTH_OF_YEAR),
|
||||
1L);
|
||||
assertEquals(pos.getIndex(), 5);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
public void test_parse_full_lenient_full_match() throws Exception {
|
||||
setStrict(false);
|
||||
@ -436,51 +369,4 @@ public class TestTextParser extends AbstractTestPrinterParser {
|
||||
assertEquals(pos.getIndex(), 1);
|
||||
}
|
||||
|
||||
@Test(dataProvider="parseLenientText")
|
||||
public void test_parseLenientText(Locale locale, TemporalField field, int expectedValue, String input) {
|
||||
setStrict(false);
|
||||
ParsePosition pos = new ParsePosition(0);
|
||||
DateTimeFormatter formatter = getFormatter(field).withLocale(locale);
|
||||
assertEquals(formatter.parseUnresolved(input, pos).getLong(field), (long) expectedValue);
|
||||
assertEquals(pos.getIndex(), input.length());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="parseChronoLocalDate")
|
||||
Object[][] provider_chronoLocalDate() {
|
||||
return new Object[][] {
|
||||
{ HijrahDate.now() },
|
||||
{ JapaneseDate.now() },
|
||||
{ MinguoDate.now() },
|
||||
{ ThaiBuddhistDate.now() }};
|
||||
}
|
||||
|
||||
private static final DateTimeFormatter fmt_chrono =
|
||||
new DateTimeFormatterBuilder()
|
||||
.optionalStart()
|
||||
.appendChronologyId()
|
||||
.appendLiteral(' ')
|
||||
.optionalEnd()
|
||||
.optionalStart()
|
||||
.appendText(ChronoField.ERA, TextStyle.SHORT)
|
||||
.appendLiteral(' ')
|
||||
.optionalEnd()
|
||||
.appendValue(ChronoField.YEAR_OF_ERA, 1, 9, SignStyle.NORMAL)
|
||||
.appendLiteral('-')
|
||||
.appendValue(ChronoField.MONTH_OF_YEAR, 1, 2, SignStyle.NEVER)
|
||||
.appendLiteral('-')
|
||||
.appendValue(ChronoField.DAY_OF_MONTH, 1, 2, SignStyle.NEVER)
|
||||
.toFormatter();
|
||||
|
||||
@Test(dataProvider="parseChronoLocalDate")
|
||||
public void test_chronoLocalDate(ChronoLocalDate date) throws Exception {
|
||||
System.out.printf(" %s, [fmt=%s]%n", date, fmt_chrono.format(date));
|
||||
assertEquals(date, fmt_chrono.parse(fmt_chrono.format(date), ChronoLocalDate::from));
|
||||
|
||||
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("[GGG ]yyy-MM-dd")
|
||||
.withChronology(date.getChronology());
|
||||
System.out.printf(" %s, [fmt=%s]%n", date.toString(), fmt.format(date));
|
||||
assertEquals(date, fmt.parse(fmt.format(date), ChronoLocalDate::from));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,226 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is available under and governed by the GNU General Public
|
||||
* License version 2 only, as published by the Free Software Foundation.
|
||||
* However, the following notice accompanied the original version of this
|
||||
* file:
|
||||
*
|
||||
* Copyright (c) 2008-2012, Stephen Colebourne & Michael Nascimento Santos
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of JSR-310 nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @modules jdk.localedata
|
||||
*/
|
||||
|
||||
package test.java.time.format;
|
||||
|
||||
import java.text.ParsePosition;
|
||||
import java.time.chrono.ChronoLocalDate;
|
||||
import java.time.chrono.JapaneseChronology;
|
||||
import java.time.chrono.HijrahDate;
|
||||
import java.time.chrono.JapaneseDate;
|
||||
import java.time.chrono.MinguoDate;
|
||||
import java.time.chrono.ThaiBuddhistDate;
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeFormatterBuilder;
|
||||
import java.time.format.TextStyle;
|
||||
import java.time.format.SignStyle;
|
||||
import java.time.temporal.ChronoField;
|
||||
import java.time.temporal.TemporalField;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
||||
import static java.time.temporal.ChronoField.DAY_OF_MONTH;
|
||||
import static java.time.temporal.ChronoField.DAY_OF_WEEK;
|
||||
import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Test TextPrinterParser.
|
||||
*/
|
||||
@Test
|
||||
public class TestTextParserWithLocale extends AbstractTestPrinterParser {
|
||||
static final Locale RUSSIAN = new Locale("ru");
|
||||
static final Locale FINNISH = new Locale("fi");
|
||||
|
||||
@DataProvider(name="parseDayOfWeekText")
|
||||
Object[][] providerDayOfWeekData() {
|
||||
return new Object[][] {
|
||||
// Locale, pattern, input text, expected DayOfWeek
|
||||
{Locale.US, "e", "1", DayOfWeek.SUNDAY},
|
||||
{Locale.US, "ee", "01", DayOfWeek.SUNDAY},
|
||||
{Locale.US, "c", "1", DayOfWeek.SUNDAY},
|
||||
|
||||
{Locale.UK, "e", "1", DayOfWeek.MONDAY},
|
||||
{Locale.UK, "ee", "01", DayOfWeek.MONDAY},
|
||||
{Locale.UK, "c", "1", DayOfWeek.MONDAY},
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="parseDayOfWeekText")
|
||||
public void test_parseDayOfWeekText(Locale locale, String pattern, String input, DayOfWeek expected) {
|
||||
DateTimeFormatter formatter = getPatternFormatter(pattern).withLocale(locale);
|
||||
ParsePosition pos = new ParsePosition(0);
|
||||
assertEquals(DayOfWeek.from(formatter.parse(input, pos)), expected);
|
||||
assertEquals(pos.getIndex(), input.length());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Test data is dependent on localized resources.
|
||||
@DataProvider(name="parseStandaloneText")
|
||||
Object[][] providerStandaloneText() {
|
||||
// Locale, TemporalField, TextStyle, expected value, input text
|
||||
return new Object[][] {
|
||||
{RUSSIAN, MONTH_OF_YEAR, TextStyle.FULL_STANDALONE, 1, "\u044f\u043d\u0432\u0430\u0440\u044c"},
|
||||
{RUSSIAN, MONTH_OF_YEAR, TextStyle.FULL_STANDALONE, 12, "\u0434\u0435\u043a\u0430\u0431\u0440\u044c"},
|
||||
{RUSSIAN, MONTH_OF_YEAR, TextStyle.SHORT_STANDALONE, 1, "\u044f\u043d\u0432."},
|
||||
{RUSSIAN, MONTH_OF_YEAR, TextStyle.SHORT_STANDALONE, 12, "\u0434\u0435\u043a."},
|
||||
{FINNISH, DAY_OF_WEEK, TextStyle.FULL_STANDALONE, 2, "tiistai"},
|
||||
{FINNISH, DAY_OF_WEEK, TextStyle.SHORT_STANDALONE, 2, "ti"},
|
||||
};
|
||||
}
|
||||
|
||||
// Test data is dependent on localized resources.
|
||||
@DataProvider(name="parseLenientText")
|
||||
Object[][] providerLenientText() {
|
||||
// Locale, TemporalField, expected value, input text
|
||||
return new Object[][] {
|
||||
{RUSSIAN, MONTH_OF_YEAR, 1, "\u044f\u043d\u0432\u0430\u0440\u044f"}, // full format
|
||||
{RUSSIAN, MONTH_OF_YEAR, 1, "\u044f\u043d\u0432\u0430\u0440\u044c"}, // full standalone
|
||||
{RUSSIAN, MONTH_OF_YEAR, 1, "\u044f\u043d\u0432."}, // short format
|
||||
{RUSSIAN, MONTH_OF_YEAR, 1, "\u044f\u043d\u0432."}, // short standalone
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="parseStandaloneText")
|
||||
public void test_parseStandaloneText(Locale locale, TemporalField field, TextStyle style, int expectedValue, String input) {
|
||||
DateTimeFormatter formatter = getFormatter(field, style).withLocale(locale);
|
||||
ParsePosition pos = new ParsePosition(0);
|
||||
assertEquals(formatter.parseUnresolved(input, pos).getLong(field), (long) expectedValue);
|
||||
assertEquals(pos.getIndex(), input.length());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
public void test_parse_french_short_strict_full_noMatch() throws Exception {
|
||||
setStrict(true);
|
||||
ParsePosition pos = new ParsePosition(0);
|
||||
getFormatter(MONTH_OF_YEAR, TextStyle.SHORT).withLocale(Locale.FRENCH)
|
||||
.parseUnresolved("janvier", pos);
|
||||
assertEquals(pos.getErrorIndex(), 0);
|
||||
}
|
||||
|
||||
public void test_parse_french_short_strict_short_match() throws Exception {
|
||||
setStrict(true);
|
||||
ParsePosition pos = new ParsePosition(0);
|
||||
assertEquals(getFormatter(MONTH_OF_YEAR, TextStyle.SHORT).withLocale(Locale.FRENCH)
|
||||
.parseUnresolved("janv.", pos)
|
||||
.getLong(MONTH_OF_YEAR),
|
||||
1L);
|
||||
assertEquals(pos.getIndex(), 5);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
@Test(dataProvider="parseLenientText")
|
||||
public void test_parseLenientText(Locale locale, TemporalField field, int expectedValue, String input) {
|
||||
setStrict(false);
|
||||
ParsePosition pos = new ParsePosition(0);
|
||||
DateTimeFormatter formatter = getFormatter(field).withLocale(locale);
|
||||
assertEquals(formatter.parseUnresolved(input, pos).getLong(field), (long) expectedValue);
|
||||
assertEquals(pos.getIndex(), input.length());
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="parseChronoLocalDate")
|
||||
Object[][] provider_chronoLocalDate() {
|
||||
return new Object[][] {
|
||||
{ HijrahDate.now() },
|
||||
{ JapaneseDate.now() },
|
||||
{ MinguoDate.now() },
|
||||
{ ThaiBuddhistDate.now() }};
|
||||
}
|
||||
|
||||
private static final DateTimeFormatter fmt_chrono =
|
||||
new DateTimeFormatterBuilder()
|
||||
.optionalStart()
|
||||
.appendChronologyId()
|
||||
.appendLiteral(' ')
|
||||
.optionalEnd()
|
||||
.optionalStart()
|
||||
.appendText(ChronoField.ERA, TextStyle.SHORT)
|
||||
.appendLiteral(' ')
|
||||
.optionalEnd()
|
||||
.appendValue(ChronoField.YEAR_OF_ERA, 1, 9, SignStyle.NORMAL)
|
||||
.appendLiteral('-')
|
||||
.appendValue(ChronoField.MONTH_OF_YEAR, 1, 2, SignStyle.NEVER)
|
||||
.appendLiteral('-')
|
||||
.appendValue(ChronoField.DAY_OF_MONTH, 1, 2, SignStyle.NEVER)
|
||||
.toFormatter();
|
||||
|
||||
@Test(dataProvider="parseChronoLocalDate")
|
||||
public void test_chronoLocalDate(ChronoLocalDate date) throws Exception {
|
||||
System.out.printf(" %s, [fmt=%s]%n", date, fmt_chrono.format(date));
|
||||
assertEquals(date, fmt_chrono.parse(fmt_chrono.format(date), ChronoLocalDate::from));
|
||||
|
||||
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("[GGG ]yyy-MM-dd")
|
||||
.withChronology(date.getChronology());
|
||||
System.out.printf(" %s, [fmt=%s]%n", date.toString(), fmt.format(date));
|
||||
assertEquals(date, fmt.parse(fmt.format(date), ChronoLocalDate::from));
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -84,8 +84,6 @@ import test.java.time.temporal.MockFieldValue;
|
||||
*/
|
||||
@Test
|
||||
public class TestTextPrinter extends AbstractTestPrinterParser {
|
||||
static final Locale RUSSIAN = new Locale("ru");
|
||||
static final Locale FINNISH = new Locale("fi");
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@ -213,32 +211,6 @@ public class TestTextPrinter extends AbstractTestPrinterParser {
|
||||
{Locale.US, "e", "1", DayOfWeek.SUNDAY},
|
||||
{Locale.US, "ee", "01", DayOfWeek.SUNDAY},
|
||||
{Locale.US, "c", "1", DayOfWeek.SUNDAY},
|
||||
|
||||
{Locale.UK, "e", "1", DayOfWeek.MONDAY},
|
||||
{Locale.UK, "ee", "01", DayOfWeek.MONDAY},
|
||||
{Locale.UK, "c", "1", DayOfWeek.MONDAY},
|
||||
};
|
||||
}
|
||||
|
||||
@DataProvider(name="print_JapaneseChronology")
|
||||
Object[][] provider_japaneseEra() {
|
||||
return new Object[][] {
|
||||
{ERA, TextStyle.FULL, 2, "Heisei"}, // Note: CLDR doesn't define "wide" Japanese era names.
|
||||
{ERA, TextStyle.SHORT, 2, "Heisei"},
|
||||
{ERA, TextStyle.NARROW, 2, "H"},
|
||||
};
|
||||
};
|
||||
|
||||
// Test data is dependent on localized resources.
|
||||
@DataProvider(name="print_standalone")
|
||||
Object[][] provider_StandaloneNames() {
|
||||
return new Object[][] {
|
||||
// standalone names for 2013-01-01 (Tue)
|
||||
// Locale, TemporalField, TextStyle, expected text
|
||||
{RUSSIAN, MONTH_OF_YEAR, TextStyle.FULL_STANDALONE, "\u044f\u043d\u0432\u0430\u0440\u044c"},
|
||||
{RUSSIAN, MONTH_OF_YEAR, TextStyle.SHORT_STANDALONE, "\u044f\u043d\u0432."},
|
||||
{FINNISH, DAY_OF_WEEK, TextStyle.FULL_STANDALONE, "tiistai"},
|
||||
{FINNISH, DAY_OF_WEEK, TextStyle.SHORT_STANDALONE, "ti"},
|
||||
};
|
||||
}
|
||||
|
||||
@ -255,30 +227,6 @@ public class TestTextPrinter extends AbstractTestPrinterParser {
|
||||
assertEquals(text, expected);
|
||||
}
|
||||
|
||||
@Test(dataProvider="print_JapaneseChronology")
|
||||
public void test_formatJapaneseEra(TemporalField field, TextStyle style, int value, String expected) throws Exception {
|
||||
LocalDate ld = LocalDate.of(2013, 1, 31);
|
||||
getFormatter(field, style).withChronology(JapaneseChronology.INSTANCE).formatTo(ld, buf);
|
||||
assertEquals(buf.toString(), expected);
|
||||
}
|
||||
|
||||
@Test(dataProvider="print_standalone")
|
||||
public void test_standaloneNames(Locale locale, TemporalField field, TextStyle style, String expected) {
|
||||
getFormatter(field, style).withLocale(locale).formatTo(LocalDate.of(2013, 1, 1), buf);
|
||||
assertEquals(buf.toString(), expected);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
public void test_print_french_long() throws Exception {
|
||||
getFormatter(MONTH_OF_YEAR, TextStyle.FULL).withLocale(Locale.FRENCH).formatTo(LocalDate.of(2012, 1, 1), buf);
|
||||
assertEquals(buf.toString(), "janvier");
|
||||
}
|
||||
|
||||
public void test_print_french_short() throws Exception {
|
||||
getFormatter(MONTH_OF_YEAR, TextStyle.SHORT).withLocale(Locale.FRENCH).formatTo(LocalDate.of(2012, 1, 1), buf);
|
||||
assertEquals(buf.toString(), "janv.");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
public void test_toString1() throws Exception {
|
||||
assertEquals(getFormatter(MONTH_OF_YEAR, TextStyle.FULL).toString(), "Text(MonthOfYear)");
|
||||
|
@ -0,0 +1,163 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is available under and governed by the GNU General Public
|
||||
* License version 2 only, as published by the Free Software Foundation.
|
||||
* However, the following notice accompanied the original version of this
|
||||
* file:
|
||||
*
|
||||
* Copyright (c) 2008-2012, Stephen Colebourne & Michael Nascimento Santos
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of JSR-310 nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @modules jdk.localedata
|
||||
*/
|
||||
|
||||
package test.java.time.format;
|
||||
|
||||
import static java.time.temporal.ChronoField.DAY_OF_MONTH;
|
||||
import static java.time.temporal.ChronoField.DAY_OF_WEEK;
|
||||
import static java.time.temporal.ChronoField.ERA;
|
||||
import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
|
||||
import static java.time.temporal.IsoFields.QUARTER_OF_YEAR;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.time.DateTimeException;
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.LocalDate;
|
||||
import java.time.chrono.JapaneseChronology;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.TextStyle;
|
||||
import java.time.temporal.TemporalField;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import test.java.time.temporal.MockFieldValue;
|
||||
|
||||
/**
|
||||
* Test TextPrinterParserWithLocale.
|
||||
*/
|
||||
@Test
|
||||
public class TestTextPrinterWithLocale extends AbstractTestPrinterParser {
|
||||
static final Locale RUSSIAN = new Locale("ru");
|
||||
static final Locale FINNISH = new Locale("fi");
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="print_DayOfWeekData")
|
||||
Object[][] providerDayOfWeekData() {
|
||||
return new Object[][] {
|
||||
// Locale, pattern, expected text, input DayOfWeek
|
||||
{Locale.US, "e", "1", DayOfWeek.SUNDAY},
|
||||
{Locale.US, "ee", "01", DayOfWeek.SUNDAY},
|
||||
{Locale.US, "c", "1", DayOfWeek.SUNDAY},
|
||||
|
||||
{Locale.UK, "e", "1", DayOfWeek.MONDAY},
|
||||
{Locale.UK, "ee", "01", DayOfWeek.MONDAY},
|
||||
{Locale.UK, "c", "1", DayOfWeek.MONDAY},
|
||||
};
|
||||
}
|
||||
|
||||
// Test data is dependent on localized resources.
|
||||
@DataProvider(name="print_standalone")
|
||||
Object[][] provider_StandaloneNames() {
|
||||
return new Object[][] {
|
||||
// standalone names for 2013-01-01 (Tue)
|
||||
// Locale, TemporalField, TextStyle, expected text
|
||||
{RUSSIAN, MONTH_OF_YEAR, TextStyle.FULL_STANDALONE, "\u044f\u043d\u0432\u0430\u0440\u044c"},
|
||||
{RUSSIAN, MONTH_OF_YEAR, TextStyle.SHORT_STANDALONE, "\u044f\u043d\u0432."},
|
||||
{FINNISH, DAY_OF_WEEK, TextStyle.FULL_STANDALONE, "tiistai"},
|
||||
{FINNISH, DAY_OF_WEEK, TextStyle.SHORT_STANDALONE, "ti"},
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="print_DayOfWeekData")
|
||||
public void test_formatDayOfWeek(Locale locale, String pattern, String expected, DayOfWeek dayOfWeek) {
|
||||
DateTimeFormatter formatter = getPatternFormatter(pattern).withLocale(locale);
|
||||
String text = formatter.format(dayOfWeek);
|
||||
assertEquals(text, expected);
|
||||
}
|
||||
|
||||
@Test(dataProvider="print_standalone")
|
||||
public void test_standaloneNames(Locale locale, TemporalField field, TextStyle style, String expected) {
|
||||
getFormatter(field, style).withLocale(locale).formatTo(LocalDate.of(2013, 1, 1), buf);
|
||||
assertEquals(buf.toString(), expected);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
public void test_print_french_long() throws Exception {
|
||||
getFormatter(MONTH_OF_YEAR, TextStyle.FULL).withLocale(Locale.FRENCH).formatTo(LocalDate.of(2012, 1, 1), buf);
|
||||
assertEquals(buf.toString(), "janvier");
|
||||
}
|
||||
|
||||
public void test_print_french_short() throws Exception {
|
||||
getFormatter(MONTH_OF_YEAR, TextStyle.SHORT).withLocale(Locale.FRENCH).formatTo(LocalDate.of(2012, 1, 1), buf);
|
||||
assertEquals(buf.toString(), "janv.");
|
||||
}
|
||||
|
||||
@DataProvider(name="print_JapaneseChronology")
|
||||
Object[][] provider_japaneseEra() {
|
||||
return new Object[][] {
|
||||
{ERA, TextStyle.FULL, 2, "Heisei"}, // Note: CLDR doesn't define "wide" Japanese era names.
|
||||
{ERA, TextStyle.SHORT, 2, "Heisei"},
|
||||
{ERA, TextStyle.NARROW, 2, "H"},
|
||||
};
|
||||
};
|
||||
|
||||
@Test(dataProvider="print_JapaneseChronology")
|
||||
public void test_formatJapaneseEra(TemporalField field, TextStyle style, int value, String expected) throws Exception {
|
||||
LocalDate ld = LocalDate.of(2013, 1, 31);
|
||||
getFormatter(field, style).withChronology(JapaneseChronology.INSTANCE).formatTo(ld, buf);
|
||||
assertEquals(buf.toString(), expected);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user