From 91dcac26f683314d176a7763f53dad158c36e3df Mon Sep 17 00:00:00 2001 From: Leonid Rozenblyum Date: Wed, 4 Nov 2015 12:18:46 +0200 Subject: Specify custom first day of week for Calendar #19227 Added possibility to provide first day of week independent of Locale. (the Calendar code has been reformatted according to Eclipse 'Save action'). Unit-tests added. UI test extended. Change-Id: I3e3531228c139ce2014a1227e47c12e7896a6f87 --- .../component/calendar/CalendarBasicsTest.java | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'server/tests') diff --git a/server/tests/src/com/vaadin/tests/server/component/calendar/CalendarBasicsTest.java b/server/tests/src/com/vaadin/tests/server/component/calendar/CalendarBasicsTest.java index 95b4aecdb3..1592fb6c38 100644 --- a/server/tests/src/com/vaadin/tests/server/component/calendar/CalendarBasicsTest.java +++ b/server/tests/src/com/vaadin/tests/server/component/calendar/CalendarBasicsTest.java @@ -216,6 +216,60 @@ public class CalendarBasicsTest { calendar.isClientChangeAllowed()); } + // regression test to ensure old functionality is not broken + @Test + public void defaultFirstDayOfWeek() { + Calendar calendar = new Calendar(); + calendar.setLocale(Locale.GERMAN); + // simulating consequences of markAsDirty + calendar.beforeClientResponse(true); + assertEquals(java.util.Calendar.MONDAY, calendar.getInternalCalendar() + .getFirstDayOfWeek()); + } + + @Test + public void customFirstDayOfWeek() { + Calendar calendar = new Calendar(); + calendar.setLocale(Locale.GERMAN); + calendar.setFirstDayOfWeek(java.util.Calendar.SUNDAY); + + // simulating consequences of markAsDirty + calendar.beforeClientResponse(true); + assertEquals(java.util.Calendar.SUNDAY, calendar.getInternalCalendar() + .getFirstDayOfWeek()); + } + + @Test + public void customFirstDayOfWeekCanSetEvenBeforeLocale() { + Calendar calendar = new Calendar(); + calendar.setFirstDayOfWeek(java.util.Calendar.SUNDAY); + + calendar.setLocale(Locale.GERMAN); + // simulating consequences of markAsDirty + calendar.beforeClientResponse(true); + assertEquals(java.util.Calendar.SUNDAY, calendar.getInternalCalendar() + .getFirstDayOfWeek()); + } + + @Test + public void customFirstDayOfWeekSetNullRestoresDefault() { + Calendar calendar = new Calendar(); + calendar.setLocale(Locale.GERMAN); + calendar.setFirstDayOfWeek(java.util.Calendar.SUNDAY); + calendar.setFirstDayOfWeek(null); + // simulating consequences of markAsDirty + calendar.beforeClientResponse(true); + assertEquals(java.util.Calendar.MONDAY, calendar.getInternalCalendar() + .getFirstDayOfWeek()); + } + + @Test(expected = IllegalArgumentException.class) + public void customFirstDayOfWeekValidation() { + Calendar calendar = new Calendar(); + int someWrongDayOfWeek = 10; + calendar.setFirstDayOfWeek(someWrongDayOfWeek); + } + private static class TestCalendar extends Calendar { TestCalendar(boolean connectorEnabled) { isConnectorEnabled = connectorEnabled; -- cgit v1.2.3