52
52
public class PropertyAccessTests extends AbstractExpressionTests {
53
53
54
54
@ Test
55
- public void testSimpleAccess01 () {
55
+ void simpleAccess01 () {
56
56
evaluate ("name" , "Nikola Tesla" , String .class );
57
57
}
58
58
59
59
@ Test
60
- public void testSimpleAccess02 () {
60
+ void simpleAccess02 () {
61
61
evaluate ("placeOfBirth.city" , "SmilJan" , String .class );
62
62
}
63
63
64
64
@ Test
65
- public void testSimpleAccess03 () {
65
+ void simpleAccess03 () {
66
66
evaluate ("stringArrayOfThreeItems.length" , "3" , Integer .class );
67
67
}
68
68
69
69
@ Test
70
- public void testNonExistentPropertiesAndMethods () {
70
+ void nonExistentPropertiesAndMethods () {
71
71
// madeup does not exist as a property
72
72
evaluateAndCheckError ("madeup" , SpelMessage .PROPERTY_OR_FIELD_NOT_READABLE , 0 );
73
73
@@ -80,21 +80,21 @@ public void testNonExistentPropertiesAndMethods() {
80
80
* supplied resolver might be able to - so null shouldn't crash the reflection resolver.
81
81
*/
82
82
@ Test
83
- public void testAccessingOnNullObject () {
84
- SpelExpression expr = (SpelExpression )parser .parseExpression ("madeup" );
83
+ void accessingOnNullObject () {
84
+ SpelExpression expr = (SpelExpression ) parser .parseExpression ("madeup" );
85
85
EvaluationContext context = new StandardEvaluationContext (null );
86
- assertThatExceptionOfType (SpelEvaluationException .class ). isThrownBy (() ->
87
- expr .getValue (context ))
88
- .satisfies ( ex -> assertThat ( ex . getMessageCode ()) .isEqualTo (SpelMessage .PROPERTY_OR_FIELD_NOT_READABLE_ON_NULL ) );
86
+ assertThatExceptionOfType (SpelEvaluationException .class )
87
+ . isThrownBy (() -> expr .getValue (context ))
88
+ .extracting ( SpelEvaluationException :: getMessageCode ) .isEqualTo (SpelMessage .PROPERTY_OR_FIELD_NOT_READABLE_ON_NULL );
89
89
assertThat (expr .isWritable (context )).isFalse ();
90
- assertThatExceptionOfType (SpelEvaluationException .class ). isThrownBy (() ->
91
- expr .setValue (context , "abc" ))
92
- .satisfies ( ex -> assertThat ( ex . getMessageCode ()) .isEqualTo (SpelMessage .PROPERTY_OR_FIELD_NOT_WRITABLE_ON_NULL ) );
90
+ assertThatExceptionOfType (SpelEvaluationException .class )
91
+ . isThrownBy (() -> expr .setValue (context , "abc" ))
92
+ .extracting ( SpelEvaluationException :: getMessageCode ) .isEqualTo (SpelMessage .PROPERTY_OR_FIELD_NOT_WRITABLE_ON_NULL );
93
93
}
94
94
95
95
@ Test
96
96
// Adding a new property accessor just for a particular type
97
- public void testAddingSpecificPropertyAccessor () {
97
+ void addingSpecificPropertyAccessor () {
98
98
SpelExpressionParser parser = new SpelExpressionParser ();
99
99
StandardEvaluationContext ctx = new StandardEvaluationContext ();
100
100
@@ -125,35 +125,34 @@ public void testAddingSpecificPropertyAccessor() {
125
125
}
126
126
127
127
@ Test
128
- public void testAddingRemovingAccessors () {
128
+ void addingAndRemovingAccessors () {
129
129
StandardEvaluationContext ctx = new StandardEvaluationContext ();
130
130
131
131
// reflective property accessor is the only one by default
132
- List <PropertyAccessor > propertyAccessors = ctx .getPropertyAccessors ();
133
- assertThat (propertyAccessors .size ()).isEqualTo (1 );
132
+ assertThat (ctx .getPropertyAccessors ()).hasSize (1 );
134
133
135
134
StringyPropertyAccessor spa = new StringyPropertyAccessor ();
136
135
ctx .addPropertyAccessor (spa );
137
- assertThat (ctx .getPropertyAccessors (). size ()). isEqualTo (2 );
136
+ assertThat (ctx .getPropertyAccessors ()). hasSize (2 );
138
137
139
138
List <PropertyAccessor > copy = new ArrayList <>(ctx .getPropertyAccessors ());
140
139
assertThat (ctx .removePropertyAccessor (spa )).isTrue ();
141
140
assertThat (ctx .removePropertyAccessor (spa )).isFalse ();
142
- assertThat (ctx .getPropertyAccessors (). size ()). isEqualTo (1 );
141
+ assertThat (ctx .getPropertyAccessors ()). hasSize (1 );
143
142
144
143
ctx .setPropertyAccessors (copy );
145
- assertThat (ctx .getPropertyAccessors (). size ()). isEqualTo (2 );
144
+ assertThat (ctx .getPropertyAccessors ()). hasSize (2 );
146
145
}
147
146
148
147
@ Test
149
- public void testAccessingPropertyOfClass () {
148
+ void accessingPropertyOfClass () {
150
149
Expression expression = parser .parseExpression ("name" );
151
150
Object value = expression .getValue (new StandardEvaluationContext (String .class ));
152
151
assertThat (value ).isEqualTo ("java.lang.String" );
153
152
}
154
153
155
154
@ Test
156
- public void shouldAlwaysUsePropertyAccessorFromEvaluationContext () {
155
+ void shouldAlwaysUsePropertyAccessorFromEvaluationContext () {
157
156
SpelExpressionParser parser = new SpelExpressionParser ();
158
157
Expression expression = parser .parseExpression ("name" );
159
158
@@ -167,19 +166,19 @@ public void shouldAlwaysUsePropertyAccessorFromEvaluationContext() {
167
166
}
168
167
169
168
@ Test
170
- public void standardGetClassAccess () {
169
+ void standardGetClassAccess () {
171
170
assertThat (parser .parseExpression ("'a'.class.name" ).getValue ()).isEqualTo (String .class .getName ());
172
171
}
173
172
174
173
@ Test
175
- public void noGetClassAccess () {
174
+ void noGetClassAccess () {
176
175
EvaluationContext context = SimpleEvaluationContext .forReadOnlyDataBinding ().build ();
177
176
assertThatExceptionOfType (SpelEvaluationException .class ).isThrownBy (() ->
178
177
parser .parseExpression ("'a'.class.name" ).getValue (context ));
179
178
}
180
179
181
180
@ Test
182
- public void propertyReadOnly () {
181
+ void propertyReadOnly () {
183
182
EvaluationContext context = SimpleEvaluationContext .forReadOnlyDataBinding ().build ();
184
183
185
184
Expression expr = parser .parseExpression ("name" );
@@ -193,7 +192,7 @@ public void propertyReadOnly() {
193
192
}
194
193
195
194
@ Test
196
- public void propertyReadOnlyWithRecordStyle () {
195
+ void propertyReadOnlyWithRecordStyle () {
197
196
EvaluationContext context = SimpleEvaluationContext .forReadOnlyDataBinding ().build ();
198
197
199
198
Expression expr = parser .parseExpression ("name" );
@@ -207,7 +206,7 @@ public void propertyReadOnlyWithRecordStyle() {
207
206
}
208
207
209
208
@ Test
210
- public void propertyReadWrite () {
209
+ void propertyReadWrite () {
211
210
EvaluationContext context = SimpleEvaluationContext .forReadWriteDataBinding ().build ();
212
211
213
212
Expression expr = parser .parseExpression ("name" );
@@ -226,42 +225,42 @@ public void propertyReadWrite() {
226
225
}
227
226
228
227
@ Test
229
- public void propertyReadWriteWithRootObject () {
230
- Person target = new Person ("p1" );
231
- EvaluationContext context = SimpleEvaluationContext .forReadWriteDataBinding ().withRootObject (target ).build ();
232
- assertThat (context .getRootObject ().getValue ()).isSameAs (target );
228
+ void propertyReadWriteWithRootObject () {
229
+ Person rootObject = new Person ("p1" );
230
+ EvaluationContext context = SimpleEvaluationContext .forReadWriteDataBinding ().withRootObject (rootObject ).build ();
231
+ assertThat (context .getRootObject ().getValue ()).isSameAs (rootObject );
233
232
234
233
Expression expr = parser .parseExpression ("name" );
235
234
assertThat (expr .getValue (context )).isEqualTo ("p1" );
236
- target .setName ("p2" );
235
+ rootObject .setName ("p2" );
237
236
assertThat (expr .getValue (context )).isEqualTo ("p2" );
238
237
239
- parser .parseExpression ("name='p3'" ).getValue (context , target );
240
- assertThat (target .getName ()).isEqualTo ("p3" );
238
+ parser .parseExpression ("name='p3'" ).getValue (context , rootObject );
239
+ assertThat (rootObject .getName ()).isEqualTo ("p3" );
241
240
assertThat (expr .getValue (context )).isEqualTo ("p3" );
242
241
243
242
expr .setValue (context , "p4" );
244
- assertThat (target .getName ()).isEqualTo ("p4" );
243
+ assertThat (rootObject .getName ()).isEqualTo ("p4" );
245
244
assertThat (expr .getValue (context )).isEqualTo ("p4" );
246
245
}
247
246
248
247
@ Test
249
- public void propertyAccessWithoutMethodResolver () {
248
+ void propertyAccessWithoutMethodResolver () {
250
249
EvaluationContext context = SimpleEvaluationContext .forReadOnlyDataBinding ().build ();
251
250
Person target = new Person ("p1" );
252
251
assertThatExceptionOfType (SpelEvaluationException .class ).isThrownBy (() ->
253
252
parser .parseExpression ("name.substring(1)" ).getValue (context , target ));
254
253
}
255
254
256
255
@ Test
257
- public void propertyAccessWithInstanceMethodResolver () {
256
+ void propertyAccessWithInstanceMethodResolver () {
258
257
EvaluationContext context = SimpleEvaluationContext .forReadOnlyDataBinding ().withInstanceMethods ().build ();
259
258
Person target = new Person ("p1" );
260
259
assertThat (parser .parseExpression ("name.substring(1)" ).getValue (context , target )).isEqualTo ("1" );
261
260
}
262
261
263
262
@ Test
264
- public void propertyAccessWithInstanceMethodResolverAndTypedRootObject () {
263
+ void propertyAccessWithInstanceMethodResolverAndTypedRootObject () {
265
264
Person rootObject = new Person ("p1" );
266
265
EvaluationContext context = SimpleEvaluationContext .forReadOnlyDataBinding ().
267
266
withInstanceMethods ().withTypedRootObject (rootObject , TypeDescriptor .valueOf (Object .class )).build ();
@@ -277,7 +276,7 @@ void propertyAccessWithArrayIndexOutOfBounds() {
277
276
Expression expression = parser .parseExpression ("stringArrayOfThreeItems[3]" );
278
277
assertThatExceptionOfType (SpelEvaluationException .class )
279
278
.isThrownBy (() -> expression .getValue (context , new Inventor ()))
280
- .satisfies ( ex -> assertThat ( ex . getMessageCode ()) .isEqualTo (SpelMessage .ARRAY_INDEX_OUT_OF_BOUNDS ) );
279
+ .extracting ( SpelEvaluationException :: getMessageCode ) .isEqualTo (SpelMessage .ARRAY_INDEX_OUT_OF_BOUNDS );
281
280
}
282
281
283
282
@@ -335,7 +334,7 @@ private static class ConfigurablePropertyAccessor implements PropertyAccessor {
335
334
336
335
private final Map <String , Object > values ;
337
336
338
- public ConfigurablePropertyAccessor (Map <String , Object > values ) {
337
+ ConfigurablePropertyAccessor (Map <String , Object > values ) {
339
338
this .values = values ;
340
339
}
341
340
0 commit comments