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 import java.text.SimpleDateFormat;
25 import java.time.chrono.JapaneseChronology;
26 import java.time.chrono.JapaneseDate;
27 import java.time.chrono.JapaneseEra;
28 import java.time.format.DateTimeFormatterBuilder;
29 import java.time.format.TextStyle;
30 import java.util.Calendar;
31 import java.util.Date;
32 import java.util.GregorianCalendar;
33 import static java.util.GregorianCalendar.*;
34 import java.util.Locale;
35 import java.util.TimeZone;
36
37 /*
38 * Usage:
39 * java SupplementalJapaneseEraTest <flag>
40 * <flag>
41 * -s prints start time for a test era
42 * -e prints the English name of the last predefined era
43 *
44 * java -Djdk.calendar.japanese.supplemental.era=... SupplementalJapaneseEraTest <flag>
45 * -t executes tests with a valid property value
46 * -b <eraname>
47 * executes tests with an invalid property value
48 * <eraname> must be the output with -e
149 if (!NEW_ERA_NAME.equals(got)) {
150 System.err.printf("JapaneseEra (FULL): got=\"%s\", expected=\"%s\"%n", got, NEW_ERA_NAME);
151 errors++;
152 }
153 got = jera.getDisplayName(TextStyle.SHORT, Locale.US);
154 if (!NEW_ERA_NAME.equals(got)) {
155 System.err.printf("JapaneseEra (SHORT): got=\"%s\", expected=\"%s\"%n", got, NEW_ERA_NAME);
156 errors++;
157 }
158 got = jera.getDisplayName(TextStyle.NARROW, Locale.US);
159 if (!NEW_ERA_ABBR.equals(got)) {
160 System.err.printf("JapaneseEra (NARROW): got=\"%s\", expected=\"%s\"%n", got, NEW_ERA_ABBR);
161 errors++;
162 }
163 got = jera.getDisplayName(TextStyle.NARROW_STANDALONE, Locale.US);
164 if (!NEW_ERA_ABBR.equals(got)) {
165 System.err.printf("JapaneseEra (NARROW_STANDALONE): got=\"%s\", expected=\"%s\"%n", got, NEW_ERA_ABBR);
166 errors++;
167 }
168
169 // test long/abbreviated names with java.time.format
170 got = new DateTimeFormatterBuilder()
171 .appendPattern("GGGG")
172 .appendLiteral(" ")
173 .appendPattern("G")
174 .toFormatter(Locale.US)
175 .withChronology(JapaneseChronology.INSTANCE)
176 .format(jdate);
177 expected = NEW_ERA_NAME + " " + NEW_ERA_ABBR;
178 if (!expected.equals(got)) {
179 System.err.printf("java.time formatter long/abbr names: got=\"%s\", expected=\"%s\"%n", got, expected);
180 errors++;
181 }
182 }
183
184 private static void testValidation(String eraName) {
185 Calendar jcal = new Calendar.Builder()
186 .setCalendarType("japanese")
187 .setFields(YEAR, 1, DAY_OF_YEAR, 1)
188 .build();
189 if (!jcal.getDisplayName(ERA, LONG, Locale.US).equals(eraName)) {
190 errors++;
191 String prop = System.getProperty("jdk.calendar.japanese.supplemental.era");
192 System.err.println("Era changed with invalid property: " + prop);
193 }
194 }
195 }
|
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 import java.text.SimpleDateFormat;
25 import java.time.chrono.JapaneseChronology;
26 import java.time.chrono.JapaneseDate;
27 import java.time.chrono.JapaneseEra;
28 import java.time.format.DateTimeFormatter;
29 import java.time.format.TextStyle;
30 import java.util.Calendar;
31 import java.util.Date;
32 import java.util.GregorianCalendar;
33 import static java.util.GregorianCalendar.*;
34 import java.util.Locale;
35 import java.util.TimeZone;
36
37 /*
38 * Usage:
39 * java SupplementalJapaneseEraTest <flag>
40 * <flag>
41 * -s prints start time for a test era
42 * -e prints the English name of the last predefined era
43 *
44 * java -Djdk.calendar.japanese.supplemental.era=... SupplementalJapaneseEraTest <flag>
45 * -t executes tests with a valid property value
46 * -b <eraname>
47 * executes tests with an invalid property value
48 * <eraname> must be the output with -e
149 if (!NEW_ERA_NAME.equals(got)) {
150 System.err.printf("JapaneseEra (FULL): got=\"%s\", expected=\"%s\"%n", got, NEW_ERA_NAME);
151 errors++;
152 }
153 got = jera.getDisplayName(TextStyle.SHORT, Locale.US);
154 if (!NEW_ERA_NAME.equals(got)) {
155 System.err.printf("JapaneseEra (SHORT): got=\"%s\", expected=\"%s\"%n", got, NEW_ERA_NAME);
156 errors++;
157 }
158 got = jera.getDisplayName(TextStyle.NARROW, Locale.US);
159 if (!NEW_ERA_ABBR.equals(got)) {
160 System.err.printf("JapaneseEra (NARROW): got=\"%s\", expected=\"%s\"%n", got, NEW_ERA_ABBR);
161 errors++;
162 }
163 got = jera.getDisplayName(TextStyle.NARROW_STANDALONE, Locale.US);
164 if (!NEW_ERA_ABBR.equals(got)) {
165 System.err.printf("JapaneseEra (NARROW_STANDALONE): got=\"%s\", expected=\"%s\"%n", got, NEW_ERA_ABBR);
166 errors++;
167 }
168
169 // test full/short/narrow names with java.time.format
170 got = DateTimeFormatter
171 .ofPattern("GGGG G GGGGG")
172 .withLocale(Locale.US)
173 .withChronology(JapaneseChronology.INSTANCE)
174 .format(jdate);
175 expected = NEW_ERA_NAME + " " + NEW_ERA_NAME + " " + NEW_ERA_ABBR;
176 if (!expected.equals(got)) {
177 System.err.printf("java.time formatter full/short/narrow names: got=\"%s\", expected=\"%s\"%n", got, expected);
178 errors++;
179 }
180 }
181
182 private static void testValidation(String eraName) {
183 Calendar jcal = new Calendar.Builder()
184 .setCalendarType("japanese")
185 .setFields(YEAR, 1, DAY_OF_YEAR, 1)
186 .build();
187 if (!jcal.getDisplayName(ERA, LONG, Locale.US).equals(eraName)) {
188 errors++;
189 String prop = System.getProperty("jdk.calendar.japanese.supplemental.era");
190 System.err.println("Era changed with invalid property: " + prop);
191 }
192 }
193 }
|