/* * Copyright (c) 2010, 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.
*/
/* * @test * @bug 4267450 * @summary Unit test for week date support
*/
// Test getWeeksInWeekYear(). // If we avoid the first week of January and the last week of // December, getWeeksInWeekYear() and // getActualMaximum(WEEK_OF_YEAR) values should be the same. for (int year = 2000; year <= 2100; year++) {
cal.clear();
cal.set(year, JUNE, 1); int n = cal.getWeeksInWeekYear(); if (n != cal.getActualMaximum(WEEK_OF_YEAR)) {
String s = String.format("getWeeksInWeekYear() = %d, "
+ "getActualMaximum(WEEK_OF_YEAR) = %d%n",
n, cal.getActualMaximum(WEEK_OF_YEAR)); thrownew RuntimeException(s);
}
cal.setWeekDate(cal.getWeekYear(), n, SUNDAY); if (cal.getWeeksInWeekYear() != n) {
String s = String.format("last day: got %d, expected %d%n",
cal.getWeeksInWeekYear(), n); thrownew RuntimeException(s);
}
}
// Test lenient mode with out of range values. for (int[][] dates : leniencyData) { int[] expected = dates[0]; int[] weekDate = dates[1]; // Convert ISO 8601 day-of-week to Calendar.DAY_OF_WEEK. int dayOfWeek = getCalendarDayOfWeek(weekDate[2]);
// Test non-lenient mode
cal.setLenient(false); for (int[] date : invalidData) {
cal.clear(); try { // Use the raw dayOfWeek value as invalid data
cal.setWeekDate(date[0], date[1], date[2]);
String s = String.format("didn't throw an IllegalArgumentException with"
+ " %d, %d, %d",date[0], date[1], date[2]); thrownew RuntimeException(s);
} catch (IllegalArgumentException e) { // OK
}
}
}
privatestatic GregorianCalendar newCalendar() { // Use GMT to avoid any surprises related DST transitions.
GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT")); if (!cal.isWeekDateSupported()) { thrownew RuntimeException("Week dates not supported");
} // Setup the ISO 8601 compatible parameters
cal.setFirstDayOfWeek(MONDAY);
cal.setMinimalDaysInFirstWeek(4); return cal;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.