16
16
17
17
package org .springframework .validation ;
18
18
19
+ import static org .junit .Assert .*;
20
+
19
21
import java .beans .PropertyEditorSupport ;
20
22
import java .util .Map ;
21
23
22
- import junit .framework .TestCase ;
24
+ import org .junit .Rule ;
25
+ import org .junit .Test ;
26
+ import org .junit .rules .ExpectedException ;
23
27
28
+ import org .springframework .beans .NullValueInNestedPathException ;
24
29
import org .springframework .tests .sample .beans .FieldAccessBean ;
25
30
import org .springframework .beans .MutablePropertyValues ;
26
31
import org .springframework .beans .NotWritablePropertyException ;
32
37
* @author Stephane Nicoll
33
38
* @since 07.03.2006
34
39
*/
35
- public class DataBinderFieldAccessTests extends TestCase {
40
+ public class DataBinderFieldAccessTests {
41
+
42
+ @ Rule
43
+ public final ExpectedException thrown = ExpectedException .none ();
36
44
37
- public void testBindingNoErrors () throws Exception {
45
+ @ Test
46
+ public void bindingNoErrors () throws Exception {
38
47
FieldAccessBean rod = new FieldAccessBean ();
39
48
DataBinder binder = new DataBinder (rod , "person" );
40
49
assertTrue (binder .isIgnoreUnknownFields ());
@@ -56,7 +65,8 @@ public void testBindingNoErrors() throws Exception {
56
65
assertTrue ("Same object" , tb .equals (rod ));
57
66
}
58
67
59
- public void testBindingNoErrorsNotIgnoreUnknown () throws Exception {
68
+ @ Test
69
+ public void bindingNoErrorsNotIgnoreUnknown () throws Exception {
60
70
FieldAccessBean rod = new FieldAccessBean ();
61
71
DataBinder binder = new DataBinder (rod , "person" );
62
72
binder .initDirectFieldAccess ();
@@ -75,7 +85,8 @@ public void testBindingNoErrorsNotIgnoreUnknown() throws Exception {
75
85
}
76
86
}
77
87
78
- public void testBindingWithErrors () throws Exception {
88
+ @ Test
89
+ public void bindingWithErrors () throws Exception {
79
90
FieldAccessBean rod = new FieldAccessBean ();
80
91
DataBinder binder = new DataBinder (rod , "person" );
81
92
binder .initDirectFieldAccess ();
@@ -110,7 +121,8 @@ public void testBindingWithErrors() throws Exception {
110
121
}
111
122
}
112
123
113
- public void testedNestedBindingWithDefaultConversionNoErrors () throws Exception {
124
+ @ Test
125
+ public void nestedBindingWithDefaultConversionNoErrors () throws Exception {
114
126
FieldAccessBean rod = new FieldAccessBean ();
115
127
DataBinder binder = new DataBinder (rod , "person" );
116
128
assertTrue (binder .isIgnoreUnknownFields ());
@@ -126,7 +138,21 @@ public void testedNestedBindingWithDefaultConversionNoErrors() throws Exception
126
138
assertTrue ((rod .getSpouse ()).isJedi ());
127
139
}
128
140
129
- public void testBindingWithErrorsAndCustomEditors () throws Exception {
141
+ @ Test
142
+ public void nestedBindingWithDisabledAutoGrow () throws Exception {
143
+ FieldAccessBean rod = new FieldAccessBean ();
144
+ DataBinder binder = new DataBinder (rod , "person" );
145
+ binder .setAutoGrowNestedPaths (false );
146
+ binder .initDirectFieldAccess ();
147
+ MutablePropertyValues pvs = new MutablePropertyValues ();
148
+ pvs .addPropertyValue (new PropertyValue ("spouse.name" , "Kerry" ));
149
+
150
+ thrown .expect (NullValueInNestedPathException .class );
151
+ binder .bind (pvs );
152
+ }
153
+
154
+ @ Test
155
+ public void bindingWithErrorsAndCustomEditors () throws Exception {
130
156
FieldAccessBean rod = new FieldAccessBean ();
131
157
DataBinder binder = new DataBinder (rod , "person" );
132
158
binder .initDirectFieldAccess ();
0 commit comments