Author: mgrigorov Date: Sat May 7 15:51:38 2011 New Revision: 1100560 URL: http://svn.apache.org/viewvc?rev=1100560&view=rev Log: WICKET-3658 Add converter for Calendar class
Make the type of the delegate converter more flexible Modified: wicket/trunk/wicket-datetime/src/test/java/org/apache/wicket/datetime/DateConverterTest.java wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/convert/converter/CalendarConverter.java Modified: wicket/trunk/wicket-datetime/src/test/java/org/apache/wicket/datetime/DateConverterTest.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-datetime/src/test/java/org/apache/wicket/datetime/DateConverterTest.java?rev=1100560&r1=1100559&r2=1100560&view=diff ============================================================================== --- wicket/trunk/wicket-datetime/src/test/java/org/apache/wicket/datetime/DateConverterTest.java (original) +++ wicket/trunk/wicket-datetime/src/test/java/org/apache/wicket/datetime/DateConverterTest.java Sat May 7 15:51:38 2011 @@ -19,6 +19,7 @@ package org.apache.wicket.datetime; import java.util.Calendar; import java.util.Locale; +import org.apache.wicket.util.convert.converter.CalendarConverter; import org.joda.time.format.DateTimeFormatter; import org.junit.Assert; import org.junit.Test; @@ -56,4 +57,30 @@ public class DateConverterTest Assert.assertEquals(expected, actual); } + + /** + * WICKET-3658 + */ + @Test + public void testCalendarConverterWithDelegate() + { + Locale locale = Locale.GERMAN; + + Calendar input = Calendar.getInstance(locale); + input.clear(); + input.set(2011, Calendar.MAY, 7); + + StyleDateConverter styleDateConverter = new StyleDateConverter("F-", false); + + CalendarConverter calendarConverter = new CalendarConverter(styleDateConverter); + + String expected = styleDateConverter.convertToString(input.getTime(), locale); + String actual = calendarConverter.convertToString(input, locale); + + Assert.assertEquals(expected, actual); + + Calendar revert = calendarConverter.convertToObject(actual, locale); + + Assert.assertEquals(input, revert); + } } Modified: wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/convert/converter/CalendarConverter.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/convert/converter/CalendarConverter.java?rev=1100560&r1=1100559&r2=1100560&view=diff ============================================================================== --- wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/convert/converter/CalendarConverter.java (original) +++ wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/convert/converter/CalendarConverter.java Sat May 7 15:51:38 2011 @@ -30,7 +30,7 @@ public class CalendarConverter implement { private static final long serialVersionUID = 1L; - private final DateConverter dateConverter; + private final IConverter<Date> dateConverter; /** * Construct. @@ -46,7 +46,7 @@ public class CalendarConverter implement * @param dateConverter * delegated converter, not null */ - public CalendarConverter(DateConverter dateConverter) + public CalendarConverter(IConverter<Date> dateConverter) { Args.notNull(dateConverter, "dateConverter");