64
64
* @author Juergen Hoeller
65
65
* @author Phillip Webb
66
66
* @author Sam Brannen
67
+ * @author Kazuki Shimizu
67
68
*/
68
69
class DateTimeFormattingTests {
69
70
@@ -467,6 +468,16 @@ void testBindYearMonth() {
467
468
assertThat (binder .getBindingResult ().getFieldValue ("yearMonth" ).toString ().equals ("2007-12" )).isTrue ();
468
469
}
469
470
471
+ @ Test
472
+ public void testBindYearMonthAnnotatedPattern () {
473
+ MutablePropertyValues propertyValues = new MutablePropertyValues ();
474
+ propertyValues .add ("yearMonthAnnotatedPattern" , "12/2007" );
475
+ binder .bind (propertyValues );
476
+ assertThat (binder .getBindingResult ().getErrorCount ()).isEqualTo (0 );
477
+ assertThat (binder .getBindingResult ().getFieldValue ("yearMonthAnnotatedPattern" )).isEqualTo ("12/2007" );
478
+ assertThat (binder .getBindingResult ().getRawFieldValue ("yearMonthAnnotatedPattern" )).isEqualTo (YearMonth .parse ("2007-12" ));
479
+ }
480
+
470
481
@ Test
471
482
void testBindMonthDay () {
472
483
MutablePropertyValues propertyValues = new MutablePropertyValues ();
@@ -476,6 +487,16 @@ void testBindMonthDay() {
476
487
assertThat (binder .getBindingResult ().getFieldValue ("monthDay" ).toString ().equals ("--12-03" )).isTrue ();
477
488
}
478
489
490
+ @ Test
491
+ public void testBindMonthDayAnnotatedPattern () {
492
+ MutablePropertyValues propertyValues = new MutablePropertyValues ();
493
+ propertyValues .add ("monthDayAnnotatedPattern" , "1/3" );
494
+ binder .bind (propertyValues );
495
+ assertThat (binder .getBindingResult ().getErrorCount ()).isEqualTo (0 );
496
+ assertThat (binder .getBindingResult ().getFieldValue ("monthDayAnnotatedPattern" )).isEqualTo ("1/3" );
497
+ assertThat (binder .getBindingResult ().getRawFieldValue ("monthDayAnnotatedPattern" )).isEqualTo (MonthDay .parse ("--01-03" ));
498
+ }
499
+
479
500
@ Nested
480
501
class FallbackPatternTests {
481
502
@@ -611,8 +632,14 @@ public static class DateTimeBean {
611
632
612
633
private YearMonth yearMonth ;
613
634
635
+ @ DateTimeFormat (pattern ="MM/uuuu" )
636
+ private YearMonth yearMonthAnnotatedPattern ;
637
+
614
638
private MonthDay monthDay ;
615
639
640
+ @ DateTimeFormat (pattern ="M/d" )
641
+ private MonthDay monthDayAnnotatedPattern ;
642
+
616
643
private final List <DateTimeBean > children = new ArrayList <>();
617
644
618
645
@@ -775,6 +802,14 @@ public void setYearMonth(YearMonth yearMonth) {
775
802
this .yearMonth = yearMonth ;
776
803
}
777
804
805
+ public YearMonth getYearMonthAnnotatedPattern () {
806
+ return yearMonthAnnotatedPattern ;
807
+ }
808
+
809
+ public void setYearMonthAnnotatedPattern (YearMonth yearMonthAnnotatedPattern ) {
810
+ this .yearMonthAnnotatedPattern = yearMonthAnnotatedPattern ;
811
+ }
812
+
778
813
public MonthDay getMonthDay () {
779
814
return this .monthDay ;
780
815
}
@@ -783,6 +818,14 @@ public void setMonthDay(MonthDay monthDay) {
783
818
this .monthDay = monthDay ;
784
819
}
785
820
821
+ public MonthDay getMonthDayAnnotatedPattern () {
822
+ return monthDayAnnotatedPattern ;
823
+ }
824
+
825
+ public void setMonthDayAnnotatedPattern (MonthDay monthDayAnnotatedPattern ) {
826
+ this .monthDayAnnotatedPattern = monthDayAnnotatedPattern ;
827
+ }
828
+
786
829
public List <DateTimeBean > getChildren () {
787
830
return this .children ;
788
831
}
0 commit comments