Polish
This commit is contained in:
@@ -127,7 +127,7 @@ public abstract class AbstractExpressionTests {
|
||||
}
|
||||
assertThat(expectedValue).as("Expression returned null value, but expected '" + expectedValue + "'").isNull();
|
||||
}
|
||||
Class<? extends Object> resultType = value.getClass();
|
||||
Class<?> resultType = value.getClass();
|
||||
if (expectedValue instanceof String) {
|
||||
assertThat(AbstractExpressionTests.stringValueOf(value)).as("Did not get expected value for expression '" + expression + "'.").isEqualTo(expectedValue);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,20 +28,20 @@ import org.springframework.expression.spel.support.StandardTypeConverter;
|
||||
* @author Andy Clement
|
||||
* @author Oliver Becker
|
||||
*/
|
||||
public class BooleanExpressionTests extends AbstractExpressionTests {
|
||||
class BooleanExpressionTests extends AbstractExpressionTests {
|
||||
|
||||
@Test
|
||||
public void testBooleanTrue() {
|
||||
void testBooleanTrue() {
|
||||
evaluate("true", Boolean.TRUE, Boolean.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBooleanFalse() {
|
||||
void testBooleanFalse() {
|
||||
evaluate("false", Boolean.FALSE, Boolean.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOr() {
|
||||
void testOr() {
|
||||
evaluate("false or false", Boolean.FALSE, Boolean.class);
|
||||
evaluate("false or true", Boolean.TRUE, Boolean.class);
|
||||
evaluate("true or false", Boolean.TRUE, Boolean.class);
|
||||
@@ -49,7 +49,7 @@ public class BooleanExpressionTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnd() {
|
||||
void testAnd() {
|
||||
evaluate("false and false", Boolean.FALSE, Boolean.class);
|
||||
evaluate("false and true", Boolean.FALSE, Boolean.class);
|
||||
evaluate("true and false", Boolean.FALSE, Boolean.class);
|
||||
@@ -57,7 +57,7 @@ public class BooleanExpressionTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNot() {
|
||||
void testNot() {
|
||||
evaluate("!false", Boolean.TRUE, Boolean.class);
|
||||
evaluate("!true", Boolean.FALSE, Boolean.class);
|
||||
|
||||
@@ -66,21 +66,21 @@ public class BooleanExpressionTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCombinations01() {
|
||||
void testCombinations01() {
|
||||
evaluate("false and false or true", Boolean.TRUE, Boolean.class);
|
||||
evaluate("true and false or true", Boolean.TRUE, Boolean.class);
|
||||
evaluate("true and false or false", Boolean.FALSE, Boolean.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWritability() {
|
||||
void testWritability() {
|
||||
evaluate("true and true", Boolean.TRUE, Boolean.class, false);
|
||||
evaluate("true or true", Boolean.TRUE, Boolean.class, false);
|
||||
evaluate("!false", Boolean.TRUE, Boolean.class, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBooleanErrors01() {
|
||||
void testBooleanErrors01() {
|
||||
evaluateAndCheckError("1.0 or false", SpelMessage.TYPE_CONVERSION_ERROR, 0);
|
||||
evaluateAndCheckError("false or 39.4", SpelMessage.TYPE_CONVERSION_ERROR, 9);
|
||||
evaluateAndCheckError("true and 'hello'", SpelMessage.TYPE_CONVERSION_ERROR, 9);
|
||||
@@ -90,7 +90,7 @@ public class BooleanExpressionTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertAndHandleNull() { // SPR-9445
|
||||
void testConvertAndHandleNull() { // SPR-9445
|
||||
// without null conversion
|
||||
evaluateAndCheckError("null or true", SpelMessage.TYPE_CONVERSION_ERROR, 0, "null", "boolean");
|
||||
evaluateAndCheckError("null and true", SpelMessage.TYPE_CONVERSION_ERROR, 0, "null", "boolean");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,7 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Oliver Becker
|
||||
*/
|
||||
public class CachedMethodExecutorTests {
|
||||
class CachedMethodExecutorTests {
|
||||
|
||||
private final ExpressionParser parser = new SpelExpressionParser();
|
||||
|
||||
@@ -39,7 +39,7 @@ public class CachedMethodExecutorTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void testCachedExecutionForParameters() {
|
||||
void testCachedExecutionForParameters() {
|
||||
Expression expression = this.parser.parseExpression("echo(#var)");
|
||||
|
||||
assertMethodExecution(expression, 42, "int: 42");
|
||||
@@ -49,7 +49,7 @@ public class CachedMethodExecutorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCachedExecutionForTarget() {
|
||||
void testCachedExecutionForTarget() {
|
||||
Expression expression = this.parser.parseExpression("#var.echo(42)");
|
||||
|
||||
assertMethodExecution(expression, new RootObject(), "int: 42");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Andy Clement
|
||||
* @author Giovanni Dall'Oglio Risso
|
||||
*/
|
||||
public class ComparatorTests {
|
||||
class ComparatorTests {
|
||||
|
||||
@Test
|
||||
void testPrimitives() throws EvaluationException {
|
||||
@@ -126,7 +126,7 @@ public class ComparatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customComparatorWorksWithEquality() {
|
||||
void customComparatorWorksWithEquality() {
|
||||
final StandardEvaluationContext ctx = new StandardEvaluationContext();
|
||||
ctx.setTypeComparator(customComparator);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,7 +23,6 @@ import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.expression.AccessException;
|
||||
import org.springframework.expression.ConstructorExecutor;
|
||||
import org.springframework.expression.ConstructorResolver;
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
@@ -40,15 +39,15 @@ import static org.assertj.core.api.Assertions.assertThatException;
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class ConstructorInvocationTests extends AbstractExpressionTests {
|
||||
class ConstructorInvocationTests extends AbstractExpressionTests {
|
||||
|
||||
@Test
|
||||
public void testTypeConstructors() {
|
||||
void testTypeConstructors() {
|
||||
evaluate("new String('hello world')", "hello world", String.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonExistentType() {
|
||||
void testNonExistentType() {
|
||||
evaluateAndCheckError("new FooBar()", SpelMessage.CONSTRUCTOR_INVOCATION_PROBLEM);
|
||||
}
|
||||
|
||||
@@ -89,7 +88,7 @@ public class ConstructorInvocationTests extends AbstractExpressionTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void testConstructorThrowingException_SPR6760() {
|
||||
void testConstructorThrowingException_SPR6760() {
|
||||
// Test ctor on inventor:
|
||||
// On 1 it will throw an IllegalArgumentException
|
||||
// On 2 it will throw a RuntimeException
|
||||
@@ -151,7 +150,7 @@ public class ConstructorInvocationTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddingConstructorResolvers() {
|
||||
void testAddingConstructorResolvers() {
|
||||
StandardEvaluationContext ctx = new StandardEvaluationContext();
|
||||
|
||||
// reflective constructor accessor is the only one by default
|
||||
@@ -176,7 +175,7 @@ public class ConstructorInvocationTests extends AbstractExpressionTests {
|
||||
|
||||
@Override
|
||||
public ConstructorExecutor resolve(EvaluationContext context, String typeName,
|
||||
List<TypeDescriptor> argumentTypes) throws AccessException {
|
||||
List<TypeDescriptor> argumentTypes) {
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
}
|
||||
|
||||
@@ -184,7 +183,7 @@ public class ConstructorInvocationTests extends AbstractExpressionTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void testVarargsInvocation01() {
|
||||
void testVarargsInvocation01() {
|
||||
// Calling 'Fruit(String... strings)'
|
||||
evaluate("new org.springframework.expression.spel.testresources.Fruit('a','b','c').stringscount()", 3,
|
||||
Integer.class);
|
||||
@@ -200,7 +199,7 @@ public class ConstructorInvocationTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarargsInvocation02() {
|
||||
void testVarargsInvocation02() {
|
||||
// Calling 'Fruit(int i, String... strings)' - returns int+length_of_strings
|
||||
evaluate("new org.springframework.expression.spel.testresources.Fruit(5,'a','b','c').stringscount()", 8,
|
||||
Integer.class);
|
||||
@@ -220,7 +219,7 @@ public class ConstructorInvocationTests extends AbstractExpressionTests {
|
||||
* the argument in order to satisfy a suitable constructor.
|
||||
*/
|
||||
@Test
|
||||
public void testWidening01() {
|
||||
void testWidening01() {
|
||||
// widening of int 3 to double 3 is OK
|
||||
evaluate("new Double(3)", 3.0d, Double.class);
|
||||
// widening of int 3 to long 3 is OK
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.expression.spel;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -336,7 +335,7 @@ class EvaluationTests extends AbstractExpressionTests {
|
||||
StandardEvaluationContext context = new StandardEvaluationContext();
|
||||
|
||||
// Register a custom MethodResolver...
|
||||
context.setMethodResolvers(Arrays.asList((evaluationContext, targetObject, name, argumentTypes) -> null));
|
||||
context.setMethodResolvers(List.of((evaluationContext, targetObject, name, argumentTypes) -> null));
|
||||
|
||||
// or simply...
|
||||
// context.setMethodResolvers(new ArrayList<MethodResolver>());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,7 +24,6 @@ import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.expression.AccessException;
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
import org.springframework.expression.EvaluationException;
|
||||
import org.springframework.expression.Expression;
|
||||
@@ -60,13 +59,13 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class ExpressionLanguageScenarioTests extends AbstractExpressionTests {
|
||||
class ExpressionLanguageScenarioTests extends AbstractExpressionTests {
|
||||
|
||||
/**
|
||||
* Scenario: using the standard infrastructure and running simple expression evaluation.
|
||||
*/
|
||||
@Test
|
||||
public void testScenario_UsingStandardInfrastructure() {
|
||||
void testScenario_UsingStandardInfrastructure() {
|
||||
try {
|
||||
// Create a parser
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
@@ -89,7 +88,7 @@ public class ExpressionLanguageScenarioTests extends AbstractExpressionTests {
|
||||
* Scenario: using the standard context but adding your own variables
|
||||
*/
|
||||
@Test
|
||||
public void testScenario_DefiningVariablesThatWillBeAccessibleInExpressions() throws Exception {
|
||||
void testScenario_DefiningVariablesThatWillBeAccessibleInExpressions() {
|
||||
// Create a parser
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
// Use the standard evaluation context
|
||||
@@ -124,7 +123,7 @@ public class ExpressionLanguageScenarioTests extends AbstractExpressionTests {
|
||||
* Scenario: using your own root context object
|
||||
*/
|
||||
@Test
|
||||
public void testScenario_UsingADifferentRootContextObject() throws Exception {
|
||||
void testScenario_UsingADifferentRootContextObject() {
|
||||
// Create a parser
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
// Use the standard evaluation context
|
||||
@@ -170,7 +169,7 @@ public class ExpressionLanguageScenarioTests extends AbstractExpressionTests {
|
||||
* Scenario: using your own java methods and calling them from the expression
|
||||
*/
|
||||
@Test
|
||||
public void testScenario_RegisteringJavaMethodsAsFunctionsAndCallingThem() throws SecurityException, NoSuchMethodException {
|
||||
void testScenario_RegisteringJavaMethodsAsFunctionsAndCallingThem() throws SecurityException, NoSuchMethodException {
|
||||
try {
|
||||
// Create a parser
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
@@ -192,7 +191,7 @@ public class ExpressionLanguageScenarioTests extends AbstractExpressionTests {
|
||||
* Scenario: looking up your own MethodHandles and calling them from the expression
|
||||
*/
|
||||
@Test
|
||||
public void testScenario_RegisteringJavaMethodsAsMethodHandlesAndCallingThem() throws SecurityException, NoSuchMethodException {
|
||||
void testScenario_RegisteringJavaMethodsAsMethodHandlesAndCallingThem() throws SecurityException {
|
||||
try {
|
||||
// Create a parser
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
@@ -231,7 +230,7 @@ public class ExpressionLanguageScenarioTests extends AbstractExpressionTests {
|
||||
* Scenario: add a property resolver that will get called in the resolver chain, this one only supports reading.
|
||||
*/
|
||||
@Test
|
||||
public void testScenario_AddingYourOwnPropertyResolvers_1() throws Exception {
|
||||
void testScenario_AddingYourOwnPropertyResolvers_1() {
|
||||
// Create a parser
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
// Use the standard evaluation context
|
||||
@@ -247,7 +246,7 @@ public class ExpressionLanguageScenarioTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScenario_AddingYourOwnPropertyResolvers_2() throws Exception {
|
||||
void testScenario_AddingYourOwnPropertyResolvers_2() {
|
||||
// Create a parser
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
// Use the standard evaluation context
|
||||
@@ -287,23 +286,22 @@ public class ExpressionLanguageScenarioTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public boolean canRead(EvaluationContext context, Object target, String name) {
|
||||
return propertyMap.containsKey(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public TypedValue read(EvaluationContext context, Object target, String name) {
|
||||
return new TypedValue(propertyMap.get(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public boolean canWrite(EvaluationContext context, Object target, String name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(EvaluationContext context, Object target, String name, Object newValue)
|
||||
throws AccessException {
|
||||
public void write(EvaluationContext context, Object target, String name, Object newValue) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -331,22 +329,22 @@ public class ExpressionLanguageScenarioTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public boolean canRead(EvaluationContext context, Object target, String name) {
|
||||
return propertyMap.containsKey(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public TypedValue read(EvaluationContext context, Object target, String name) {
|
||||
return new TypedValue(propertyMap.get(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public boolean canWrite(EvaluationContext context, Object target, String name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(EvaluationContext context, Object target, String name, Object newValue) throws AccessException {
|
||||
public void write(EvaluationContext context, Object target, String name, Object newValue) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -42,7 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Andy Clement
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class ExpressionWithConversionTests extends AbstractExpressionTests {
|
||||
class ExpressionWithConversionTests extends AbstractExpressionTests {
|
||||
|
||||
private static List<String> listOfString = new ArrayList<>();
|
||||
private static TypeDescriptor typeDescriptorForListOfString = null;
|
||||
@@ -59,7 +59,7 @@ public class ExpressionWithConversionTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
void setUp() throws Exception {
|
||||
ExpressionWithConversionTests.typeDescriptorForListOfString = new TypeDescriptor(ExpressionWithConversionTests.class.getDeclaredField("listOfString"));
|
||||
ExpressionWithConversionTests.typeDescriptorForListOfInteger = new TypeDescriptor(ExpressionWithConversionTests.class.getDeclaredField("listOfInteger"));
|
||||
}
|
||||
@@ -69,7 +69,7 @@ public class ExpressionWithConversionTests extends AbstractExpressionTests {
|
||||
* Test the service can convert what we are about to use in the expression evaluation tests.
|
||||
*/
|
||||
@Test
|
||||
public void testConversionsAvailable() throws Exception {
|
||||
void testConversionsAvailable() {
|
||||
TypeConvertorUsingConversionService tcs = new TypeConvertorUsingConversionService();
|
||||
|
||||
// ArrayList containing List<Integer> to List<String>
|
||||
@@ -87,7 +87,7 @@ public class ExpressionWithConversionTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetParameterizedList() throws Exception {
|
||||
void testSetParameterizedList() {
|
||||
StandardEvaluationContext context = TestScenarioCreator.getTestEvaluationContext();
|
||||
Expression e = parser.parseExpression("listOfInteger.size()");
|
||||
assertThat(e.getValue(context, Integer.class)).isZero();
|
||||
@@ -101,7 +101,7 @@ public class ExpressionWithConversionTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCoercionToCollectionOfPrimitive() throws Exception {
|
||||
void testCoercionToCollectionOfPrimitive() throws Exception {
|
||||
|
||||
class TestTarget {
|
||||
@SuppressWarnings("unused")
|
||||
@@ -134,7 +134,7 @@ public class ExpressionWithConversionTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert() {
|
||||
void testConvert() {
|
||||
Foo root = new Foo("bar");
|
||||
Collection<String> foos = Collections.singletonList("baz");
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -33,36 +33,36 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class InProgressTests extends AbstractExpressionTests {
|
||||
class InProgressTests extends AbstractExpressionTests {
|
||||
|
||||
@Test
|
||||
public void testRelOperatorsBetween01() {
|
||||
void testRelOperatorsBetween01() {
|
||||
evaluate("1 between listOneFive", "true", Boolean.class);
|
||||
// no inline list building at the moment
|
||||
// evaluate("1 between {1, 5}", "true", Boolean.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRelOperatorsBetweenErrors01() {
|
||||
void testRelOperatorsBetweenErrors01() {
|
||||
evaluateAndCheckError("1 between T(String)", SpelMessage.BETWEEN_RIGHT_OPERAND_MUST_BE_TWO_ELEMENT_LIST, 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRelOperatorsBetweenErrors03() {
|
||||
void testRelOperatorsBetweenErrors03() {
|
||||
evaluateAndCheckError("1 between listOfNumbersUpToTen",
|
||||
SpelMessage.BETWEEN_RIGHT_OPERAND_MUST_BE_TWO_ELEMENT_LIST, 10);
|
||||
}
|
||||
|
||||
// PROJECTION
|
||||
@Test
|
||||
public void testProjection01() {
|
||||
void testProjection01() {
|
||||
evaluate("listOfNumbersUpToTen.![#this<5?'y':'n']", "[y, y, y, y, n, n, n, n, n, n]", ArrayList.class);
|
||||
// inline list creation not supported at the moment
|
||||
// evaluate("{1,2,3,4,5,6,7,8,9,10}.!{#isEven(#this)}", "[n, y, n, y, n, y, n, y, n, y]", ArrayList.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProjection02() {
|
||||
void testProjection02() {
|
||||
// inline map creation not supported at the moment
|
||||
// evaluate("#{'a':'y','b':'n','c':'y'}.![value=='y'?key:null].nonnull().sort()", "[a, c]", ArrayList.class);
|
||||
evaluate("mapOfNumbersUpToTen.![key>5?value:null]",
|
||||
@@ -70,14 +70,14 @@ public class InProgressTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProjection05() {
|
||||
void testProjection05() {
|
||||
evaluateAndCheckError("'abc'.![true]", SpelMessage.PROJECTION_NOT_SUPPORTED_ON_TYPE);
|
||||
evaluateAndCheckError("null.![true]", SpelMessage.PROJECTION_NOT_SUPPORTED_ON_TYPE);
|
||||
evaluate("null?.![true]", null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProjection06() throws Exception {
|
||||
void testProjection06() {
|
||||
SpelExpression expr = (SpelExpression) parser.parseExpression("'abc'.![true]");
|
||||
assertThat(expr.toStringAST()).isEqualTo("'abc'.![true]");
|
||||
}
|
||||
@@ -85,31 +85,31 @@ public class InProgressTests extends AbstractExpressionTests {
|
||||
// SELECTION
|
||||
|
||||
@Test
|
||||
public void testSelection02() {
|
||||
void testSelection02() {
|
||||
evaluate("testMap.keySet().?[#this matches '.*o.*']", "[monday]", ArrayList.class);
|
||||
evaluate("testMap.keySet().?[#this matches '.*r.*'].contains('saturday')", "true", Boolean.class);
|
||||
evaluate("testMap.keySet().?[#this matches '.*r.*'].size()", "3", Integer.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelectionError_NonBooleanSelectionCriteria() {
|
||||
void testSelectionError_NonBooleanSelectionCriteria() {
|
||||
evaluateAndCheckError("listOfNumbersUpToTen.?['nonboolean']",
|
||||
SpelMessage.RESULT_OF_SELECTION_CRITERIA_IS_NOT_BOOLEAN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelection03() {
|
||||
void testSelection03() {
|
||||
evaluate("mapOfNumbersUpToTen.?[key>5].size()", "5", Integer.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelection04() {
|
||||
void testSelection04() {
|
||||
evaluateAndCheckError("mapOfNumbersUpToTen.?['hello'].size()",
|
||||
SpelMessage.RESULT_OF_SELECTION_CRITERIA_IS_NOT_BOOLEAN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelection05() {
|
||||
void testSelection05() {
|
||||
evaluate("mapOfNumbersUpToTen.?[key>11].size()", "0", Integer.class);
|
||||
evaluate("mapOfNumbersUpToTen.^[key>11]", null, null);
|
||||
evaluate("mapOfNumbersUpToTen.$[key>11]", null, null);
|
||||
@@ -119,28 +119,28 @@ public class InProgressTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelectionFirst01() {
|
||||
void testSelectionFirst01() {
|
||||
evaluate("listOfNumbersUpToTen.^[#isEven(#this) == 'y']", "2", Integer.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelectionFirst02() {
|
||||
void testSelectionFirst02() {
|
||||
evaluate("mapOfNumbersUpToTen.^[key>5].size()", "1", Integer.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelectionLast01() {
|
||||
void testSelectionLast01() {
|
||||
evaluate("listOfNumbersUpToTen.$[#isEven(#this) == 'y']", "10", Integer.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelectionLast02() {
|
||||
void testSelectionLast02() {
|
||||
evaluate("mapOfNumbersUpToTen.$[key>5]", "{10=ten}", HashMap.class);
|
||||
evaluate("mapOfNumbersUpToTen.$[key>5].size()", "1", Integer.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelectionAST() throws Exception {
|
||||
void testSelectionAST() {
|
||||
SpelExpression expr = (SpelExpression) parser.parseExpression("'abc'.^[true]");
|
||||
assertThat(expr.toStringAST()).isEqualTo("'abc'.^[true]");
|
||||
expr = (SpelExpression) parser.parseExpression("'abc'.?[true]");
|
||||
@@ -151,7 +151,7 @@ public class InProgressTests extends AbstractExpressionTests {
|
||||
|
||||
// Constructor invocation
|
||||
@Test
|
||||
public void testSetConstruction01() {
|
||||
void testSetConstruction01() {
|
||||
evaluate("new java.util.HashSet().addAll({'a','b','c'})", "true", Boolean.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,7 +29,6 @@ import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.expression.AccessException;
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
import org.springframework.expression.EvaluationException;
|
||||
import org.springframework.expression.Expression;
|
||||
@@ -83,24 +82,23 @@ class IndexingTests {
|
||||
public static class MapAccessor implements PropertyAccessor {
|
||||
|
||||
@Override
|
||||
public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public boolean canRead(EvaluationContext context, Object target, String name) {
|
||||
return (((Map<?, ?>) target).containsKey(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public TypedValue read(EvaluationContext context, Object target, String name) {
|
||||
return new TypedValue(((Map<?, ?>) target).get(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public boolean canWrite(EvaluationContext context, Object target, String name) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void write(EvaluationContext context, Object target, String name, Object newValue)
|
||||
throws AccessException {
|
||||
public void write(EvaluationContext context, Object target, String name, Object newValue) {
|
||||
((Map) target).put(name, newValue);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -35,7 +35,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
* @author Giovanni Dall'Oglio Risso
|
||||
* @since 3.0.4
|
||||
*/
|
||||
public class ListTests extends AbstractExpressionTests {
|
||||
class ListTests extends AbstractExpressionTests {
|
||||
|
||||
// if the list is full of literals then it will be of the type unmodifiableClass
|
||||
// rather than ArrayList
|
||||
@@ -43,80 +43,80 @@ public class ListTests extends AbstractExpressionTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void testInlineListCreation01() {
|
||||
void testInlineListCreation01() {
|
||||
evaluate("{1, 2, 3, 4, 5}", "[1, 2, 3, 4, 5]", unmodifiableClass);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInlineListCreation02() {
|
||||
void testInlineListCreation02() {
|
||||
evaluate("{'abc', 'xyz'}", "[abc, xyz]", unmodifiableClass);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInlineListCreation03() {
|
||||
void testInlineListCreation03() {
|
||||
evaluate("{}", "[]", unmodifiableClass);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInlineListCreation04() {
|
||||
void testInlineListCreation04() {
|
||||
evaluate("{'abc'=='xyz'}", "[false]", ArrayList.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInlineListAndNesting() {
|
||||
void testInlineListAndNesting() {
|
||||
evaluate("{{1,2,3},{4,5,6}}", "[[1, 2, 3], [4, 5, 6]]", unmodifiableClass);
|
||||
evaluate("{{1,'2',3},{4,{'a','b'},5,6}}", "[[1, 2, 3], [4, [a, b], 5, 6]]", unmodifiableClass);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInlineListError() {
|
||||
void testInlineListError() {
|
||||
parseAndCheckError("{'abc'", SpelMessage.OOD);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRelOperatorsIs02() {
|
||||
void testRelOperatorsIs02() {
|
||||
evaluate("{1, 2, 3, 4, 5} instanceof T(java.util.List)", "true", Boolean.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInlineListCreation05() {
|
||||
void testInlineListCreation05() {
|
||||
evaluate("3 between {1,5}", "true", Boolean.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInlineListCreation06() {
|
||||
void testInlineListCreation06() {
|
||||
evaluate("8 between {1,5}", "false", Boolean.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInlineListAndProjectionSelection() {
|
||||
void testInlineListAndProjectionSelection() {
|
||||
evaluate("{1,2,3,4,5,6}.![#this>3]", "[false, false, false, true, true, true]", ArrayList.class);
|
||||
evaluate("{1,2,3,4,5,6}.?[#this>3]", "[4, 5, 6]", ArrayList.class);
|
||||
evaluate("{1,2,3,4,5,6,7,8,9,10}.?[#isEven(#this) == 'y']", "[2, 4, 6, 8, 10]", ArrayList.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetConstruction01() {
|
||||
void testSetConstruction01() {
|
||||
evaluate("new java.util.HashSet().addAll({'a','b','c'})", "true", Boolean.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRelOperatorsBetween01() {
|
||||
void testRelOperatorsBetween01() {
|
||||
evaluate("32 between {32, 42}", "true", Boolean.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRelOperatorsBetween02() {
|
||||
void testRelOperatorsBetween02() {
|
||||
evaluate("'efg' between {'abc', 'xyz'}", "true", Boolean.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRelOperatorsBetween03() {
|
||||
void testRelOperatorsBetween03() {
|
||||
evaluate("42 between {32, 42}", "true", Boolean.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRelOperatorsBetween04() {
|
||||
void testRelOperatorsBetween04() {
|
||||
evaluate("new java.math.BigDecimal('1') between {new java.math.BigDecimal('1'),new java.math.BigDecimal('5')}",
|
||||
"true", Boolean.class);
|
||||
evaluate("new java.math.BigDecimal('3') between {new java.math.BigDecimal('1'),new java.math.BigDecimal('5')}",
|
||||
@@ -128,12 +128,12 @@ public class ListTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRelOperatorsBetweenErrors02() {
|
||||
void testRelOperatorsBetweenErrors02() {
|
||||
evaluateAndCheckError("'abc' between {5,7}", SpelMessage.NOT_COMPARABLE, 6);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstantRepresentation1() {
|
||||
void testConstantRepresentation1() {
|
||||
checkConstantList("{1,2,3,4,5}", true);
|
||||
checkConstantList("{'abc'}", true);
|
||||
checkConstantList("{}", true);
|
||||
@@ -158,7 +158,7 @@ public class ListTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInlineListWriting() {
|
||||
void testInlineListWriting() {
|
||||
// list should be unmodifiable
|
||||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
|
||||
evaluate("{1, 2, 3, 4, 5}[0]=6", "[1, 2, 3, 4, 5]", unmodifiableClass));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -35,7 +35,7 @@ class LiteralExpressionTests {
|
||||
|
||||
|
||||
@Test
|
||||
void getValue() throws Exception {
|
||||
void getValue() {
|
||||
assertThat(lEx.getValue()).isEqualTo("somevalue");
|
||||
assertThat(lEx.getValue(String.class)).isEqualTo("somevalue");
|
||||
assertThat(lEx.getValue(new Rooty())).isEqualTo("somevalue");
|
||||
@@ -43,7 +43,7 @@ class LiteralExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getValueWithSuppliedEvaluationContext() throws Exception {
|
||||
void getValueWithSuppliedEvaluationContext() {
|
||||
EvaluationContext ctx = new StandardEvaluationContext();
|
||||
assertThat(lEx.getValue(ctx)).isEqualTo("somevalue");
|
||||
assertThat(lEx.getValue(ctx, String.class)).isEqualTo("somevalue");
|
||||
@@ -57,7 +57,7 @@ class LiteralExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void isWritable() throws Exception {
|
||||
void isWritable() {
|
||||
assertThat(lEx.isWritable(new StandardEvaluationContext())).isFalse();
|
||||
assertThat(lEx.isWritable(new Rooty())).isFalse();
|
||||
assertThat(lEx.isWritable(new StandardEvaluationContext(), new Rooty())).isFalse();
|
||||
@@ -77,7 +77,7 @@ class LiteralExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getValueType() throws Exception {
|
||||
void getValueType() {
|
||||
assertThat(lEx.getValueType()).isEqualTo(String.class);
|
||||
assertThat(lEx.getValueType(new StandardEvaluationContext())).isEqualTo(String.class);
|
||||
assertThat(lEx.getValueType(new Rooty())).isEqualTo(String.class);
|
||||
@@ -85,7 +85,7 @@ class LiteralExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getValueTypeDescriptor() throws Exception {
|
||||
void getValueTypeDescriptor() {
|
||||
assertThat(lEx.getValueTypeDescriptor().getType()).isEqualTo(String.class);
|
||||
assertThat(lEx.getValueTypeDescriptor(new StandardEvaluationContext()).getType()).isEqualTo(String.class);
|
||||
assertThat(lEx.getValueTypeDescriptor(new Rooty()).getType()).isEqualTo(String.class);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,61 +28,61 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class LiteralTests extends AbstractExpressionTests {
|
||||
class LiteralTests extends AbstractExpressionTests {
|
||||
|
||||
@Test
|
||||
public void testLiteralBoolean01() {
|
||||
void testLiteralBoolean01() {
|
||||
evaluate("false", "false", Boolean.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLiteralBoolean02() {
|
||||
void testLiteralBoolean02() {
|
||||
evaluate("true", "true", Boolean.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLiteralInteger01() {
|
||||
void testLiteralInteger01() {
|
||||
evaluate("1", "1", Integer.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLiteralInteger02() {
|
||||
void testLiteralInteger02() {
|
||||
evaluate("1415", "1415", Integer.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLiteralString01() {
|
||||
void testLiteralString01() {
|
||||
evaluate("'Hello World'", "Hello World", String.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLiteralString02() {
|
||||
void testLiteralString02() {
|
||||
evaluate("'joe bloggs'", "joe bloggs", String.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLiteralString03() {
|
||||
void testLiteralString03() {
|
||||
evaluate("'hello'", "hello", String.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLiteralString04() {
|
||||
void testLiteralString04() {
|
||||
evaluate("'Tony''s Pizza'", "Tony's Pizza", String.class);
|
||||
evaluate("'Tony\\r''s Pizza'", "Tony\\r's Pizza", String.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLiteralString05() {
|
||||
void testLiteralString05() {
|
||||
evaluate("\"Hello World\"", "Hello World", String.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLiteralString06() {
|
||||
void testLiteralString06() {
|
||||
evaluate("\"Hello ' World\"", "Hello ' World", String.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHexIntLiteral01() {
|
||||
void testHexIntLiteral01() {
|
||||
evaluate("0x7FFFF", "524287", Integer.class);
|
||||
evaluate("0x7FFFFL", 524287L, Long.class);
|
||||
evaluate("0X7FFFF", "524287", Integer.class);
|
||||
@@ -90,12 +90,12 @@ public class LiteralTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongIntLiteral01() {
|
||||
void testLongIntLiteral01() {
|
||||
evaluate("0xCAFEBABEL", 3405691582L, Long.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongIntInteractions01() {
|
||||
void testLongIntInteractions01() {
|
||||
evaluate("0x20 * 2L", 64L, Long.class);
|
||||
// ask for the result to be made into an Integer
|
||||
evaluateAndAskForReturnType("0x20 * 2L", 64, Integer.class);
|
||||
@@ -104,7 +104,7 @@ public class LiteralTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSignedIntLiterals() {
|
||||
void testSignedIntLiterals() {
|
||||
evaluate("-1", -1, Integer.class);
|
||||
evaluate("-0xa", -10, Integer.class);
|
||||
evaluate("-1L", -1L, Long.class);
|
||||
@@ -112,7 +112,7 @@ public class LiteralTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLiteralReal01_CreatingDoubles() {
|
||||
void testLiteralReal01_CreatingDoubles() {
|
||||
evaluate("1.25", 1.25d, Double.class);
|
||||
evaluate("2.99", 2.99d, Double.class);
|
||||
evaluate("-3.141", -3.141d, Double.class);
|
||||
@@ -125,7 +125,7 @@ public class LiteralTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLiteralReal02_CreatingFloats() {
|
||||
void testLiteralReal02_CreatingFloats() {
|
||||
// For now, everything becomes a double...
|
||||
evaluate("1.25f", 1.25f, Float.class);
|
||||
evaluate("2.5f", 2.5f, Float.class);
|
||||
@@ -136,7 +136,7 @@ public class LiteralTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLiteralReal03_UsingExponents() {
|
||||
void testLiteralReal03_UsingExponents() {
|
||||
evaluate("6.0221415E+23", "6.0221415E23", Double.class);
|
||||
evaluate("6.0221415e+23", "6.0221415E23", Double.class);
|
||||
evaluate("6.0221415E+23d", "6.0221415E23", Double.class);
|
||||
@@ -145,25 +145,25 @@ public class LiteralTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLiteralReal04_BadExpressions() {
|
||||
void testLiteralReal04_BadExpressions() {
|
||||
parseAndCheckError("6.1e23e22", SpelMessage.MORE_INPUT, 6, "e22");
|
||||
parseAndCheckError("6.1f23e22", SpelMessage.MORE_INPUT, 4, "23e22");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLiteralNull01() {
|
||||
void testLiteralNull01() {
|
||||
evaluate("null", null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConversions() {
|
||||
void testConversions() {
|
||||
// getting the expression type to be what we want - either:
|
||||
evaluate("new Integer(37).byteValue()", (byte) 37, Byte.class); // calling byteValue() on Integer.class
|
||||
evaluateAndAskForReturnType("new Integer(37)", (byte) 37, Byte.class); // relying on registered type converters
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotWritable() throws Exception {
|
||||
void testNotWritable() {
|
||||
SpelExpression expr = (SpelExpression)parser.parseExpression("37");
|
||||
assertThat(expr.isWritable(new StandardEvaluationContext())).isFalse();
|
||||
expr = (SpelExpression)parser.parseExpression("37L");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,7 +21,6 @@ import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.expression.AccessException;
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.ExpressionParser;
|
||||
@@ -37,20 +36,20 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class MapAccessTests extends AbstractExpressionTests {
|
||||
class MapAccessTests extends AbstractExpressionTests {
|
||||
|
||||
@Test
|
||||
public void testSimpleMapAccess01() {
|
||||
void testSimpleMapAccess01() {
|
||||
evaluate("testMap.get('monday')", "montag", String.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapAccessThroughIndexer() {
|
||||
void testMapAccessThroughIndexer() {
|
||||
evaluate("testMap['monday']", "montag", String.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomMapAccessor() throws Exception {
|
||||
void testCustomMapAccessor() {
|
||||
ExpressionParser parser = new SpelExpressionParser();
|
||||
StandardEvaluationContext ctx = TestScenarioCreator.getTestEvaluationContext();
|
||||
ctx.addPropertyAccessor(new MapAccessor());
|
||||
@@ -61,7 +60,7 @@ public class MapAccessTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVariableMapAccess() throws Exception {
|
||||
void testVariableMapAccess() {
|
||||
ExpressionParser parser = new SpelExpressionParser();
|
||||
StandardEvaluationContext ctx = TestScenarioCreator.getTestEvaluationContext();
|
||||
ctx.setVariable("day", "saturday");
|
||||
@@ -72,7 +71,7 @@ public class MapAccessTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetValue() {
|
||||
void testGetValue() {
|
||||
Map<String, String> props1 = new HashMap<>();
|
||||
props1.put("key1", "value1");
|
||||
props1.put("key2", "value2");
|
||||
@@ -86,7 +85,7 @@ public class MapAccessTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetValueFromRootMap() {
|
||||
void testGetValueFromRootMap() {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("key", "value");
|
||||
|
||||
@@ -157,23 +156,23 @@ public class MapAccessTests extends AbstractExpressionTests {
|
||||
public static class MapAccessor implements PropertyAccessor {
|
||||
|
||||
@Override
|
||||
public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public boolean canRead(EvaluationContext context, Object target, String name) {
|
||||
return (((Map<?, ?>) target).containsKey(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public TypedValue read(EvaluationContext context, Object target, String name) {
|
||||
return new TypedValue(((Map<?, ?>) target).get(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public boolean canWrite(EvaluationContext context, Object target, String name) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void write(EvaluationContext context, Object target, String name, Object newValue) throws AccessException {
|
||||
public void write(EvaluationContext context, Object target, String name, Object newValue) {
|
||||
((Map<Object, Object>) target).put(name, newValue);
|
||||
}
|
||||
|
||||
|
||||
@@ -184,7 +184,7 @@ class MapTests extends AbstractExpressionTests {
|
||||
assertThat(o).isEqualTo("value");
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
static class MapHolder {
|
||||
|
||||
public Map foo = Map.of(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -26,7 +26,6 @@ import java.util.List;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.expression.AccessException;
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.ExpressionInvocationTargetException;
|
||||
@@ -49,15 +48,15 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
* @author Phillip Webb
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
public class MethodInvocationTests extends AbstractExpressionTests {
|
||||
class MethodInvocationTests extends AbstractExpressionTests {
|
||||
|
||||
@Test
|
||||
public void testSimpleAccess01() {
|
||||
void testSimpleAccess01() {
|
||||
evaluate("getPlaceOfBirth().getCity()", "SmilJan", String.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringClass() {
|
||||
void testStringClass() {
|
||||
evaluate("new java.lang.String('hello').charAt(2)", 'l', Character.class);
|
||||
evaluate("new java.lang.String('hello').charAt(2).equals('l'.charAt(0))", true, Boolean.class);
|
||||
evaluate("'HELLO'.toLowerCase()", "hello", String.class);
|
||||
@@ -65,13 +64,13 @@ public class MethodInvocationTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonExistentMethods() {
|
||||
void testNonExistentMethods() {
|
||||
// name is ok but madeup() does not exist
|
||||
evaluateAndCheckError("name.madeup()", SpelMessage.METHOD_NOT_FOUND, 5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWidening01() {
|
||||
void testWidening01() {
|
||||
// widening of int 3 to double 3 is OK
|
||||
evaluate("new Double(3.0d).compareTo(8)", -1, Integer.class);
|
||||
evaluate("new Double(3.0d).compareTo(3)", 0, Integer.class);
|
||||
@@ -79,14 +78,14 @@ public class MethodInvocationTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArgumentConversion01() {
|
||||
void testArgumentConversion01() {
|
||||
// Rely on Double>String conversion for calling startsWith()
|
||||
evaluate("new String('hello 2.0 to you').startsWith(7.0d)", false, Boolean.class);
|
||||
evaluate("new String('7.0 foobar').startsWith(7.0d)", true, Boolean.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodThrowingException_SPR6760() {
|
||||
void testMethodThrowingException_SPR6760() {
|
||||
// Test method on inventor: throwException()
|
||||
// On 1 it will throw an IllegalArgumentException
|
||||
// On 2 it will throw a RuntimeException
|
||||
@@ -140,7 +139,7 @@ public class MethodInvocationTests extends AbstractExpressionTests {
|
||||
* Check on first usage (when the cachedExecutor in MethodReference is null) that the exception is not wrapped.
|
||||
*/
|
||||
@Test
|
||||
public void testMethodThrowingException_SPR6941() {
|
||||
void testMethodThrowingException_SPR6941() {
|
||||
// Test method on inventor: throwException()
|
||||
// On 1 it will throw an IllegalArgumentException
|
||||
// On 2 it will throw a RuntimeException
|
||||
@@ -157,7 +156,7 @@ public class MethodInvocationTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodThrowingException_SPR6941_2() {
|
||||
void testMethodThrowingException_SPR6941_2() {
|
||||
// Test method on inventor: throwException()
|
||||
// On 1 it will throw an IllegalArgumentException
|
||||
// On 2 it will throw a RuntimeException
|
||||
@@ -175,7 +174,7 @@ public class MethodInvocationTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodFiltering_SPR6764() {
|
||||
void testMethodFiltering_SPR6764() {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
StandardEvaluationContext context = new StandardEvaluationContext();
|
||||
context.setRootObject(new TestObject());
|
||||
@@ -198,7 +197,7 @@ public class MethodInvocationTests extends AbstractExpressionTests {
|
||||
|
||||
// check not called for other types
|
||||
filter.filterCalled = false;
|
||||
context.setRootObject(new String("abc"));
|
||||
context.setRootObject("abc");
|
||||
expr = (SpelExpression) parser.parseExpression("charAt(0)");
|
||||
result = expr.getValue(context, String.class);
|
||||
assertThat(result).isEqualTo("a");
|
||||
@@ -215,7 +214,7 @@ public class MethodInvocationTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddingMethodResolvers() {
|
||||
void testAddingMethodResolvers() {
|
||||
StandardEvaluationContext ctx = new StandardEvaluationContext();
|
||||
|
||||
// reflective method accessor is the only one by default
|
||||
@@ -236,7 +235,7 @@ public class MethodInvocationTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarargsInvocation01() {
|
||||
void testVarargsInvocation01() {
|
||||
// Calling 'public String aVarargsMethod(String... strings)'
|
||||
evaluate("aVarargsMethod('a','b','c')", "[a, b, c]", String.class);
|
||||
evaluate("aVarargsMethod('a')", "[a]", String.class);
|
||||
@@ -252,7 +251,7 @@ public class MethodInvocationTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarargsInvocation02() {
|
||||
void testVarargsInvocation02() {
|
||||
// Calling 'public String aVarargsMethod2(int i, String... strings)'
|
||||
evaluate("aVarargsMethod2(5,'a','b','c')", "5-[a, b, c]", String.class);
|
||||
evaluate("aVarargsMethod2(2,'a')", "2-[a]", String.class);
|
||||
@@ -267,7 +266,7 @@ public class MethodInvocationTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarargsInvocation03() {
|
||||
void testVarargsInvocation03() {
|
||||
// Calling 'public int aVarargsMethod3(String str1, String... strings)' - returns all strings concatenated with "-"
|
||||
|
||||
// No conversion necessary
|
||||
@@ -295,7 +294,7 @@ public class MethodInvocationTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarargsOptionalInvocation() {
|
||||
void testVarargsOptionalInvocation() {
|
||||
// Calling 'public String optionalVarargsMethod(Optional<String>... values)'
|
||||
evaluate("optionalVarargsMethod()", "[]", String.class);
|
||||
evaluate("optionalVarargsMethod(new String[0])", "[]", String.class);
|
||||
@@ -311,19 +310,19 @@ public class MethodInvocationTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvocationOnNullContextObject() {
|
||||
void testInvocationOnNullContextObject() {
|
||||
evaluateAndCheckError("null.toString()",SpelMessage.METHOD_CALL_ON_NULL_OBJECT_NOT_ALLOWED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodOfClass() throws Exception {
|
||||
void testMethodOfClass() {
|
||||
Expression expression = parser.parseExpression("getName()");
|
||||
Object value = expression.getValue(new StandardEvaluationContext(String.class));
|
||||
assertThat(value).isEqualTo("java.lang.String");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invokeMethodWithoutConversion() throws Exception {
|
||||
void invokeMethodWithoutConversion() {
|
||||
final BytesService service = new BytesService();
|
||||
byte[] bytes = new byte[100];
|
||||
StandardEvaluationContext context = new StandardEvaluationContext(bytes);
|
||||
@@ -394,7 +393,7 @@ public class MethodInvocationTests extends AbstractExpressionTests {
|
||||
|
||||
@Override
|
||||
public MethodExecutor resolve(EvaluationContext context, Object targetObject, String name,
|
||||
List<TypeDescriptor> argumentTypes) throws AccessException {
|
||||
List<TypeDescriptor> argumentTypes) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,10 +31,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class OperatorOverloaderTests extends AbstractExpressionTests {
|
||||
class OperatorOverloaderTests extends AbstractExpressionTests {
|
||||
|
||||
@Test
|
||||
public void testSimpleOperations() throws Exception {
|
||||
void testSimpleOperations() {
|
||||
// no built-in support for this:
|
||||
evaluateAndCheckError("'abc'-true",SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES);
|
||||
|
||||
@@ -57,7 +57,7 @@ public class OperatorOverloaderTests extends AbstractExpressionTests {
|
||||
@Override
|
||||
public Object operate(Operation operation, Object leftOperand, Object rightOperand) throws EvaluationException {
|
||||
if (operation==Operation.ADD) {
|
||||
return ((String)leftOperand)+((Boolean)rightOperand).toString();
|
||||
return leftOperand + ((Boolean) rightOperand).toString();
|
||||
}
|
||||
else {
|
||||
return leftOperand;
|
||||
@@ -66,10 +66,7 @@ public class OperatorOverloaderTests extends AbstractExpressionTests {
|
||||
|
||||
@Override
|
||||
public boolean overridesOperation(Operation operation, Object leftOperand, Object rightOperand) throws EvaluationException {
|
||||
if (leftOperand instanceof String && rightOperand instanceof Boolean) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return leftOperand instanceof String && rightOperand instanceof Boolean;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,10 +23,10 @@ import org.junit.jupiter.api.Test;
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class ParserErrorMessagesTests extends AbstractExpressionTests {
|
||||
class ParserErrorMessagesTests extends AbstractExpressionTests {
|
||||
|
||||
@Test
|
||||
public void testBrokenExpression01() {
|
||||
void testBrokenExpression01() {
|
||||
// will not fit into an int, needs L suffix
|
||||
parseAndCheckError("0xCAFEBABE", SpelMessage.NOT_AN_INTEGER);
|
||||
evaluate("0xCAFEBABEL", 0xCAFEBABEL, Long.class);
|
||||
@@ -34,25 +34,25 @@ public class ParserErrorMessagesTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBrokenExpression02() {
|
||||
void testBrokenExpression02() {
|
||||
// rogue 'G' on the end
|
||||
parseAndCheckError("0xB0BG", SpelMessage.MORE_INPUT, 5, "G");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBrokenExpression04() {
|
||||
void testBrokenExpression04() {
|
||||
// missing right operand
|
||||
parseAndCheckError("true or ", SpelMessage.RIGHT_OPERAND_PROBLEM, 5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBrokenExpression05() {
|
||||
void testBrokenExpression05() {
|
||||
// missing right operand
|
||||
parseAndCheckError("1 + ", SpelMessage.RIGHT_OPERAND_PROBLEM, 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBrokenExpression07() {
|
||||
void testBrokenExpression07() {
|
||||
// T() can only take an identifier (possibly qualified), not a literal
|
||||
// message ought to say identifier rather than ID
|
||||
parseAndCheckError("null instanceof T('a')", SpelMessage.NOT_EXPECTED_TOKEN, 18,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -49,7 +49,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
* @author Joyce Zhan
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
public class PropertyAccessTests extends AbstractExpressionTests {
|
||||
class PropertyAccessTests extends AbstractExpressionTests {
|
||||
|
||||
@Test
|
||||
void simpleAccess01() {
|
||||
@@ -291,7 +291,7 @@ public class PropertyAccessTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public boolean canRead(EvaluationContext context, Object target, String name) {
|
||||
if (!(target instanceof String)) {
|
||||
throw new RuntimeException("Assertion Failed! target should be String");
|
||||
}
|
||||
@@ -299,7 +299,7 @@ public class PropertyAccessTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public boolean canWrite(EvaluationContext context, Object target, String name) {
|
||||
if (!(target instanceof String)) {
|
||||
throw new RuntimeException("Assertion Failed! target should be String");
|
||||
}
|
||||
@@ -307,7 +307,7 @@ public class PropertyAccessTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public TypedValue read(EvaluationContext context, Object target, String name) {
|
||||
if (!name.equals("flibbles")) {
|
||||
throw new RuntimeException("Assertion Failed! name should be flibbles");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -43,10 +43,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class ScenariosForSpringSecurityExpressionTests extends AbstractExpressionTests {
|
||||
class ScenariosForSpringSecurityExpressionTests extends AbstractExpressionTests {
|
||||
|
||||
@Test
|
||||
public void testScenario01_Roles() throws Exception {
|
||||
void testScenario01_Roles() {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
StandardEvaluationContext ctx = new StandardEvaluationContext();
|
||||
Expression expr = parser.parseRaw("hasAnyRole('MANAGER','TELLER')");
|
||||
@@ -61,7 +61,7 @@ public class ScenariosForSpringSecurityExpressionTests extends AbstractExpressio
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScenario02_ComparingNames() throws Exception {
|
||||
void testScenario02_ComparingNames() {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
StandardEvaluationContext ctx = new StandardEvaluationContext();
|
||||
|
||||
@@ -96,7 +96,7 @@ public class ScenariosForSpringSecurityExpressionTests extends AbstractExpressio
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScenario03_Arithmetic() throws Exception {
|
||||
void testScenario03_Arithmetic() {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
StandardEvaluationContext ctx = new StandardEvaluationContext();
|
||||
|
||||
@@ -119,7 +119,7 @@ public class ScenariosForSpringSecurityExpressionTests extends AbstractExpressio
|
||||
|
||||
// Here i'm going to change which hasRole() executes and make it one of my own Java methods
|
||||
@Test
|
||||
public void testScenario04_ControllingWhichMethodsRun() throws Exception {
|
||||
void testScenario04_ControllingWhichMethodsRun() {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
StandardEvaluationContext ctx = new StandardEvaluationContext();
|
||||
|
||||
@@ -219,23 +219,22 @@ public class ScenariosForSpringSecurityExpressionTests extends AbstractExpressio
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public boolean canRead(EvaluationContext context, Object target, String name) {
|
||||
return name.equals("principal");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public TypedValue read(EvaluationContext context, Object target, String name) {
|
||||
return new TypedValue(new Principal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public boolean canWrite(EvaluationContext context, Object target, String name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(EvaluationContext context, Object target, String name, Object newValue)
|
||||
throws AccessException {
|
||||
public void write(EvaluationContext context, Object target, String name, Object newValue) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -254,23 +253,22 @@ public class ScenariosForSpringSecurityExpressionTests extends AbstractExpressio
|
||||
void setPerson(Person p) { this.activePerson = p; }
|
||||
|
||||
@Override
|
||||
public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public boolean canRead(EvaluationContext context, Object target, String name) {
|
||||
return name.equals("p");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public TypedValue read(EvaluationContext context, Object target, String name) {
|
||||
return new TypedValue(activePerson);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public boolean canWrite(EvaluationContext context, Object target, String name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(EvaluationContext context, Object target, String name, Object newValue)
|
||||
throws AccessException {
|
||||
public void write(EvaluationContext context, Object target, String name, Object newValue) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -316,8 +314,7 @@ public class ScenariosForSpringSecurityExpressionTests extends AbstractExpressio
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodExecutor resolve(EvaluationContext context, Object targetObject, String name, List<TypeDescriptor> arguments)
|
||||
throws AccessException {
|
||||
public MethodExecutor resolve(EvaluationContext context, Object targetObject, String name, List<TypeDescriptor> arguments) {
|
||||
if (name.equals("hasRole")) {
|
||||
return new HasRoleExecutor(context.getTypeConverter());
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -43,7 +43,7 @@ class SelectionAndProjectionTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void selectionWithList() throws Exception {
|
||||
void selectionWithList() {
|
||||
Expression expression = new SpelExpressionParser().parseRaw("integers.?[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new ListTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
@@ -53,7 +53,7 @@ class SelectionAndProjectionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void selectFirstItemInList() throws Exception {
|
||||
void selectFirstItemInList() {
|
||||
Expression expression = new SpelExpressionParser().parseRaw("integers.^[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new ListTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
@@ -62,7 +62,7 @@ class SelectionAndProjectionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void selectLastItemInList() throws Exception {
|
||||
void selectLastItemInList() {
|
||||
Expression expression = new SpelExpressionParser().parseRaw("integers.$[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new ListTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
@@ -72,7 +72,7 @@ class SelectionAndProjectionTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void selectionWithSet() throws Exception {
|
||||
void selectionWithSet() {
|
||||
Expression expression = new SpelExpressionParser().parseRaw("integers.?[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new SetTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
@@ -82,7 +82,7 @@ class SelectionAndProjectionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void selectFirstItemInSet() throws Exception {
|
||||
void selectFirstItemInSet() {
|
||||
Expression expression = new SpelExpressionParser().parseRaw("integers.^[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new SetTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
@@ -91,7 +91,7 @@ class SelectionAndProjectionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void selectLastItemInSet() throws Exception {
|
||||
void selectLastItemInSet() {
|
||||
Expression expression = new SpelExpressionParser().parseRaw("integers.$[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new SetTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
@@ -101,7 +101,7 @@ class SelectionAndProjectionTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void selectionWithIterable() throws Exception {
|
||||
void selectionWithIterable() {
|
||||
Expression expression = new SpelExpressionParser().parseRaw("integers.?[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new IterableTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
@@ -111,7 +111,7 @@ class SelectionAndProjectionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void selectionWithArray() throws Exception {
|
||||
void selectionWithArray() {
|
||||
Expression expression = new SpelExpressionParser().parseRaw("integers.?[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
@@ -123,7 +123,7 @@ class SelectionAndProjectionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void selectFirstItemInArray() throws Exception {
|
||||
void selectFirstItemInArray() {
|
||||
Expression expression = new SpelExpressionParser().parseRaw("integers.^[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
@@ -132,7 +132,7 @@ class SelectionAndProjectionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void selectLastItemInArray() throws Exception {
|
||||
void selectLastItemInArray() {
|
||||
Expression expression = new SpelExpressionParser().parseRaw("integers.$[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
@@ -141,7 +141,7 @@ class SelectionAndProjectionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void selectionWithPrimitiveArray() throws Exception {
|
||||
void selectionWithPrimitiveArray() {
|
||||
Expression expression = new SpelExpressionParser().parseRaw("ints.?[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
@@ -153,7 +153,7 @@ class SelectionAndProjectionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void selectFirstItemInPrimitiveArray() throws Exception {
|
||||
void selectFirstItemInPrimitiveArray() {
|
||||
Expression expression = new SpelExpressionParser().parseRaw("ints.^[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
@@ -162,7 +162,7 @@ class SelectionAndProjectionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void selectLastItemInPrimitiveArray() throws Exception {
|
||||
void selectLastItemInPrimitiveArray() {
|
||||
Expression expression = new SpelExpressionParser().parseRaw("ints.$[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
@@ -205,7 +205,7 @@ class SelectionAndProjectionTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void projectionWithList() throws Exception {
|
||||
void projectionWithList() {
|
||||
Expression expression = new SpelExpressionParser().parseRaw("#testList.![wrapper.value]");
|
||||
EvaluationContext context = new StandardEvaluationContext();
|
||||
context.setVariable("testList", IntegerTestBean.createList());
|
||||
@@ -217,7 +217,7 @@ class SelectionAndProjectionTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void projectionWithSet() throws Exception {
|
||||
void projectionWithSet() {
|
||||
Expression expression = new SpelExpressionParser().parseRaw("#testList.![wrapper.value]");
|
||||
EvaluationContext context = new StandardEvaluationContext();
|
||||
context.setVariable("testList", IntegerTestBean.createSet());
|
||||
@@ -229,7 +229,7 @@ class SelectionAndProjectionTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void projectionWithIterable() throws Exception {
|
||||
void projectionWithIterable() {
|
||||
Expression expression = new SpelExpressionParser().parseRaw("#testList.![wrapper.value]");
|
||||
EvaluationContext context = new StandardEvaluationContext();
|
||||
context.setVariable("testList", IntegerTestBean.createIterable());
|
||||
@@ -240,7 +240,7 @@ class SelectionAndProjectionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void projectionWithArray() throws Exception {
|
||||
void projectionWithArray() {
|
||||
Expression expression = new SpelExpressionParser().parseRaw("#testArray.![wrapper.value]");
|
||||
EvaluationContext context = new StandardEvaluationContext();
|
||||
context.setVariable("testArray", IntegerTestBean.createArray());
|
||||
@@ -296,7 +296,7 @@ class SelectionAndProjectionTests {
|
||||
}
|
||||
|
||||
public Iterable<Integer> getIntegers() {
|
||||
return integers::iterator;
|
||||
return integers;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -373,7 +373,7 @@ class SelectionAndProjectionTests {
|
||||
|
||||
static Iterable<IntegerTestBean> createIterable() {
|
||||
final Set<IntegerTestBean> set = createSet();
|
||||
return set::iterator;
|
||||
return set;
|
||||
}
|
||||
|
||||
static IntegerTestBean[] createArray() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -36,39 +36,39 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
* @author Keith Donald
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class SetValueTests extends AbstractExpressionTests {
|
||||
class SetValueTests extends AbstractExpressionTests {
|
||||
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
|
||||
@Test
|
||||
public void testSetProperty() {
|
||||
void testSetProperty() {
|
||||
setValue("wonNobelPrize", true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetNestedProperty() {
|
||||
void testSetNestedProperty() {
|
||||
setValue("placeOfBirth.city", "Wien");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetArrayElementValue() {
|
||||
void testSetArrayElementValue() {
|
||||
setValue("inventions[0]", "Just the telephone");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorCase() {
|
||||
void testErrorCase() {
|
||||
setValueExpectError("3=4", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetElementOfNull() {
|
||||
void testSetElementOfNull() {
|
||||
setValueExpectError("new org.springframework.expression.spel.testresources.Inventor().inventions[1]",
|
||||
SpelMessage.CANNOT_INDEX_INTO_NULL_VALUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetArrayElementValueAllPrimitiveTypes() {
|
||||
void testSetArrayElementValueAllPrimitiveTypes() {
|
||||
setValue("arrayContainer.ints[1]", 3);
|
||||
setValue("arrayContainer.floats[1]", 3.0f);
|
||||
setValue("arrayContainer.booleans[1]", false);
|
||||
@@ -80,7 +80,7 @@ public class SetValueTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsWritableForInvalidExpressions_SPR10610() {
|
||||
void testIsWritableForInvalidExpressions_SPR10610() {
|
||||
StandardEvaluationContext lContext = TestScenarioCreator.getTestEvaluationContext();
|
||||
|
||||
// PROPERTYORFIELDREFERENCE
|
||||
@@ -115,7 +115,7 @@ public class SetValueTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetArrayElementValueAllPrimitiveTypesErrors() {
|
||||
void testSetArrayElementValueAllPrimitiveTypesErrors() {
|
||||
// none of these sets are possible due to (expected) conversion problems
|
||||
setValueExpectError("arrayContainer.ints[1]", "wibble");
|
||||
setValueExpectError("arrayContainer.floats[1]", "dribble");
|
||||
@@ -129,59 +129,59 @@ public class SetValueTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetArrayElementNestedValue() {
|
||||
void testSetArrayElementNestedValue() {
|
||||
setValue("placesLived[0].city", "Wien");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetListElementValue() {
|
||||
void testSetListElementValue() {
|
||||
setValue("placesLivedList[0]", new PlaceOfBirth("Wien"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetGenericListElementValueTypeCoercion() {
|
||||
void testSetGenericListElementValueTypeCoercion() {
|
||||
// TODO currently failing since setValue does a getValue and "Wien" string != PlaceOfBirth - check with andy
|
||||
setValue("placesLivedList[0]", "Wien");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetGenericListElementValueTypeCoercionOK() {
|
||||
void testSetGenericListElementValueTypeCoercionOK() {
|
||||
setValue("booleanList[0]", "true", Boolean.TRUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetListElementNestedValue() {
|
||||
void testSetListElementNestedValue() {
|
||||
setValue("placesLived[0].city", "Wien");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetArrayElementInvalidIndex() {
|
||||
void testSetArrayElementInvalidIndex() {
|
||||
setValueExpectError("placesLived[23]", "Wien");
|
||||
setValueExpectError("placesLivedList[23]", "Wien");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetMapElements() {
|
||||
void testSetMapElements() {
|
||||
setValue("testMap['montag']","lundi");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexingIntoUnsupportedType() {
|
||||
void testIndexingIntoUnsupportedType() {
|
||||
setValueExpectError("'hello'[3]", 'p');
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetPropertyTypeCoercion() {
|
||||
void testSetPropertyTypeCoercion() {
|
||||
setValue("publicBoolean", "true", Boolean.TRUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetPropertyTypeCoercionThroughSetter() {
|
||||
void testSetPropertyTypeCoercionThroughSetter() {
|
||||
setValue("SomeProperty", "true", Boolean.TRUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAssign() throws Exception {
|
||||
void testAssign() {
|
||||
StandardEvaluationContext eContext = TestScenarioCreator.getTestEvaluationContext();
|
||||
Expression e = parse("publicName='Andy'");
|
||||
assertThat(e.isWritable(eContext)).isFalse();
|
||||
@@ -192,7 +192,7 @@ public class SetValueTests extends AbstractExpressionTests {
|
||||
* Testing the coercion of both the keys and the values to the correct type
|
||||
*/
|
||||
@Test
|
||||
public void testSetGenericMapElementRequiresCoercion() throws Exception {
|
||||
void testSetGenericMapElementRequiresCoercion() {
|
||||
StandardEvaluationContext eContext = TestScenarioCreator.getTestEvaluationContext();
|
||||
Expression e = parse("mapOfStringToBoolean[42]");
|
||||
assertThat(e.getValue(eContext)).isNull();
|
||||
@@ -218,7 +218,7 @@ public class SetValueTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
|
||||
private Expression parse(String expressionString) throws Exception {
|
||||
private Expression parse(String expressionString) {
|
||||
return parser.parseExpression(expressionString);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -52,6 +52,7 @@ import static org.assertj.core.api.Assertions.assertThatException;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.within;
|
||||
import static org.assertj.core.api.InstanceOfAssertFactories.BOOLEAN;
|
||||
import static org.springframework.expression.spel.standard.SpelExpressionTestUtils.assertIsCompiled;
|
||||
|
||||
/**
|
||||
* Checks SpelCompiler behavior. This should cover compilation all compiled node types.
|
||||
@@ -250,7 +251,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void operatorInstanceOf_SPR14250() throws Exception {
|
||||
void operatorInstanceOf_SPR14250() {
|
||||
// primitive left operand - should get boxed, return true
|
||||
expression = parse("3 instanceof T(Integer)");
|
||||
assertThat(expression.getValue()).asInstanceOf(BOOLEAN).isTrue();
|
||||
@@ -297,7 +298,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void stringLiteral() throws Exception {
|
||||
void stringLiteral() {
|
||||
expression = parser.parseExpression("'abcde'");
|
||||
assertThat(expression.getValue(new TestClass1(), String.class)).isEqualTo("abcde");
|
||||
assertCanCompile(expression);
|
||||
@@ -312,7 +313,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void nullLiteral() throws Exception {
|
||||
void nullLiteral() {
|
||||
expression = parser.parseExpression("null");
|
||||
Object resultI = expression.getValue(new TestClass1(), Object.class);
|
||||
assertCanCompile(expression);
|
||||
@@ -323,7 +324,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void realLiteral() throws Exception {
|
||||
void realLiteral() {
|
||||
expression = parser.parseExpression("3.4d");
|
||||
double resultI = expression.getValue(new TestClass1(), Double.TYPE);
|
||||
assertCanCompile(expression);
|
||||
@@ -337,7 +338,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Test
|
||||
void inlineList() throws Exception {
|
||||
void inlineList() {
|
||||
expression = parser.parseExpression("'abcde'.substring({1,3,4}[0])");
|
||||
Object o = expression.getValue();
|
||||
assertThat(o).isEqualTo("bcde");
|
||||
@@ -376,7 +377,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Test
|
||||
void nestedInlineLists() throws Exception {
|
||||
public void nestedInlineLists() {
|
||||
Object o = null;
|
||||
|
||||
expression = parser.parseExpression("{{1,2,3},{4,5,6},{7,8,9}}");
|
||||
@@ -451,7 +452,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void intLiteral() throws Exception {
|
||||
void intLiteral() {
|
||||
expression = parser.parseExpression("42");
|
||||
int resultI = expression.getValue(new TestClass1(), Integer.TYPE);
|
||||
assertCanCompile(expression);
|
||||
@@ -482,7 +483,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void longLiteral() throws Exception {
|
||||
void longLiteral() {
|
||||
expression = parser.parseExpression("99L");
|
||||
long resultI = expression.getValue(new TestClass1(), Long.TYPE);
|
||||
assertCanCompile(expression);
|
||||
@@ -492,7 +493,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void booleanLiteral() throws Exception {
|
||||
void booleanLiteral() {
|
||||
expression = parser.parseExpression("true");
|
||||
boolean resultI = expression.getValue(1, Boolean.TYPE);
|
||||
assertThat(resultI).isTrue();
|
||||
@@ -509,7 +510,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void floatLiteral() throws Exception {
|
||||
void floatLiteral() {
|
||||
expression = parser.parseExpression("3.4f");
|
||||
float resultI = expression.getValue(new TestClass1(), Float.TYPE);
|
||||
assertCanCompile(expression);
|
||||
@@ -522,7 +523,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void opOr() throws Exception {
|
||||
void opOr() {
|
||||
Expression expression = parser.parseExpression("false or false");
|
||||
boolean resultI = expression.getValue(1, Boolean.TYPE);
|
||||
SpelCompiler.compile(expression);
|
||||
@@ -584,7 +585,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void opAnd() throws Exception {
|
||||
void opAnd() {
|
||||
Expression expression = parser.parseExpression("false and false");
|
||||
boolean resultI = expression.getValue(1, Boolean.TYPE);
|
||||
SpelCompiler.compile(expression);
|
||||
@@ -644,7 +645,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void operatorNot() throws Exception {
|
||||
void operatorNot() {
|
||||
expression = parse("!true");
|
||||
assertThat(expression.getValue()).isEqualTo(false);
|
||||
assertCanCompile(expression);
|
||||
@@ -669,7 +670,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ternary() throws Exception {
|
||||
void ternary() {
|
||||
Expression expression = parser.parseExpression("true?'a':'b'");
|
||||
String resultI = expression.getValue(String.class);
|
||||
assertCanCompile(expression);
|
||||
@@ -702,7 +703,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ternaryWithBooleanReturn_SPR12271() {
|
||||
void ternaryWithBooleanReturn_SPR12271() {
|
||||
expression = parser.parseExpression("T(Boolean).TRUE?'abc':'def'");
|
||||
assertThat(expression.getValue()).isEqualTo("abc");
|
||||
assertCanCompile(expression);
|
||||
@@ -715,7 +716,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullsafeFieldPropertyDereferencing_SPR16489() throws Exception {
|
||||
void nullsafeFieldPropertyDereferencing_SPR16489() {
|
||||
FooObjectHolder foh = new FooObjectHolder();
|
||||
StandardEvaluationContext context = new StandardEvaluationContext();
|
||||
context.setRootObject(foh);
|
||||
@@ -772,7 +773,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test // gh-27421
|
||||
public void nullSafeMethodChainingWithNonStaticVoidMethod() throws Exception {
|
||||
public void nullSafeMethodChainingWithNonStaticVoidMethod() {
|
||||
FooObjectHolder foh = new FooObjectHolder();
|
||||
StandardEvaluationContext context = new StandardEvaluationContext(foh);
|
||||
SpelExpression expression = (SpelExpression) parser.parseExpression("getFoo()?.doFoo()");
|
||||
@@ -800,7 +801,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullsafeMethodChaining_SPR16489() throws Exception {
|
||||
void nullsafeMethodChaining_SPR16489() {
|
||||
FooObjectHolder foh = new FooObjectHolder();
|
||||
StandardEvaluationContext context = new StandardEvaluationContext();
|
||||
context.setRootObject(foh);
|
||||
@@ -902,7 +903,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void elvis() throws Exception {
|
||||
void elvis() {
|
||||
Expression expression = parser.parseExpression("'a'?:'b'");
|
||||
String resultI = expression.getValue(String.class);
|
||||
assertCanCompile(expression);
|
||||
@@ -926,7 +927,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void variableReference_root() throws Exception {
|
||||
void variableReference_root() {
|
||||
String s = "hello";
|
||||
Expression expression = parser.parseExpression("#root");
|
||||
String resultI = expression.getValue(s, String.class);
|
||||
@@ -956,7 +957,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compiledExpressionShouldWorkWhenUsingCustomFunctionWithVarargs() throws Exception {
|
||||
void compiledExpressionShouldWorkWhenUsingCustomFunctionWithVarargs() throws Exception {
|
||||
StandardEvaluationContext context = null;
|
||||
|
||||
// Here the target method takes Object... and we are passing a string
|
||||
@@ -996,7 +997,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void functionReference() throws Exception {
|
||||
void functionReference() throws Exception {
|
||||
EvaluationContext ctx = new StandardEvaluationContext();
|
||||
Method m = getClass().getDeclaredMethod("concat", String.class, String.class);
|
||||
ctx.setVariable("concat",m);
|
||||
@@ -1083,7 +1084,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void functionReferenceVisibility_SPR12359() throws Exception {
|
||||
void functionReferenceVisibility_SPR12359() throws Exception {
|
||||
// Confirms visibility of what is being called.
|
||||
StandardEvaluationContext context = new StandardEvaluationContext(new Object[] {"1"});
|
||||
context.registerFunction("doCompare", SomeCompareMethod.class.getDeclaredMethod(
|
||||
@@ -1105,7 +1106,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void functionReferenceNonCompilableArguments_SPR12359() throws Exception {
|
||||
void functionReferenceNonCompilableArguments_SPR12359() throws Exception {
|
||||
StandardEvaluationContext context = new StandardEvaluationContext(new Object[] {"1"});
|
||||
context.registerFunction("negate", SomeCompareMethod2.class.getDeclaredMethod(
|
||||
"negate", Integer.TYPE));
|
||||
@@ -1120,7 +1121,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void functionReferenceVarargs_SPR12359() throws Exception {
|
||||
void functionReferenceVarargs_SPR12359() throws Exception {
|
||||
StandardEvaluationContext context = new StandardEvaluationContext();
|
||||
context.registerFunction("append",
|
||||
SomeCompareMethod2.class.getDeclaredMethod("append", String[].class));
|
||||
@@ -1317,7 +1318,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void functionReferenceVarargs() throws Exception {
|
||||
void functionReferenceVarargs() throws Exception {
|
||||
EvaluationContext ctx = new StandardEvaluationContext();
|
||||
Method m = getClass().getDeclaredMethod("join", String[].class);
|
||||
ctx.setVariable("join", m);
|
||||
@@ -1328,7 +1329,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void variableReference_userDefined() throws Exception {
|
||||
void variableReference_userDefined() {
|
||||
EvaluationContext ctx = new StandardEvaluationContext();
|
||||
ctx.setVariable("target", "abc");
|
||||
expression = parser.parseExpression("#target");
|
||||
@@ -1356,7 +1357,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void opLt() throws Exception {
|
||||
void opLt() {
|
||||
expression = parse("3.0d < 4.0d");
|
||||
assertCanCompile(expression);
|
||||
assertThat((Boolean) expression.getValue()).isTrue();
|
||||
@@ -1406,7 +1407,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void opLe() throws Exception {
|
||||
void opLe() {
|
||||
expression = parse("3.0d <= 4.0d");
|
||||
assertCanCompile(expression);
|
||||
assertThat((Boolean) expression.getValue()).isTrue();
|
||||
@@ -1465,7 +1466,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void opGt() throws Exception {
|
||||
void opGt() {
|
||||
expression = parse("3.0d > 4.0d");
|
||||
assertCanCompile(expression);
|
||||
assertThat((Boolean) expression.getValue()).isFalse();
|
||||
@@ -1515,7 +1516,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void opGe() throws Exception {
|
||||
void opGe() {
|
||||
expression = parse("3.0d >= 4.0d");
|
||||
assertCanCompile(expression);
|
||||
assertThat((Boolean) expression.getValue()).isFalse();
|
||||
@@ -1577,7 +1578,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void opEq() throws Exception {
|
||||
void opEq() {
|
||||
String tvar = "35";
|
||||
expression = parse("#root == 35");
|
||||
assertThat((Boolean) expression.getValue(tvar)).isFalse();
|
||||
@@ -1752,7 +1753,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void opNe() throws Exception {
|
||||
void opNe() {
|
||||
expression = parse("3.0d != 4.0d");
|
||||
assertCanCompile(expression);
|
||||
assertThat((Boolean) expression.getValue()).isTrue();
|
||||
@@ -1867,14 +1868,14 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void opNe_SPR14863() throws Exception {
|
||||
void opNe_SPR14863() {
|
||||
SpelParserConfiguration configuration =
|
||||
new SpelParserConfiguration(SpelCompilerMode.MIXED, ClassLoader.getSystemClassLoader());
|
||||
SpelExpressionParser parser = new SpelExpressionParser(configuration);
|
||||
Expression expression = parser.parseExpression("data['my-key'] != 'my-value'");
|
||||
|
||||
Map<String, String> data = new HashMap<>();
|
||||
data.put("my-key", new String("my-value"));
|
||||
data.put("my-key", "my-value");
|
||||
StandardEvaluationContext context = new StandardEvaluationContext(new MyContext(data));
|
||||
assertThat(expression.getValue(context, Boolean.class)).isFalse();
|
||||
assertCanCompile(expression);
|
||||
@@ -1882,7 +1883,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
assertThat(expression.getValue(context, Boolean.class)).isFalse();
|
||||
|
||||
List<String> ls = new ArrayList<>();
|
||||
ls.add(new String("foo"));
|
||||
ls.add("foo");
|
||||
context = new StandardEvaluationContext(ls);
|
||||
expression = parse("get(0) != 'foo'");
|
||||
assertThat(expression.getValue(context, Boolean.class)).isFalse();
|
||||
@@ -1895,7 +1896,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void opEq_SPR14863() throws Exception {
|
||||
void opEq_SPR14863() {
|
||||
// Exercise the comparator invocation code that runs in
|
||||
// equalityCheck() (called from interpreted and compiled code)
|
||||
expression = parser.parseExpression("#aa==#bb");
|
||||
@@ -1930,7 +1931,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
|
||||
|
||||
List<String> ls = new ArrayList<>();
|
||||
ls.add(new String("foo"));
|
||||
ls.add("foo");
|
||||
StandardEvaluationContext context = new StandardEvaluationContext(ls);
|
||||
expression = parse("get(0) == 'foo'");
|
||||
assertThat(expression.getValue(context, Boolean.class)).isTrue();
|
||||
@@ -1943,7 +1944,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void opPlus() throws Exception {
|
||||
void opPlus() {
|
||||
expression = parse("2+2");
|
||||
expression.getValue();
|
||||
assertCanCompile(expression);
|
||||
@@ -2036,7 +2037,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void opDivide_mixedNumberTypes() throws Exception {
|
||||
void opDivide_mixedNumberTypes() {
|
||||
PayloadX p = new PayloadX();
|
||||
|
||||
// This is what you had to do before the changes in order for it to compile:
|
||||
@@ -2218,7 +2219,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void opPlus_mixedNumberTypes() throws Exception {
|
||||
void opPlus_mixedNumberTypes() {
|
||||
PayloadX p = new PayloadX();
|
||||
|
||||
// This is what you had to do before the changes in order for it to compile:
|
||||
@@ -2428,7 +2429,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void opPlusString() throws Exception {
|
||||
void opPlusString() {
|
||||
expression = parse("'hello' + 'world'");
|
||||
assertThat(expression.getValue()).isEqualTo("helloworld");
|
||||
assertCanCompile(expression);
|
||||
@@ -2484,7 +2485,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void opMinus() throws Exception {
|
||||
void opMinus() {
|
||||
expression = parse("2-2");
|
||||
expression.getValue();
|
||||
assertCanCompile(expression);
|
||||
@@ -2572,7 +2573,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void opMinus_mixedNumberTypes() throws Exception {
|
||||
void opMinus_mixedNumberTypes() {
|
||||
PayloadX p = new PayloadX();
|
||||
|
||||
// This is what you had to do before the changes in order for it to compile:
|
||||
@@ -2754,7 +2755,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void opMultiply_mixedNumberTypes() throws Exception {
|
||||
void opMultiply_mixedNumberTypes() {
|
||||
PayloadX p = new PayloadX();
|
||||
|
||||
// This is what you had to do before the changes in order for it to compile:
|
||||
@@ -2936,7 +2937,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void opModulus_mixedNumberTypes() throws Exception {
|
||||
void opModulus_mixedNumberTypes() {
|
||||
PayloadX p = new PayloadX();
|
||||
|
||||
// This is what you had to do before the changes in order for it to compile:
|
||||
@@ -3118,7 +3119,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void opMultiply() throws Exception {
|
||||
void opMultiply() {
|
||||
expression = parse("2*2");
|
||||
expression.getValue();
|
||||
assertCanCompile(expression);
|
||||
@@ -3176,7 +3177,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void opDivide() throws Exception {
|
||||
void opDivide() {
|
||||
expression = parse("2/2");
|
||||
expression.getValue();
|
||||
assertCanCompile(expression);
|
||||
@@ -3234,7 +3235,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void opModulus_12041() throws Exception {
|
||||
void opModulus_12041() {
|
||||
expression = parse("2%2");
|
||||
assertThat(expression.getValue()).isEqualTo(0);
|
||||
assertCanCompile(expression);
|
||||
@@ -3309,7 +3310,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compilationOfBasicNullSafeMethodReference() {
|
||||
void compilationOfBasicNullSafeMethodReference() {
|
||||
SpelExpressionParser parser = new SpelExpressionParser(
|
||||
new SpelParserConfiguration(SpelCompilerMode.OFF, getClass().getClassLoader()));
|
||||
SpelExpression expression = parser.parseRaw("#it?.equals(3)");
|
||||
@@ -3329,7 +3330,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failsWhenSettingContextForExpression_SPR12326() {
|
||||
void failsWhenSettingContextForExpression_SPR12326() {
|
||||
SpelExpressionParser parser = new SpelExpressionParser(
|
||||
new SpelParserConfiguration(SpelCompilerMode.OFF, getClass().getClassLoader()));
|
||||
Person3 person = new Person3("foo", 1);
|
||||
@@ -3356,7 +3357,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
* Test variants of using T(...) and static/non-static method/property/field references.
|
||||
*/
|
||||
@Test
|
||||
public void constructorReference_SPR13781() {
|
||||
void constructorReference_SPR13781() {
|
||||
// Static field access on a T() referenced type
|
||||
expression = parser.parseExpression("T(java.util.Locale).ENGLISH");
|
||||
assertThat(expression.getValue().toString()).isEqualTo("en");
|
||||
@@ -3448,7 +3449,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorReference_SPR12326() {
|
||||
void constructorReference_SPR12326() {
|
||||
String type = getClass().getName();
|
||||
String prefix = "new " + type + ".Obj";
|
||||
|
||||
@@ -3509,7 +3510,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void methodReferenceMissingCastAndRootObjectAccessing_SPR12326() {
|
||||
void methodReferenceMissingCastAndRootObjectAccessing_SPR12326() {
|
||||
// Need boxing code on the 1 so that toString() can be called
|
||||
expression = parser.parseExpression("1.toString()");
|
||||
assertThat(expression.getValue()).isEqualTo("1");
|
||||
@@ -3549,7 +3550,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorReference() throws Exception {
|
||||
void constructorReference() {
|
||||
// simple ctor
|
||||
expression = parser.parseExpression("new String('123')");
|
||||
assertThat(expression.getValue()).isEqualTo("123");
|
||||
@@ -3594,7 +3595,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void methodReferenceReflectiveMethodSelectionWithVarargs() throws Exception {
|
||||
void methodReferenceReflectiveMethodSelectionWithVarargs() {
|
||||
TestClass10 tc = new TestClass10();
|
||||
|
||||
// Should call the non varargs version of concat
|
||||
@@ -4707,7 +4708,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void variantGetter() throws Exception {
|
||||
void variantGetter() {
|
||||
Payload2Holder holder = new Payload2Holder();
|
||||
StandardEvaluationContext ctx = new StandardEvaluationContext();
|
||||
ctx.addPropertyAccessor(new MyAccessor());
|
||||
@@ -4917,7 +4918,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void indexerMapAccessor_12045() throws Exception {
|
||||
void indexerMapAccessor_12045() {
|
||||
SpelParserConfiguration spc = new SpelParserConfiguration(
|
||||
SpelCompilerMode.IMMEDIATE,getClass().getClassLoader());
|
||||
SpelExpressionParser sep = new SpelExpressionParser(spc);
|
||||
@@ -5302,18 +5303,6 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
assertThatException().isThrownBy(expression::getValue);
|
||||
}
|
||||
|
||||
public static void assertIsCompiled(Expression expression) {
|
||||
try {
|
||||
Field field = SpelExpression.class.getDeclaredField("compiledAst");
|
||||
field.setAccessible(true);
|
||||
Object object = field.get(expression);
|
||||
assertThat(object).isNotNull();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new AssertionError(ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Nested types
|
||||
|
||||
@@ -5404,24 +5393,24 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public boolean canRead(EvaluationContext context, Object target, String name) {
|
||||
// target is a Payload2 instance
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public TypedValue read(EvaluationContext context, Object target, String name) {
|
||||
Payload2 payload2 = (Payload2)target;
|
||||
return new TypedValue(payload2.getField(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public boolean canWrite(EvaluationContext context, Object target, String name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(EvaluationContext context, Object target, String name, Object newValue) throws AccessException {
|
||||
public void write(EvaluationContext context, Object target, String name, Object newValue) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -5461,7 +5450,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
static class CompilableMapAccessor implements CompilablePropertyAccessor {
|
||||
|
||||
@Override
|
||||
public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public boolean canRead(EvaluationContext context, Object target, String name) {
|
||||
Map<?,?> map = (Map<?,?>) target;
|
||||
return map.containsKey(name);
|
||||
}
|
||||
@@ -5477,13 +5466,13 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public boolean canWrite(EvaluationContext context, Object target, String name) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void write(EvaluationContext context, Object target, String name, Object newValue) throws AccessException {
|
||||
public void write(EvaluationContext context, Object target, String name, Object newValue) {
|
||||
Map<String, Object> map = (Map<String, Object>) target;
|
||||
map.put(name, newValue);
|
||||
}
|
||||
@@ -6092,7 +6081,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
public Obj3(int... params) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
for (int param: params) {
|
||||
b.append(Integer.toString(param));
|
||||
b.append(param);
|
||||
}
|
||||
output = b.toString();
|
||||
}
|
||||
@@ -6101,10 +6090,10 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
StringBuilder b = new StringBuilder();
|
||||
b.append(s);
|
||||
b.append(':');
|
||||
b.append(Float.toString(f));
|
||||
b.append(f);
|
||||
b.append(':');
|
||||
for (int param: ints) {
|
||||
b.append(Integer.toString(param));
|
||||
b.append(param);
|
||||
}
|
||||
output = b.toString();
|
||||
}
|
||||
@@ -6118,7 +6107,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
public Obj4(int[] params) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
for (int param: params) {
|
||||
b.append(Integer.toString(param));
|
||||
b.append(param);
|
||||
}
|
||||
output = b.toString();
|
||||
}
|
||||
@@ -6302,15 +6291,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
@Override
|
||||
public int compareTo(Apple that) {
|
||||
this.gotComparedTo = that;
|
||||
if (this.i < that.i) {
|
||||
return -1;
|
||||
}
|
||||
else if (this.i > that.i) {
|
||||
return +1;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
return Integer.compare(this.i, that.i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -51,7 +51,7 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
|
||||
* different operand types.
|
||||
*/
|
||||
@Test
|
||||
public void compilingMathematicalExpressionsWithDifferentOperandTypes() throws Exception {
|
||||
void compilingMathematicalExpressionsWithDifferentOperandTypes() {
|
||||
NumberHolder nh = new NumberHolder();
|
||||
expression = parser.parseExpression("(T(Integer).valueOf(payload).doubleValue())/18D");
|
||||
Object o = expression.getValue(nh);
|
||||
@@ -135,7 +135,7 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inlineLists() throws Exception {
|
||||
void inlineLists() {
|
||||
expression = parser.parseExpression("{'abcde','ijklm'}[0].substring({1,3,4}[0],{1,3,4}[1])");
|
||||
Object o = expression.getValue();
|
||||
assertThat(o).isEqualTo("bc");
|
||||
@@ -178,7 +178,7 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inlineNestedLists() throws Exception {
|
||||
void inlineNestedLists() {
|
||||
expression = parser.parseExpression("{'abcde',{'ijklm','nopqr'}}[1][0].substring({1,3,4}[0],{1,3,4}[1])");
|
||||
Object o = expression.getValue();
|
||||
assertThat(o).isEqualTo("jk");
|
||||
@@ -221,7 +221,7 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stringConcatenation() throws Exception {
|
||||
void stringConcatenation() {
|
||||
expression = parser.parseExpression("'hello' + getWorld() + ' spring'");
|
||||
Greeter g = new Greeter();
|
||||
Object o = expression.getValue(g);
|
||||
@@ -266,7 +266,7 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void complexExpressionPerformance() throws Exception {
|
||||
void complexExpressionPerformance() {
|
||||
Payload payload = new Payload();
|
||||
Expression expression = parser.parseExpression("DR[0].DRFixedSection.duration lt 0.1");
|
||||
boolean b = false;
|
||||
@@ -327,7 +327,7 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compilingMethodReference() throws Exception {
|
||||
void compilingMethodReference() {
|
||||
long interpretedTotal = 0, compiledTotal = 0;
|
||||
long stime,etime;
|
||||
String interpretedResult = null,compiledResult = null;
|
||||
@@ -380,7 +380,7 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void compilingPropertyReferenceField() throws Exception {
|
||||
void compilingPropertyReferenceField() {
|
||||
long interpretedTotal = 0, compiledTotal = 0, stime, etime;
|
||||
String interpretedResult = null, compiledResult = null;
|
||||
|
||||
@@ -426,7 +426,7 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compilingPropertyReferenceNestedField() throws Exception {
|
||||
void compilingPropertyReferenceNestedField() {
|
||||
long interpretedTotal = 0, compiledTotal = 0, stime, etime;
|
||||
String interpretedResult = null, compiledResult = null;
|
||||
|
||||
@@ -472,7 +472,7 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compilingPropertyReferenceNestedMixedFieldGetter() throws Exception {
|
||||
void compilingPropertyReferenceNestedMixedFieldGetter() {
|
||||
long interpretedTotal = 0, compiledTotal = 0, stime, etime;
|
||||
String interpretedResult = null, compiledResult = null;
|
||||
|
||||
@@ -517,7 +517,7 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compilingNestedMixedFieldPropertyReferenceMethodReference() throws Exception {
|
||||
void compilingNestedMixedFieldPropertyReferenceMethodReference() {
|
||||
long interpretedTotal = 0, compiledTotal = 0, stime, etime;
|
||||
String interpretedResult = null, compiledResult = null;
|
||||
|
||||
@@ -564,7 +564,7 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compilingPropertyReferenceGetter() throws Exception {
|
||||
void compilingPropertyReferenceGetter() {
|
||||
long interpretedTotal = 0, compiledTotal = 0, stime, etime;
|
||||
String interpretedResult = null, compiledResult = null;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -35,10 +35,10 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
* @author Juergen Hoeller
|
||||
* @author DJ Kulkarni
|
||||
*/
|
||||
public class SpelExceptionTests {
|
||||
class SpelExceptionTests {
|
||||
|
||||
@Test
|
||||
public void spelExpressionMapNullVariables() {
|
||||
void spelExpressionMapNullVariables() {
|
||||
ExpressionParser parser = new SpelExpressionParser();
|
||||
Expression spelExpression = parser.parseExpression("#aMap.containsKey('one')");
|
||||
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(
|
||||
@@ -46,7 +46,7 @@ public class SpelExceptionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spelExpressionMapIndexAccessNullVariables() {
|
||||
void spelExpressionMapIndexAccessNullVariables() {
|
||||
ExpressionParser parser = new SpelExpressionParser();
|
||||
Expression spelExpression = parser.parseExpression("#aMap['one'] eq 1");
|
||||
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(
|
||||
@@ -77,7 +77,7 @@ public class SpelExceptionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spelExpressionListNullVariables() {
|
||||
void spelExpressionListNullVariables() {
|
||||
ExpressionParser parser = new SpelExpressionParser();
|
||||
Expression spelExpression = parser.parseExpression("#aList.contains('one')");
|
||||
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(
|
||||
@@ -85,7 +85,7 @@ public class SpelExceptionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spelExpressionListIndexAccessNullVariables() {
|
||||
void spelExpressionListIndexAccessNullVariables() {
|
||||
ExpressionParser parser = new SpelExpressionParser();
|
||||
Expression spelExpression = parser.parseExpression("#aList[0] eq 'one'");
|
||||
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(
|
||||
@@ -137,7 +137,7 @@ public class SpelExceptionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spelExpressionArrayIndexAccessNullVariables() {
|
||||
void spelExpressionArrayIndexAccessNullVariables() {
|
||||
ExpressionParser parser = new SpelExpressionParser();
|
||||
Expression spelExpression = parser.parseExpression("#anArray[0] eq 1");
|
||||
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,6 +32,7 @@ import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@@ -1680,12 +1681,7 @@ class SpelReproTests extends AbstractExpressionTests {
|
||||
public String tryToInvokeWithNull3(Integer value, String... strings) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String string : strings) {
|
||||
if (string == null) {
|
||||
sb.append("null");
|
||||
}
|
||||
else {
|
||||
sb.append(string);
|
||||
}
|
||||
sb.append(Objects.requireNonNullElse(string, "null"));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
@@ -1720,23 +1716,23 @@ class SpelReproTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public boolean canRead(EvaluationContext context, Object target, String name) {
|
||||
return (((Map<?, ?>) target).containsKey(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public TypedValue read(EvaluationContext context, Object target, String name) {
|
||||
return new TypedValue(((Map<?, ?>) target).get(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public boolean canWrite(EvaluationContext context, Object target, String name) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void write(EvaluationContext context, Object target, String name, Object newValue) throws AccessException {
|
||||
public void write(EvaluationContext context, Object target, String name, Object newValue) {
|
||||
((Map<String, Object>) target).put(name, newValue);
|
||||
}
|
||||
}
|
||||
@@ -2016,12 +2012,12 @@ class SpelReproTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public boolean canRead(EvaluationContext context, Object target, String name) {
|
||||
return getMap(target).containsKey(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public boolean canWrite(EvaluationContext context, Object target, String name) {
|
||||
return getMap(target).containsKey(name);
|
||||
}
|
||||
|
||||
@@ -2031,12 +2027,12 @@ class SpelReproTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public TypedValue read(EvaluationContext context, Object target, String name) {
|
||||
return new TypedValue(getMap(target).get(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(EvaluationContext context, Object target, String name, Object newValue) throws AccessException {
|
||||
public void write(EvaluationContext context, Object target, String name, Object newValue) {
|
||||
getMap(target).put(name, (String) newValue);
|
||||
}
|
||||
}
|
||||
@@ -2254,7 +2250,7 @@ class SpelReproTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resolve(EvaluationContext context, String beanName) throws AccessException {
|
||||
public Object resolve(EvaluationContext context, String beanName) {
|
||||
return (beanName.equals("bean") ? this : null);
|
||||
}
|
||||
}
|
||||
@@ -2425,15 +2421,15 @@ class SpelReproTests extends AbstractExpressionTests {
|
||||
public static class DistanceEnforcer {
|
||||
|
||||
public static String from(Number no) {
|
||||
return "Number:" + no.toString();
|
||||
return "Number:" + no;
|
||||
}
|
||||
|
||||
public static String from(Integer no) {
|
||||
return "Integer:" + no.toString();
|
||||
return "Integer:" + no;
|
||||
}
|
||||
|
||||
public static String from(Object no) {
|
||||
return "Object:" + no.toString();
|
||||
return "Object:" + no;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public class SpelUtilities {
|
||||
sb.append(indent).append(t.getClass().getSimpleName());
|
||||
sb.append(" value:").append(t.toStringAST());
|
||||
sb.append(t.getChildCount() < 2 ? "" : " #children:" + t.getChildCount());
|
||||
out.println(sb.toString());
|
||||
out.println(sb);
|
||||
for (int i = 0; i < t.getChildCount(); i++) {
|
||||
printAST(out, t.getChild(i), indent + " ");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Andy Clement
|
||||
* @author Giovanni Dall'Oglio Risso
|
||||
*/
|
||||
public class StandardTypeComparatorTests {
|
||||
class StandardTypeComparatorTests {
|
||||
|
||||
@Test
|
||||
void testPrimitives() throws EvaluationException {
|
||||
@@ -121,7 +121,7 @@ public class StandardTypeComparatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldUseCustomComparator() {
|
||||
void shouldUseCustomComparator() {
|
||||
TypeComparator comparator = new StandardTypeComparator();
|
||||
ComparableType t1 = new ComparableType(1);
|
||||
ComparableType t2 = new ComparableType(2);
|
||||
|
||||
@@ -119,9 +119,9 @@ class TestScenarioCreator {
|
||||
c.set(1856, 7, 9);
|
||||
Inventor tesla = new Inventor("Nikola Tesla", c.getTime(), "Serbian");
|
||||
tesla.setPlaceOfBirth(new PlaceOfBirth("SmilJan"));
|
||||
tesla.setInventions(new String[] { "Telephone repeater", "Rotating magnetic field principle",
|
||||
tesla.setInventions("Telephone repeater", "Rotating magnetic field principle",
|
||||
"Polyphase alternating-current system", "Induction motor", "Alternating-current power transmission",
|
||||
"Tesla coil transformer", "Wireless communication", "Radio", "Fluorescent lights" });
|
||||
"Tesla coil transformer", "Wireless communication", "Radio", "Fluorescent lights");
|
||||
testContext.setRootObject(tesla);
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ class TestScenarioCreator {
|
||||
}
|
||||
|
||||
public static String varargsFunction2(int i, String... strings) {
|
||||
return String.valueOf(i) + "-" + Arrays.toString(strings);
|
||||
return i + "-" + Arrays.toString(strings);
|
||||
}
|
||||
|
||||
public static String message(String template, String... args) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,35 +30,35 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
* @author Andy Clement
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
public class VariableAndFunctionTests extends AbstractExpressionTests {
|
||||
class VariableAndFunctionTests extends AbstractExpressionTests {
|
||||
|
||||
@Test
|
||||
public void testVariableAccess01() {
|
||||
void testVariableAccess01() {
|
||||
evaluate("#answer", "42", Integer.class, SHOULD_BE_WRITABLE);
|
||||
evaluate("#answer / 2", 21, Integer.class, SHOULD_NOT_BE_WRITABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVariableAccess_WellKnownVariables() {
|
||||
void testVariableAccess_WellKnownVariables() {
|
||||
evaluate("#this.getName()","Nikola Tesla",String.class);
|
||||
evaluate("#root.getName()","Nikola Tesla",String.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFunctionAccess01() {
|
||||
void testFunctionAccess01() {
|
||||
evaluate("#reverseInt(1,2,3)", "int[3]{3,2,1}", int[].class);
|
||||
evaluate("#reverseInt('1',2,3)", "int[3]{3,2,1}", int[].class); // requires type conversion of '1' to 1
|
||||
evaluateAndCheckError("#reverseInt(1)", SpelMessage.INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION, 0, 1, 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFunctionAccess02() {
|
||||
void testFunctionAccess02() {
|
||||
evaluate("#reverseString('hello')", "olleh", String.class);
|
||||
evaluate("#reverseString(37)", "73", String.class); // requires type conversion of 37 to '37'
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCallVarargsFunction() {
|
||||
void testCallVarargsFunction() {
|
||||
evaluate("#varargsFunction()", "[]", String.class);
|
||||
evaluate("#varargsFunction(new String[0])", "[]", String.class);
|
||||
evaluate("#varargsFunction('a')", "[a]", String.class);
|
||||
@@ -89,7 +89,7 @@ public class VariableAndFunctionTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCallingIllegalFunctions() throws Exception {
|
||||
void testCallingIllegalFunctions() throws Exception {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
StandardEvaluationContext ctx = new StandardEvaluationContext();
|
||||
ctx.setVariable("notStatic", this.getClass().getMethod("nonStatic"));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.expression.spel.ast;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -27,16 +28,16 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
/**
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class FormatHelperTests {
|
||||
class FormatHelperTests {
|
||||
|
||||
@Test
|
||||
public void formatMethodWithSingleArgumentForMessage() {
|
||||
String message = FormatHelper.formatMethodForMessage("foo", Arrays.asList(TypeDescriptor.forObject("a string")));
|
||||
void formatMethodWithSingleArgumentForMessage() {
|
||||
String message = FormatHelper.formatMethodForMessage("foo", List.of(TypeDescriptor.forObject("a string")));
|
||||
assertThat(message).isEqualTo("foo(java.lang.String)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void formatMethodWithMultipleArgumentsForMessage() {
|
||||
void formatMethodWithMultipleArgumentsForMessage() {
|
||||
String message = FormatHelper.formatMethodForMessage("foo", Arrays.asList(TypeDescriptor.forObject("a string"), TypeDescriptor.forObject(5)));
|
||||
assertThat(message).isEqualTo("foo(java.lang.String,java.lang.Integer)");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -42,16 +42,16 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
* @since 3.2
|
||||
* @see OpPlus
|
||||
*/
|
||||
public class OpPlusTests {
|
||||
class OpPlusTests {
|
||||
|
||||
@Test
|
||||
public void test_emptyOperands() {
|
||||
void test_emptyOperands() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
new OpPlus(-1, -1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_unaryPlusWithStringLiteral() {
|
||||
void test_unaryPlusWithStringLiteral() {
|
||||
ExpressionState expressionState = new ExpressionState(new StandardEvaluationContext());
|
||||
|
||||
StringLiteral str = new StringLiteral("word", -1, -1, "word");
|
||||
@@ -62,7 +62,7 @@ public class OpPlusTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_unaryPlusWithNumberOperand() {
|
||||
void test_unaryPlusWithNumberOperand() {
|
||||
ExpressionState expressionState = new ExpressionState(new StandardEvaluationContext());
|
||||
|
||||
{
|
||||
@@ -97,7 +97,7 @@ public class OpPlusTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_binaryPlusWithNumberOperands() {
|
||||
void test_binaryPlusWithNumberOperands() {
|
||||
ExpressionState expressionState = new ExpressionState(new StandardEvaluationContext());
|
||||
|
||||
{
|
||||
@@ -135,7 +135,7 @@ public class OpPlusTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_binaryPlusWithStringOperands() {
|
||||
void test_binaryPlusWithStringOperands() {
|
||||
ExpressionState expressionState = new ExpressionState(new StandardEvaluationContext());
|
||||
|
||||
StringLiteral n1 = new StringLiteral("\"foo\"", -1, -1, "\"foo\"");
|
||||
@@ -149,7 +149,7 @@ public class OpPlusTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_binaryPlusWithLeftStringOperand() {
|
||||
void test_binaryPlusWithLeftStringOperand() {
|
||||
ExpressionState expressionState = new ExpressionState(new StandardEvaluationContext());
|
||||
|
||||
StringLiteral n1 = new StringLiteral("\"number is \"", -1, -1, "\"number is \"");
|
||||
@@ -163,7 +163,7 @@ public class OpPlusTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_binaryPlusWithRightStringOperand() {
|
||||
void test_binaryPlusWithRightStringOperand() {
|
||||
ExpressionState expressionState = new ExpressionState(new StandardEvaluationContext());
|
||||
|
||||
LongLiteral n1 = new LongLiteral("123", -1, -1, 123);
|
||||
@@ -177,7 +177,7 @@ public class OpPlusTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_binaryPlusWithTime_ToString() {
|
||||
void test_binaryPlusWithTime_ToString() {
|
||||
ExpressionState expressionState = new ExpressionState(new StandardEvaluationContext());
|
||||
Time time = new Time(new Date().getTime());
|
||||
|
||||
@@ -194,7 +194,7 @@ public class OpPlusTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_binaryPlusWithTimeConverted() {
|
||||
void test_binaryPlusWithTimeConverted() {
|
||||
SimpleDateFormat format = new SimpleDateFormat("hh :--: mm :--: ss", Locale.ENGLISH);
|
||||
|
||||
GenericConversionService conversionService = new GenericConversionService();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,12 +31,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class PropertiesConversionSpelTests {
|
||||
class PropertiesConversionSpelTests {
|
||||
|
||||
private static final SpelExpressionParser parser = new SpelExpressionParser();
|
||||
|
||||
@Test
|
||||
public void props() {
|
||||
void props() {
|
||||
Properties props = new Properties();
|
||||
props.setProperty("x", "1");
|
||||
props.setProperty("y", "2");
|
||||
@@ -49,7 +49,7 @@ public class PropertiesConversionSpelTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapWithAllStringValues() {
|
||||
void mapWithAllStringValues() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("x", "1");
|
||||
map.put("y", "2");
|
||||
@@ -62,7 +62,7 @@ public class PropertiesConversionSpelTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapWithNonStringValue() {
|
||||
void mapWithNonStringValue() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("x", "1");
|
||||
map.put("y", 2);
|
||||
@@ -76,7 +76,7 @@ public class PropertiesConversionSpelTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customMapWithNonStringValue() {
|
||||
void customMapWithNonStringValue() {
|
||||
CustomMap map = new CustomMap();
|
||||
map.put("x", "1");
|
||||
map.put("y", 2);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,13 +22,13 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.spel.SpelCompilationCoverageTests;
|
||||
import org.springframework.expression.spel.SpelCompilerMode;
|
||||
import org.springframework.expression.spel.SpelParserConfiguration;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.InstanceOfAssertFactories.BOOLEAN;
|
||||
import static org.springframework.expression.spel.standard.SpelExpressionTestUtils.assertIsCompiled;
|
||||
|
||||
/**
|
||||
* Tests for the {@link SpelCompiler}.
|
||||
@@ -64,7 +64,7 @@ class SpelCompilerTests {
|
||||
assertThat(SpelCompiler.compile(expression)).isFalse();
|
||||
assertThat(expression.getValue(context)).isEqualTo(false);
|
||||
assertThat(SpelCompiler.compile(expression)).isTrue();
|
||||
SpelCompilationCoverageTests.assertIsCompiled(expression);
|
||||
assertIsCompiled(expression);
|
||||
assertThat(expression.getValue(context)).isEqualTo(false);
|
||||
|
||||
context.setVariable("user", new User());
|
||||
@@ -72,7 +72,7 @@ class SpelCompilerTests {
|
||||
assertThat(SpelCompiler.compile(expression)).isFalse();
|
||||
assertThat(expression.getValue(context)).asInstanceOf(BOOLEAN).isTrue();
|
||||
assertThat(SpelCompiler.compile(expression)).isTrue();
|
||||
SpelCompilationCoverageTests.assertIsCompiled(expression);
|
||||
assertIsCompiled(expression);
|
||||
assertThat(expression.getValue(context)).asInstanceOf(BOOLEAN).isTrue();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.expression.spel.standard;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.springframework.expression.Expression;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests utilities for {@link SpelExpression}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public abstract class SpelExpressionTestUtils {
|
||||
|
||||
public static void assertIsCompiled(Expression expression) {
|
||||
try {
|
||||
Field field = SpelExpression.class.getDeclaredField("compiledAst");
|
||||
field.setAccessible(true);
|
||||
Object object = field.get(expression);
|
||||
assertThat(object).isNotNull();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new AssertionError(ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -34,7 +34,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
public class StandardComponentsTests {
|
||||
|
||||
@Test
|
||||
public void testStandardEvaluationContext() {
|
||||
void testStandardEvaluationContext() {
|
||||
StandardEvaluationContext context = new StandardEvaluationContext();
|
||||
assertThat(context.getTypeComparator()).isNotNull();
|
||||
|
||||
@@ -48,7 +48,7 @@ public class StandardComponentsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStandardOperatorOverloader() throws EvaluationException {
|
||||
void testStandardOperatorOverloader() throws EvaluationException {
|
||||
OperatorOverloader oo = new StandardOperatorOverloader();
|
||||
assertThat(oo.overridesOperation(Operation.ADD, null, null)).isFalse();
|
||||
assertThatExceptionOfType(EvaluationException.class).isThrownBy(() ->
|
||||
@@ -56,7 +56,7 @@ public class StandardComponentsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStandardTypeLocator() {
|
||||
void testStandardTypeLocator() {
|
||||
StandardTypeLocator tl = new StandardTypeLocator();
|
||||
List<String> prefixes = tl.getImportPrefixes();
|
||||
assertThat(prefixes).hasSize(1);
|
||||
@@ -69,7 +69,7 @@ public class StandardComponentsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStandardTypeConverter() throws EvaluationException {
|
||||
void testStandardTypeConverter() throws EvaluationException {
|
||||
TypeConverter tc = new StandardTypeConverter();
|
||||
tc.convertValue(3, TypeDescriptor.forObject(3), TypeDescriptor.valueOf(Double.class));
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ public class Inventor {
|
||||
}
|
||||
|
||||
public String aVarargsMethod2(int i, String... strings) {
|
||||
return String.valueOf(i) + "-" + Arrays.toString(strings);
|
||||
return i + "-" + Arrays.toString(strings);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
Reference in New Issue
Block a user