|
1 | 1 | /* |
2 | | - * Copyright 2002-2011 the original author or authors. |
| 2 | + * Copyright 2002-2012 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
16 | 16 |
|
17 | 17 | package org.springframework.format.datetime.joda; |
18 | 18 |
|
19 | | -import static org.junit.Assert.assertEquals; |
20 | | - |
21 | 19 | import java.util.ArrayList; |
22 | 20 | import java.util.Calendar; |
23 | 21 | import java.util.Date; |
|
34 | 32 | import org.junit.After; |
35 | 33 | import org.junit.Before; |
36 | 34 | import org.junit.Test; |
| 35 | + |
37 | 36 | import org.springframework.beans.MutablePropertyValues; |
38 | 37 | import org.springframework.context.i18n.LocaleContextHolder; |
39 | 38 | import org.springframework.core.convert.support.DefaultConversionService; |
|
42 | 41 | import org.springframework.format.support.FormattingConversionService; |
43 | 42 | import org.springframework.validation.DataBinder; |
44 | 43 |
|
| 44 | +import static org.junit.Assert.*; |
| 45 | + |
45 | 46 | /** |
46 | 47 | * @author Keith Donald |
47 | 48 | * @author Juergen Hoeller |
@@ -96,7 +97,7 @@ public void testBindLocalDate() { |
96 | 97 | @Test |
97 | 98 | public void testBindLocalDateArray() { |
98 | 99 | MutablePropertyValues propertyValues = new MutablePropertyValues(); |
99 | | - propertyValues.add("localDate", new String[] {"10/31/09"}); |
| 100 | + propertyValues.add("localDate", new String[]{"10/31/09"}); |
100 | 101 | binder.bind(propertyValues); |
101 | 102 | assertEquals(0, binder.getBindingResult().getErrorCount()); |
102 | 103 | } |
@@ -240,6 +241,24 @@ public void testBindDate() { |
240 | 241 | assertEquals("10/31/09 12:00 PM", binder.getBindingResult().getFieldValue("date")); |
241 | 242 | } |
242 | 243 |
|
| 244 | + @Test |
| 245 | + public void testBindDateWithErrorAvoidingDateConstructor() { |
| 246 | + MutablePropertyValues propertyValues = new MutablePropertyValues(); |
| 247 | + propertyValues.add("date", "Sat, 12 Aug 1995 13:30:00 GMT"); |
| 248 | + binder.bind(propertyValues); |
| 249 | + assertEquals(1, binder.getBindingResult().getErrorCount()); |
| 250 | + assertEquals("Sat, 12 Aug 1995 13:30:00 GMT", binder.getBindingResult().getFieldValue("date")); |
| 251 | + } |
| 252 | + |
| 253 | + @Test |
| 254 | + public void testBindDateWithoutErrorFallingBackToDateConstructor() { |
| 255 | + DataBinder binder = new DataBinder(new JodaTimeBean()); |
| 256 | + MutablePropertyValues propertyValues = new MutablePropertyValues(); |
| 257 | + propertyValues.add("date", "Sat, 12 Aug 1995 13:30:00 GMT"); |
| 258 | + binder.bind(propertyValues); |
| 259 | + assertEquals(0, binder.getBindingResult().getErrorCount()); |
| 260 | + } |
| 261 | + |
243 | 262 | @Test |
244 | 263 | public void testBindDateAnnotated() { |
245 | 264 | MutablePropertyValues propertyValues = new MutablePropertyValues(); |
|
0 commit comments