Skip to content

Commit d7cfdc6

Browse files
committed
Polish
1 parent 085af10 commit d7cfdc6

37 files changed

+435
-427
lines changed

spring-expression/src/test/java/org/springframework/expression/spel/AbstractExpressionTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public void evaluate(String expression, Object expectedValue, Class<?> expectedR
127127
}
128128
assertThat(expectedValue).as("Expression returned null value, but expected '" + expectedValue + "'").isNull();
129129
}
130-
Class<? extends Object> resultType = value.getClass();
130+
Class<?> resultType = value.getClass();
131131
if (expectedValue instanceof String) {
132132
assertThat(AbstractExpressionTests.stringValueOf(value)).as("Did not get expected value for expression '" + expression + "'.").isEqualTo(expectedValue);
133133
}

spring-expression/src/test/java/org/springframework/expression/spel/BooleanExpressionTests.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,36 +28,36 @@
2828
* @author Andy Clement
2929
* @author Oliver Becker
3030
*/
31-
public class BooleanExpressionTests extends AbstractExpressionTests {
31+
class BooleanExpressionTests extends AbstractExpressionTests {
3232

3333
@Test
34-
public void testBooleanTrue() {
34+
void testBooleanTrue() {
3535
evaluate("true", Boolean.TRUE, Boolean.class);
3636
}
3737

3838
@Test
39-
public void testBooleanFalse() {
39+
void testBooleanFalse() {
4040
evaluate("false", Boolean.FALSE, Boolean.class);
4141
}
4242

4343
@Test
44-
public void testOr() {
44+
void testOr() {
4545
evaluate("false or false", Boolean.FALSE, Boolean.class);
4646
evaluate("false or true", Boolean.TRUE, Boolean.class);
4747
evaluate("true or false", Boolean.TRUE, Boolean.class);
4848
evaluate("true or true", Boolean.TRUE, Boolean.class);
4949
}
5050

5151
@Test
52-
public void testAnd() {
52+
void testAnd() {
5353
evaluate("false and false", Boolean.FALSE, Boolean.class);
5454
evaluate("false and true", Boolean.FALSE, Boolean.class);
5555
evaluate("true and false", Boolean.FALSE, Boolean.class);
5656
evaluate("true and true", Boolean.TRUE, Boolean.class);
5757
}
5858

5959
@Test
60-
public void testNot() {
60+
void testNot() {
6161
evaluate("!false", Boolean.TRUE, Boolean.class);
6262
evaluate("!true", Boolean.FALSE, Boolean.class);
6363

@@ -66,21 +66,21 @@ public void testNot() {
6666
}
6767

6868
@Test
69-
public void testCombinations01() {
69+
void testCombinations01() {
7070
evaluate("false and false or true", Boolean.TRUE, Boolean.class);
7171
evaluate("true and false or true", Boolean.TRUE, Boolean.class);
7272
evaluate("true and false or false", Boolean.FALSE, Boolean.class);
7373
}
7474

7575
@Test
76-
public void testWritability() {
76+
void testWritability() {
7777
evaluate("true and true", Boolean.TRUE, Boolean.class, false);
7878
evaluate("true or true", Boolean.TRUE, Boolean.class, false);
7979
evaluate("!false", Boolean.TRUE, Boolean.class, false);
8080
}
8181

8282
@Test
83-
public void testBooleanErrors01() {
83+
void testBooleanErrors01() {
8484
evaluateAndCheckError("1.0 or false", SpelMessage.TYPE_CONVERSION_ERROR, 0);
8585
evaluateAndCheckError("false or 39.4", SpelMessage.TYPE_CONVERSION_ERROR, 9);
8686
evaluateAndCheckError("true and 'hello'", SpelMessage.TYPE_CONVERSION_ERROR, 9);
@@ -90,7 +90,7 @@ public void testBooleanErrors01() {
9090
}
9191

9292
@Test
93-
public void testConvertAndHandleNull() { // SPR-9445
93+
void testConvertAndHandleNull() { // SPR-9445
9494
// without null conversion
9595
evaluateAndCheckError("null or true", SpelMessage.TYPE_CONVERSION_ERROR, 0, "null", "boolean");
9696
evaluateAndCheckError("null and true", SpelMessage.TYPE_CONVERSION_ERROR, 0, "null", "boolean");

spring-expression/src/test/java/org/springframework/expression/spel/CachedMethodExecutorTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,15 +31,15 @@
3131
*
3232
* @author Oliver Becker
3333
*/
34-
public class CachedMethodExecutorTests {
34+
class CachedMethodExecutorTests {
3535

3636
private final ExpressionParser parser = new SpelExpressionParser();
3737

3838
private final StandardEvaluationContext context = new StandardEvaluationContext(new RootObject());
3939

4040

4141
@Test
42-
public void testCachedExecutionForParameters() {
42+
void testCachedExecutionForParameters() {
4343
Expression expression = this.parser.parseExpression("echo(#var)");
4444

4545
assertMethodExecution(expression, 42, "int: 42");
@@ -49,7 +49,7 @@ public void testCachedExecutionForParameters() {
4949
}
5050

5151
@Test
52-
public void testCachedExecutionForTarget() {
52+
void testCachedExecutionForTarget() {
5353
Expression expression = this.parser.parseExpression("#var.echo(42)");
5454

5555
assertMethodExecution(expression, new RootObject(), "int: 42");

spring-expression/src/test/java/org/springframework/expression/spel/ComparatorTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,7 +37,7 @@
3737
* @author Andy Clement
3838
* @author Giovanni Dall'Oglio Risso
3939
*/
40-
public class ComparatorTests {
40+
class ComparatorTests {
4141

4242
@Test
4343
void testPrimitives() throws EvaluationException {
@@ -126,7 +126,7 @@ void testCanCompare() throws EvaluationException {
126126
}
127127

128128
@Test
129-
public void customComparatorWorksWithEquality() {
129+
void customComparatorWorksWithEquality() {
130130
final StandardEvaluationContext ctx = new StandardEvaluationContext();
131131
ctx.setTypeComparator(customComparator);
132132

spring-expression/src/test/java/org/springframework/expression/spel/ConstructorInvocationTests.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@
2323
import org.junit.jupiter.api.Test;
2424

2525
import org.springframework.core.convert.TypeDescriptor;
26-
import org.springframework.expression.AccessException;
2726
import org.springframework.expression.ConstructorExecutor;
2827
import org.springframework.expression.ConstructorResolver;
2928
import org.springframework.expression.EvaluationContext;
@@ -40,15 +39,15 @@
4039
*
4140
* @author Andy Clement
4241
*/
43-
public class ConstructorInvocationTests extends AbstractExpressionTests {
42+
class ConstructorInvocationTests extends AbstractExpressionTests {
4443

4544
@Test
46-
public void testTypeConstructors() {
45+
void testTypeConstructors() {
4746
evaluate("new String('hello world')", "hello world", String.class);
4847
}
4948

5049
@Test
51-
public void testNonExistentType() {
50+
void testNonExistentType() {
5251
evaluateAndCheckError("new FooBar()", SpelMessage.CONSTRUCTOR_INVOCATION_PROBLEM);
5352
}
5453

@@ -89,7 +88,7 @@ public Tester(PlaceOfBirth pob) {
8988

9089

9190
@Test
92-
public void testConstructorThrowingException_SPR6760() {
91+
void testConstructorThrowingException_SPR6760() {
9392
// Test ctor on inventor:
9493
// On 1 it will throw an IllegalArgumentException
9594
// On 2 it will throw a RuntimeException
@@ -151,7 +150,7 @@ public void testConstructorThrowingException_SPR6760() {
151150
}
152151

153152
@Test
154-
public void testAddingConstructorResolvers() {
153+
void testAddingConstructorResolvers() {
155154
StandardEvaluationContext ctx = new StandardEvaluationContext();
156155

157156
// reflective constructor accessor is the only one by default
@@ -176,15 +175,15 @@ static class DummyConstructorResolver implements ConstructorResolver {
176175

177176
@Override
178177
public ConstructorExecutor resolve(EvaluationContext context, String typeName,
179-
List<TypeDescriptor> argumentTypes) throws AccessException {
178+
List<TypeDescriptor> argumentTypes) {
180179
throw new UnsupportedOperationException("Auto-generated method stub");
181180
}
182181

183182
}
184183

185184

186185
@Test
187-
public void testVarargsInvocation01() {
186+
void testVarargsInvocation01() {
188187
// Calling 'Fruit(String... strings)'
189188
evaluate("new org.springframework.expression.spel.testresources.Fruit('a','b','c').stringscount()", 3,
190189
Integer.class);
@@ -200,7 +199,7 @@ public void testVarargsInvocation01() {
200199
}
201200

202201
@Test
203-
public void testVarargsInvocation02() {
202+
void testVarargsInvocation02() {
204203
// Calling 'Fruit(int i, String... strings)' - returns int+length_of_strings
205204
evaluate("new org.springframework.expression.spel.testresources.Fruit(5,'a','b','c').stringscount()", 8,
206205
Integer.class);
@@ -220,7 +219,7 @@ public void testVarargsInvocation02() {
220219
* the argument in order to satisfy a suitable constructor.
221220
*/
222221
@Test
223-
public void testWidening01() {
222+
void testWidening01() {
224223
// widening of int 3 to double 3 is OK
225224
evaluate("new Double(3)", 3.0d, Double.class);
226225
// widening of int 3 to long 3 is OK

spring-expression/src/test/java/org/springframework/expression/spel/EvaluationTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.math.BigDecimal;
2020
import java.math.BigInteger;
2121
import java.util.ArrayList;
22-
import java.util.Arrays;
2322
import java.util.List;
2423
import java.util.Map;
2524

@@ -336,7 +335,7 @@ void customMethodFilter() {
336335
StandardEvaluationContext context = new StandardEvaluationContext();
337336

338337
// Register a custom MethodResolver...
339-
context.setMethodResolvers(Arrays.asList((evaluationContext, targetObject, name, argumentTypes) -> null));
338+
context.setMethodResolvers(List.of((evaluationContext, targetObject, name, argumentTypes) -> null));
340339

341340
// or simply...
342341
// context.setMethodResolvers(new ArrayList<MethodResolver>());

spring-expression/src/test/java/org/springframework/expression/spel/ExpressionLanguageScenarioTests.java

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,7 +24,6 @@
2424

2525
import org.junit.jupiter.api.Test;
2626

27-
import org.springframework.expression.AccessException;
2827
import org.springframework.expression.EvaluationContext;
2928
import org.springframework.expression.EvaluationException;
3029
import org.springframework.expression.Expression;
@@ -60,13 +59,13 @@
6059
*
6160
* @author Andy Clement
6261
*/
63-
public class ExpressionLanguageScenarioTests extends AbstractExpressionTests {
62+
class ExpressionLanguageScenarioTests extends AbstractExpressionTests {
6463

6564
/**
6665
* Scenario: using the standard infrastructure and running simple expression evaluation.
6766
*/
6867
@Test
69-
public void testScenario_UsingStandardInfrastructure() {
68+
void testScenario_UsingStandardInfrastructure() {
7069
try {
7170
// Create a parser
7271
SpelExpressionParser parser = new SpelExpressionParser();
@@ -89,7 +88,7 @@ public void testScenario_UsingStandardInfrastructure() {
8988
* Scenario: using the standard context but adding your own variables
9089
*/
9190
@Test
92-
public void testScenario_DefiningVariablesThatWillBeAccessibleInExpressions() throws Exception {
91+
void testScenario_DefiningVariablesThatWillBeAccessibleInExpressions() {
9392
// Create a parser
9493
SpelExpressionParser parser = new SpelExpressionParser();
9594
// Use the standard evaluation context
@@ -124,7 +123,7 @@ static class TestClass {
124123
* Scenario: using your own root context object
125124
*/
126125
@Test
127-
public void testScenario_UsingADifferentRootContextObject() throws Exception {
126+
void testScenario_UsingADifferentRootContextObject() {
128127
// Create a parser
129128
SpelExpressionParser parser = new SpelExpressionParser();
130129
// Use the standard evaluation context
@@ -170,7 +169,7 @@ public void testScenario_UsingADifferentRootContextObject() throws Exception {
170169
* Scenario: using your own java methods and calling them from the expression
171170
*/
172171
@Test
173-
public void testScenario_RegisteringJavaMethodsAsFunctionsAndCallingThem() throws SecurityException, NoSuchMethodException {
172+
void testScenario_RegisteringJavaMethodsAsFunctionsAndCallingThem() throws SecurityException, NoSuchMethodException {
174173
try {
175174
// Create a parser
176175
SpelExpressionParser parser = new SpelExpressionParser();
@@ -192,7 +191,7 @@ public void testScenario_RegisteringJavaMethodsAsFunctionsAndCallingThem() throw
192191
* Scenario: looking up your own MethodHandles and calling them from the expression
193192
*/
194193
@Test
195-
public void testScenario_RegisteringJavaMethodsAsMethodHandlesAndCallingThem() throws SecurityException, NoSuchMethodException {
194+
void testScenario_RegisteringJavaMethodsAsMethodHandlesAndCallingThem() throws SecurityException {
196195
try {
197196
// Create a parser
198197
SpelExpressionParser parser = new SpelExpressionParser();
@@ -231,7 +230,7 @@ public void testScenario_RegisteringJavaMethodsAsMethodHandlesAndCallingThem() t
231230
* Scenario: add a property resolver that will get called in the resolver chain, this one only supports reading.
232231
*/
233232
@Test
234-
public void testScenario_AddingYourOwnPropertyResolvers_1() throws Exception {
233+
void testScenario_AddingYourOwnPropertyResolvers_1() {
235234
// Create a parser
236235
SpelExpressionParser parser = new SpelExpressionParser();
237236
// Use the standard evaluation context
@@ -247,7 +246,7 @@ public void testScenario_AddingYourOwnPropertyResolvers_1() throws Exception {
247246
}
248247

249248
@Test
250-
public void testScenario_AddingYourOwnPropertyResolvers_2() throws Exception {
249+
void testScenario_AddingYourOwnPropertyResolvers_2() {
251250
// Create a parser
252251
SpelExpressionParser parser = new SpelExpressionParser();
253252
// Use the standard evaluation context
@@ -287,23 +286,22 @@ public Class<?>[] getSpecificTargetClasses() {
287286
}
288287

289288
@Override
290-
public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException {
289+
public boolean canRead(EvaluationContext context, Object target, String name) {
291290
return propertyMap.containsKey(name);
292291
}
293292

294293
@Override
295-
public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException {
294+
public TypedValue read(EvaluationContext context, Object target, String name) {
296295
return new TypedValue(propertyMap.get(name));
297296
}
298297

299298
@Override
300-
public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException {
299+
public boolean canWrite(EvaluationContext context, Object target, String name) {
301300
return false;
302301
}
303302

304303
@Override
305-
public void write(EvaluationContext context, Object target, String name, Object newValue)
306-
throws AccessException {
304+
public void write(EvaluationContext context, Object target, String name, Object newValue) {
307305
}
308306

309307
}
@@ -331,22 +329,22 @@ public Class<?>[] getSpecificTargetClasses() {
331329
}
332330

333331
@Override
334-
public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException {
332+
public boolean canRead(EvaluationContext context, Object target, String name) {
335333
return propertyMap.containsKey(name);
336334
}
337335

338336
@Override
339-
public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException {
337+
public TypedValue read(EvaluationContext context, Object target, String name) {
340338
return new TypedValue(propertyMap.get(name));
341339
}
342340

343341
@Override
344-
public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException {
342+
public boolean canWrite(EvaluationContext context, Object target, String name) {
345343
return false;
346344
}
347345

348346
@Override
349-
public void write(EvaluationContext context, Object target, String name, Object newValue) throws AccessException {
347+
public void write(EvaluationContext context, Object target, String name, Object newValue) {
350348
}
351349

352350
}

0 commit comments

Comments
 (0)