Merge branch '5.3.x'

This commit is contained in:
Sam Brannen
2022-01-10 14:21:25 +01:00
72 changed files with 334 additions and 322 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2022 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.
@@ -64,7 +64,7 @@ public class ExpressionStateTests extends AbstractExpressionTests {
state.setLocalVariable("foo", null);
value = state.lookupLocalVariable("foo");
assertThat(value).isEqualTo(null);
assertThat(value).isNull();
}
@Test
@@ -101,7 +101,7 @@ public class ExpressionStateTests extends AbstractExpressionTests {
@Test
public void testLocalVariableNestedScopes() {
ExpressionState state = getState();
assertThat(state.lookupLocalVariable("foo")).isEqualTo(null);
assertThat(state.lookupLocalVariable("foo")).isNull();
state.setLocalVariable("foo",12);
assertThat(state.lookupLocalVariable("foo")).isEqualTo(12);
@@ -134,7 +134,7 @@ public class ExpressionStateTests extends AbstractExpressionTests {
((StandardEvaluationContext) state.getEvaluationContext()).setRootObject(null);
assertThat(state.getRootContextObject().getValue()).isEqualTo(null);
assertThat(state.getRootContextObject().getValue()).isNull();
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 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.
@@ -150,7 +150,7 @@ class IndexingTests {
assertThat(expression.getValueTypeDescriptor(this).toString()).isEqualTo("java.util.Map<java.lang.Integer, java.lang.Integer>");
assertThat(expression.getValue(this)).isEqualTo(property);
expression = parser.parseExpression("parameterizedMap['9']");
assertThat(expression.getValue(this)).isEqualTo(null);
assertThat(expression.getValue(this)).isNull();
expression.setValue(this, "37");
assertThat(expression.getValue(this)).isEqualTo(37);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 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.
@@ -48,6 +48,7 @@ import org.springframework.expression.spel.testdata.PersonInOtherPackage;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.within;
import static org.assertj.core.api.InstanceOfAssertFactories.BOOLEAN;
/**
* Checks SpelCompiler behavior. This should cover compilation all compiled node types.
@@ -198,9 +199,9 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
@Test
void operatorInstanceOf() {
expression = parse("'xyz' instanceof T(String)");
assertThat(expression.getValue()).isEqualTo(true);
assertThat(expression.getValue()).asInstanceOf(BOOLEAN).isTrue();
assertCanCompile(expression);
assertThat(expression.getValue()).isEqualTo(true);
assertThat(expression.getValue()).asInstanceOf(BOOLEAN).isTrue();
expression = parse("'xyz' instanceof T(Integer)");
assertThat(expression.getValue()).isEqualTo(false);
@@ -209,21 +210,21 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
List<String> list = new ArrayList<>();
expression = parse("#root instanceof T(java.util.List)");
assertThat(expression.getValue(list)).isEqualTo(true);
assertThat(expression.getValue(list)).asInstanceOf(BOOLEAN).isTrue();
assertCanCompile(expression);
assertThat(expression.getValue(list)).isEqualTo(true);
assertThat(expression.getValue(list)).asInstanceOf(BOOLEAN).isTrue();
List<String>[] arrayOfLists = new List[] {new ArrayList<String>()};
expression = parse("#root instanceof T(java.util.List[])");
assertThat(expression.getValue(arrayOfLists)).isEqualTo(true);
assertThat(expression.getValue(arrayOfLists)).asInstanceOf(BOOLEAN).isTrue();
assertCanCompile(expression);
assertThat(expression.getValue(arrayOfLists)).isEqualTo(true);
assertThat(expression.getValue(arrayOfLists)).asInstanceOf(BOOLEAN).isTrue();
int[] intArray = new int[] {1,2,3};
expression = parse("#root instanceof T(int[])");
assertThat(expression.getValue(intArray)).isEqualTo(true);
assertThat(expression.getValue(intArray)).asInstanceOf(BOOLEAN).isTrue();
assertCanCompile(expression);
assertThat(expression.getValue(intArray)).isEqualTo(true);
assertThat(expression.getValue(intArray)).asInstanceOf(BOOLEAN).isTrue();
String root = null;
expression = parse("#root instanceof T(Integer)");
@@ -239,18 +240,18 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
root = "howdy!";
expression = parse("#root instanceof T(java.lang.Object)");
assertThat(expression.getValue(root)).isEqualTo(true);
assertThat(expression.getValue(root)).asInstanceOf(BOOLEAN).isTrue();
assertCanCompile(expression);
assertThat(expression.getValue(root)).isEqualTo(true);
assertThat(expression.getValue(root)).asInstanceOf(BOOLEAN).isTrue();
}
@Test
void operatorInstanceOf_SPR14250() throws Exception {
// primitive left operand - should get boxed, return true
expression = parse("3 instanceof T(Integer)");
assertThat(expression.getValue()).isEqualTo(true);
assertThat(expression.getValue()).asInstanceOf(BOOLEAN).isTrue();
assertCanCompile(expression);
assertThat(expression.getValue()).isEqualTo(true);
assertThat(expression.getValue()).asInstanceOf(BOOLEAN).isTrue();
// primitive left operand - should get boxed, return false
expression = parse("3 instanceof T(String)");
@@ -266,9 +267,9 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
// double slot left operand - should get boxed, return true
expression = parse("3.0d instanceof T(Double)");
assertThat(expression.getValue()).isEqualTo(true);
assertThat(expression.getValue()).asInstanceOf(BOOLEAN).isTrue();
assertCanCompile(expression);
assertThat(expression.getValue()).isEqualTo(true);
assertThat(expression.getValue()).asInstanceOf(BOOLEAN).isTrue();
// Only when the right hand operand is a direct type reference
// will it be compilable.
@@ -646,9 +647,9 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
assertThat(expression.getValue()).isEqualTo(false);
expression = parse("!false");
assertThat(expression.getValue()).isEqualTo(true);
assertThat(expression.getValue()).asInstanceOf(BOOLEAN).isTrue();
assertCanCompile(expression);
assertThat(expression.getValue()).isEqualTo(true);
assertThat(expression.getValue()).asInstanceOf(BOOLEAN).isTrue();
boolean b = true;
expression = parse("!#root");
@@ -658,9 +659,9 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
b = false;
expression = parse("!#root");
assertThat(expression.getValue(b)).isEqualTo(true);
assertThat(expression.getValue(b)).asInstanceOf(BOOLEAN).isTrue();
assertCanCompile(expression);
assertThat(expression.getValue(b)).isEqualTo(true);
assertThat(expression.getValue(b)).asInstanceOf(BOOLEAN).isTrue();
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2022 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,6 +28,7 @@ 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;
/**
* Tests for the {@link SpelCompiler}.
@@ -69,10 +70,10 @@ class SpelCompilerTests {
context.setVariable("user", new User());
expression = parser.parseExpression("#root.isEditable(#user)");
assertThat(SpelCompiler.compile(expression)).isFalse();
assertThat(expression.getValue(context)).isEqualTo(true);
assertThat(expression.getValue(context)).asInstanceOf(BOOLEAN).isTrue();
assertThat(SpelCompiler.compile(expression)).isTrue();
SpelCompilationCoverageTests.assertIsCompiled(expression);
assertThat(expression.getValue(context)).isEqualTo(true);
assertThat(expression.getValue(context)).asInstanceOf(BOOLEAN).isTrue();
}