Migrate JUnit 4 assertions to AssertJ
Migrate all existing JUnit 4 `assert...` based assertions to AssertJ and add a checkstyle rule to ensure they don't return. See gh-23022
This commit is contained in:
@@ -27,9 +27,6 @@ import org.springframework.util.ObjectUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Common superclass for expression tests.
|
||||
@@ -71,19 +68,18 @@ public abstract class AbstractExpressionTests {
|
||||
if (expectedValue == null) {
|
||||
return; // no point doing other checks
|
||||
}
|
||||
assertNull("Expression returned null value, but expected '" + expectedValue + "'", expectedValue);
|
||||
assertThat(expectedValue).as("Expression returned null value, but expected '" + expectedValue + "'").isNull();
|
||||
}
|
||||
|
||||
Class<?> resultType = value.getClass();
|
||||
assertEquals("Type of the actual result was not as expected. Expected '" + expectedResultType +
|
||||
"' but result was of type '" + resultType + "'", expectedResultType, resultType);
|
||||
assertThat(resultType).as("Type of the actual result was not as expected. Expected '" + expectedResultType +
|
||||
"' but result was of type '" + resultType + "'").isEqualTo(expectedResultType);
|
||||
|
||||
if (expectedValue instanceof String) {
|
||||
assertEquals("Did not get expected value for expression '" + expression + "'.", expectedValue,
|
||||
AbstractExpressionTests.stringValueOf(value));
|
||||
assertThat(AbstractExpressionTests.stringValueOf(value)).as("Did not get expected value for expression '" + expression + "'.").isEqualTo(expectedValue);
|
||||
}
|
||||
else {
|
||||
assertEquals("Did not get expected value for expression '" + expression + "'.", expectedValue, value);
|
||||
assertThat(value).as("Did not get expected value for expression '" + expression + "'.").isEqualTo(expectedValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,13 +95,13 @@ public abstract class AbstractExpressionTests {
|
||||
if (expectedValue == null) {
|
||||
return; // no point doing other checks
|
||||
}
|
||||
assertNull("Expression returned null value, but expected '" + expectedValue + "'", expectedValue);
|
||||
assertThat(expectedValue).as("Expression returned null value, but expected '" + expectedValue + "'").isNull();
|
||||
}
|
||||
|
||||
Class<?> resultType = value.getClass();
|
||||
assertEquals("Type of the actual result was not as expected. Expected '" + expectedResultType +
|
||||
"' but result was of type '" + resultType + "'", expectedResultType, resultType);
|
||||
assertEquals("Did not get expected value for expression '" + expression + "'.", expectedValue, value);
|
||||
assertThat(resultType).as("Type of the actual result was not as expected. Expected '" + expectedResultType +
|
||||
"' but result was of type '" + resultType + "'").isEqualTo(expectedResultType);
|
||||
assertThat(value).as("Did not get expected value for expression '" + expression + "'.").isEqualTo(expectedValue);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,18 +125,17 @@ public abstract class AbstractExpressionTests {
|
||||
if (expectedValue == null) {
|
||||
return; // no point doing other checks
|
||||
}
|
||||
assertNull("Expression returned null value, but expected '" + expectedValue + "'", expectedValue);
|
||||
assertThat(expectedValue).as("Expression returned null value, but expected '" + expectedValue + "'").isNull();
|
||||
}
|
||||
Class<? extends Object> resultType = value.getClass();
|
||||
if (expectedValue instanceof String) {
|
||||
assertEquals("Did not get expected value for expression '" + expression + "'.", expectedValue,
|
||||
AbstractExpressionTests.stringValueOf(value));
|
||||
assertThat(AbstractExpressionTests.stringValueOf(value)).as("Did not get expected value for expression '" + expression + "'.").isEqualTo(expectedValue);
|
||||
}
|
||||
else {
|
||||
assertEquals("Did not get expected value for expression '" + expression + "'.", expectedValue, value);
|
||||
assertThat(value).as("Did not get expected value for expression '" + expression + "'.").isEqualTo(expectedValue);
|
||||
}
|
||||
assertTrue("Type of the result was not as expected. Expected '" + expectedClassOfResult +
|
||||
"' but result was of type '" + resultType + "'", expectedClassOfResult.equals(resultType));
|
||||
assertThat(expectedClassOfResult.equals(resultType)).as("Type of the result was not as expected. Expected '" + expectedClassOfResult +
|
||||
"' but result was of type '" + resultType + "'").isTrue();
|
||||
|
||||
assertThat(expr.isWritable(context)).as("isWritable").isEqualTo(shouldBeWritable);
|
||||
}
|
||||
|
||||
@@ -21,9 +21,7 @@ import org.junit.Test;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Test construction of arrays.
|
||||
@@ -121,8 +119,8 @@ public class ArrayConstructorTests extends AbstractExpressionTests {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
Expression e = parser.parseExpression(expression);
|
||||
Object o = e.getValue();
|
||||
assertNotNull(o);
|
||||
assertTrue(o.getClass().isArray());
|
||||
assertThat(o).isNotNull();
|
||||
assertThat(o.getClass().isArray()).isTrue();
|
||||
StringBuilder s = new StringBuilder();
|
||||
s.append('[');
|
||||
if (o instanceof int[]) {
|
||||
@@ -201,7 +199,7 @@ public class ArrayConstructorTests extends AbstractExpressionTests {
|
||||
throw new IllegalStateException("Not supported " + o.getClass());
|
||||
}
|
||||
s.append(']');
|
||||
assertEquals(expectedToString, s.toString());
|
||||
assertThat(s.toString()).isEqualTo(expectedToString);
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.springframework.expression.spel.ast.MethodReference;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Test for caching in {@link MethodReference} (SPR-10657).
|
||||
@@ -60,7 +60,7 @@ public class CachedMethodExecutorTests {
|
||||
|
||||
private void assertMethodExecution(Expression expression, Object var, String expected) {
|
||||
this.context.setVariable("var", var);
|
||||
assertEquals(expected, expression.getValue(this.context));
|
||||
assertThat(expression.getValue(this.context)).isEqualTo(expected);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -34,9 +34,6 @@ import org.springframework.expression.spel.testresources.PlaceOfBirth;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests invocation of constructors.
|
||||
@@ -107,15 +104,15 @@ public class ConstructorInvocationTests extends AbstractExpressionTests {
|
||||
eContext.setRootObject(new Tester());
|
||||
eContext.setVariable("bar", 3);
|
||||
Object o = expr.getValue(eContext);
|
||||
assertEquals(3, o);
|
||||
assertEquals(1, parser.parseExpression("counter").getValue(eContext));
|
||||
assertThat(o).isEqualTo(3);
|
||||
assertThat(parser.parseExpression("counter").getValue(eContext)).isEqualTo(1);
|
||||
|
||||
// Now the expression has cached that throwException(int) is the right thing to
|
||||
// call. Let's change 'bar' to be a PlaceOfBirth which indicates the cached
|
||||
// reference is out of date.
|
||||
eContext.setVariable("bar", new PlaceOfBirth("London"));
|
||||
o = expr.getValue(eContext);
|
||||
assertEquals(0, o);
|
||||
assertThat(o).isEqualTo(0);
|
||||
// That confirms the logic to mark the cached reference stale and retry is working
|
||||
|
||||
// Now let's cause the method to exit via exception and ensure it doesn't cause
|
||||
@@ -124,8 +121,8 @@ public class ConstructorInvocationTests extends AbstractExpressionTests {
|
||||
// First, switch back to throwException(int)
|
||||
eContext.setVariable("bar", 3);
|
||||
o = expr.getValue(eContext);
|
||||
assertEquals(3, o);
|
||||
assertEquals(2, parser.parseExpression("counter").getValue(eContext));
|
||||
assertThat(o).isEqualTo(3);
|
||||
assertThat(parser.parseExpression("counter").getValue(eContext)).isEqualTo(2);
|
||||
|
||||
// 4 will make it throw a checked exception - this will be wrapped by spel on the
|
||||
// way out
|
||||
@@ -138,7 +135,7 @@ public class ConstructorInvocationTests extends AbstractExpressionTests {
|
||||
// using arguments '(java.lang.Integer)'
|
||||
|
||||
// If counter is 4 then the method got called twice!
|
||||
assertEquals(3, parser.parseExpression("counter").getValue(eContext));
|
||||
assertThat(parser.parseExpression("counter").getValue(eContext)).isEqualTo(3);
|
||||
|
||||
// 1 will make it throw a RuntimeException - SpEL will let this through
|
||||
eContext.setVariable("bar", 1);
|
||||
@@ -150,7 +147,7 @@ public class ConstructorInvocationTests extends AbstractExpressionTests {
|
||||
// using arguments '(java.lang.Integer)'
|
||||
|
||||
// If counter is 5 then the method got called twice!
|
||||
assertEquals(4, parser.parseExpression("counter").getValue(eContext));
|
||||
assertThat(parser.parseExpression("counter").getValue(eContext)).isEqualTo(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -159,20 +156,20 @@ public class ConstructorInvocationTests extends AbstractExpressionTests {
|
||||
|
||||
// reflective constructor accessor is the only one by default
|
||||
List<ConstructorResolver> constructorResolvers = ctx.getConstructorResolvers();
|
||||
assertEquals(1, constructorResolvers.size());
|
||||
assertThat(constructorResolvers.size()).isEqualTo(1);
|
||||
|
||||
ConstructorResolver dummy = new DummyConstructorResolver();
|
||||
ctx.addConstructorResolver(dummy);
|
||||
assertEquals(2, ctx.getConstructorResolvers().size());
|
||||
assertThat(ctx.getConstructorResolvers().size()).isEqualTo(2);
|
||||
|
||||
List<ConstructorResolver> copy = new ArrayList<>();
|
||||
copy.addAll(ctx.getConstructorResolvers());
|
||||
assertTrue(ctx.removeConstructorResolver(dummy));
|
||||
assertFalse(ctx.removeConstructorResolver(dummy));
|
||||
assertEquals(1, ctx.getConstructorResolvers().size());
|
||||
assertThat(ctx.removeConstructorResolver(dummy)).isTrue();
|
||||
assertThat(ctx.removeConstructorResolver(dummy)).isFalse();
|
||||
assertThat(ctx.getConstructorResolvers().size()).isEqualTo(1);
|
||||
|
||||
ctx.setConstructorResolvers(copy);
|
||||
assertEquals(2, ctx.getConstructorResolvers().size());
|
||||
assertThat(ctx.getConstructorResolvers().size()).isEqualTo(2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -23,8 +23,7 @@ import org.springframework.expression.EvaluationException;
|
||||
import org.springframework.expression.TypeComparator;
|
||||
import org.springframework.expression.spel.support.StandardTypeComparator;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Unit tests for type comparison
|
||||
@@ -38,29 +37,29 @@ public class DefaultComparatorUnitTests {
|
||||
public void testPrimitives() throws EvaluationException {
|
||||
TypeComparator comparator = new StandardTypeComparator();
|
||||
// primitive int
|
||||
assertTrue(comparator.compare(1, 2) < 0);
|
||||
assertTrue(comparator.compare(1, 1) == 0);
|
||||
assertTrue(comparator.compare(2, 1) > 0);
|
||||
assertThat(comparator.compare(1, 2) < 0).isTrue();
|
||||
assertThat(comparator.compare(1, 1) == 0).isTrue();
|
||||
assertThat(comparator.compare(2, 1) > 0).isTrue();
|
||||
|
||||
assertTrue(comparator.compare(1.0d, 2) < 0);
|
||||
assertTrue(comparator.compare(1.0d, 1) == 0);
|
||||
assertTrue(comparator.compare(2.0d, 1) > 0);
|
||||
assertThat(comparator.compare(1.0d, 2) < 0).isTrue();
|
||||
assertThat(comparator.compare(1.0d, 1) == 0).isTrue();
|
||||
assertThat(comparator.compare(2.0d, 1) > 0).isTrue();
|
||||
|
||||
assertTrue(comparator.compare(1.0f, 2) < 0);
|
||||
assertTrue(comparator.compare(1.0f, 1) == 0);
|
||||
assertTrue(comparator.compare(2.0f, 1) > 0);
|
||||
assertThat(comparator.compare(1.0f, 2) < 0).isTrue();
|
||||
assertThat(comparator.compare(1.0f, 1) == 0).isTrue();
|
||||
assertThat(comparator.compare(2.0f, 1) > 0).isTrue();
|
||||
|
||||
assertTrue(comparator.compare(1L, 2) < 0);
|
||||
assertTrue(comparator.compare(1L, 1) == 0);
|
||||
assertTrue(comparator.compare(2L, 1) > 0);
|
||||
assertThat(comparator.compare(1L, 2) < 0).isTrue();
|
||||
assertThat(comparator.compare(1L, 1) == 0).isTrue();
|
||||
assertThat(comparator.compare(2L, 1) > 0).isTrue();
|
||||
|
||||
assertTrue(comparator.compare(1, 2L) < 0);
|
||||
assertTrue(comparator.compare(1, 1L) == 0);
|
||||
assertTrue(comparator.compare(2, 1L) > 0);
|
||||
assertThat(comparator.compare(1, 2L) < 0).isTrue();
|
||||
assertThat(comparator.compare(1, 1L) == 0).isTrue();
|
||||
assertThat(comparator.compare(2, 1L) > 0).isTrue();
|
||||
|
||||
assertTrue(comparator.compare(1L, 2L) < 0);
|
||||
assertTrue(comparator.compare(1L, 1L) == 0);
|
||||
assertTrue(comparator.compare(2L, 1L) > 0);
|
||||
assertThat(comparator.compare(1L, 2L) < 0).isTrue();
|
||||
assertThat(comparator.compare(1L, 1L) == 0).isTrue();
|
||||
assertThat(comparator.compare(2L, 1L) > 0).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -70,54 +69,54 @@ public class DefaultComparatorUnitTests {
|
||||
BigDecimal bdOne = new BigDecimal("1");
|
||||
BigDecimal bdTwo = new BigDecimal("2");
|
||||
|
||||
assertTrue(comparator.compare(bdOne, bdTwo) < 0);
|
||||
assertTrue(comparator.compare(bdOne, new BigDecimal("1")) == 0);
|
||||
assertTrue(comparator.compare(bdTwo, bdOne) > 0);
|
||||
assertThat(comparator.compare(bdOne, bdTwo) < 0).isTrue();
|
||||
assertThat(comparator.compare(bdOne, new BigDecimal("1")) == 0).isTrue();
|
||||
assertThat(comparator.compare(bdTwo, bdOne) > 0).isTrue();
|
||||
|
||||
assertTrue(comparator.compare(1, bdTwo) < 0);
|
||||
assertTrue(comparator.compare(1, bdOne) == 0);
|
||||
assertTrue(comparator.compare(2, bdOne) > 0);
|
||||
assertThat(comparator.compare(1, bdTwo) < 0).isTrue();
|
||||
assertThat(comparator.compare(1, bdOne) == 0).isTrue();
|
||||
assertThat(comparator.compare(2, bdOne) > 0).isTrue();
|
||||
|
||||
assertTrue(comparator.compare(1.0d, bdTwo) < 0);
|
||||
assertTrue(comparator.compare(1.0d, bdOne) == 0);
|
||||
assertTrue(comparator.compare(2.0d, bdOne) > 0);
|
||||
assertThat(comparator.compare(1.0d, bdTwo) < 0).isTrue();
|
||||
assertThat(comparator.compare(1.0d, bdOne) == 0).isTrue();
|
||||
assertThat(comparator.compare(2.0d, bdOne) > 0).isTrue();
|
||||
|
||||
assertTrue(comparator.compare(1.0f, bdTwo) < 0);
|
||||
assertTrue(comparator.compare(1.0f, bdOne) == 0);
|
||||
assertTrue(comparator.compare(2.0f, bdOne) > 0);
|
||||
assertThat(comparator.compare(1.0f, bdTwo) < 0).isTrue();
|
||||
assertThat(comparator.compare(1.0f, bdOne) == 0).isTrue();
|
||||
assertThat(comparator.compare(2.0f, bdOne) > 0).isTrue();
|
||||
|
||||
assertTrue(comparator.compare(1L, bdTwo) < 0);
|
||||
assertTrue(comparator.compare(1L, bdOne) == 0);
|
||||
assertTrue(comparator.compare(2L, bdOne) > 0);
|
||||
assertThat(comparator.compare(1L, bdTwo) < 0).isTrue();
|
||||
assertThat(comparator.compare(1L, bdOne) == 0).isTrue();
|
||||
assertThat(comparator.compare(2L, bdOne) > 0).isTrue();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNulls() throws EvaluationException {
|
||||
TypeComparator comparator = new StandardTypeComparator();
|
||||
assertTrue(comparator.compare(null,"abc")<0);
|
||||
assertTrue(comparator.compare(null,null)==0);
|
||||
assertTrue(comparator.compare("abc",null)>0);
|
||||
assertThat(comparator.compare(null,"abc")<0).isTrue();
|
||||
assertThat(comparator.compare(null,null)==0).isTrue();
|
||||
assertThat(comparator.compare("abc",null)>0).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjects() throws EvaluationException {
|
||||
TypeComparator comparator = new StandardTypeComparator();
|
||||
assertTrue(comparator.compare("a","a")==0);
|
||||
assertTrue(comparator.compare("a","b")<0);
|
||||
assertTrue(comparator.compare("b","a")>0);
|
||||
assertThat(comparator.compare("a","a")==0).isTrue();
|
||||
assertThat(comparator.compare("a","b")<0).isTrue();
|
||||
assertThat(comparator.compare("b","a")>0).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCanCompare() throws EvaluationException {
|
||||
TypeComparator comparator = new StandardTypeComparator();
|
||||
assertTrue(comparator.canCompare(null,1));
|
||||
assertTrue(comparator.canCompare(1,null));
|
||||
assertThat(comparator.canCompare(null,1)).isTrue();
|
||||
assertThat(comparator.canCompare(1,null)).isTrue();
|
||||
|
||||
assertTrue(comparator.canCompare(2,1));
|
||||
assertTrue(comparator.canCompare("abc","def"));
|
||||
assertTrue(comparator.canCompare("abc",3));
|
||||
assertFalse(comparator.canCompare(String.class,3));
|
||||
assertThat(comparator.canCompare(2,1)).isTrue();
|
||||
assertThat(comparator.canCompare("abc","def")).isTrue();
|
||||
assertThat(comparator.canCompare("abc",3)).isTrue();
|
||||
assertThat(comparator.canCompare(String.class,3)).isFalse();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,11 +45,7 @@ import org.springframework.expression.spel.testresources.TestPerson;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.within;
|
||||
|
||||
/**
|
||||
* Tests the evaluation of real expressions in a real context.
|
||||
@@ -70,17 +66,17 @@ public class EvaluationTests extends AbstractExpressionTests {
|
||||
TestClass testClass = new TestClass();
|
||||
|
||||
Object o = e.getValue(new StandardEvaluationContext(testClass));
|
||||
assertEquals("", o);
|
||||
assertThat(o).isEqualTo("");
|
||||
o = parser.parseExpression("list[3]").getValue(new StandardEvaluationContext(testClass));
|
||||
assertEquals("", o);
|
||||
assertEquals(4, testClass.list.size());
|
||||
assertThat(o).isEqualTo("");
|
||||
assertThat(testClass.list.size()).isEqualTo(4);
|
||||
|
||||
assertThatExceptionOfType(EvaluationException.class).isThrownBy(() ->
|
||||
parser.parseExpression("list2[3]").getValue(new StandardEvaluationContext(testClass)));
|
||||
|
||||
o = parser.parseExpression("foo[3]").getValue(new StandardEvaluationContext(testClass));
|
||||
assertEquals("", o);
|
||||
assertEquals(4, testClass.getFoo().size());
|
||||
assertThat(o).isEqualTo("");
|
||||
assertThat(testClass.getFoo().size()).isEqualTo(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -90,9 +86,9 @@ public class EvaluationTests extends AbstractExpressionTests {
|
||||
ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
|
||||
|
||||
Object o = parser.parseExpression("map['a']").getValue(ctx);
|
||||
assertNull(o);
|
||||
assertThat(o).isNull();
|
||||
o = parser.parseExpression("map").getValue(ctx);
|
||||
assertNotNull(o);
|
||||
assertThat(o).isNotNull();
|
||||
|
||||
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() ->
|
||||
parser.parseExpression("map2['a']").getValue(ctx));
|
||||
@@ -107,9 +103,9 @@ public class EvaluationTests extends AbstractExpressionTests {
|
||||
ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
|
||||
|
||||
Object o = parser.parseExpression("wibble.bar").getValue(ctx);
|
||||
assertEquals("hello", o);
|
||||
assertThat(o).isEqualTo("hello");
|
||||
o = parser.parseExpression("wibble").getValue(ctx);
|
||||
assertNotNull(o);
|
||||
assertThat(o).isNotNull();
|
||||
|
||||
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() ->
|
||||
parser.parseExpression("wibble2.bar").getValue(ctx));
|
||||
@@ -286,15 +282,15 @@ public class EvaluationTests extends AbstractExpressionTests {
|
||||
// repeated evaluation to drive use of cached executor
|
||||
SpelExpression e = (SpelExpression) parser.parseExpression("new String('wibble')");
|
||||
String newString = e.getValue(String.class);
|
||||
assertEquals("wibble", newString);
|
||||
assertThat(newString).isEqualTo("wibble");
|
||||
newString = e.getValue(String.class);
|
||||
assertEquals("wibble", newString);
|
||||
assertThat(newString).isEqualTo("wibble");
|
||||
|
||||
// not writable
|
||||
assertFalse(e.isWritable(new StandardEvaluationContext()));
|
||||
assertThat(e.isWritable(new StandardEvaluationContext())).isFalse();
|
||||
|
||||
// ast
|
||||
assertEquals("new String('wibble')", e.toStringAST());
|
||||
assertThat(e.toStringAST()).isEqualTo("new String('wibble')");
|
||||
}
|
||||
|
||||
// unary expressions
|
||||
@@ -373,7 +369,7 @@ public class EvaluationTests extends AbstractExpressionTests {
|
||||
@Test
|
||||
public void testTernaryOperator04() {
|
||||
Expression e = parser.parseExpression("1>2?3:4");
|
||||
assertFalse(e.isWritable(context));
|
||||
assertThat(e.isWritable(context)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -452,12 +448,12 @@ public class EvaluationTests extends AbstractExpressionTests {
|
||||
@Test
|
||||
public void testTypeReferencesAndQualifiedIdentifierCaching() {
|
||||
SpelExpression e = (SpelExpression) parser.parseExpression("T(java.lang.String)");
|
||||
assertFalse(e.isWritable(new StandardEvaluationContext()));
|
||||
assertEquals("T(java.lang.String)", e.toStringAST());
|
||||
assertEquals(String.class, e.getValue(Class.class));
|
||||
assertThat(e.isWritable(new StandardEvaluationContext())).isFalse();
|
||||
assertThat(e.toStringAST()).isEqualTo("T(java.lang.String)");
|
||||
assertThat(e.getValue(Class.class)).isEqualTo(String.class);
|
||||
// use cached QualifiedIdentifier:
|
||||
assertEquals("T(java.lang.String)", e.toStringAST());
|
||||
assertEquals(String.class, e.getValue(Class.class));
|
||||
assertThat(e.toStringAST()).isEqualTo("T(java.lang.String)");
|
||||
assertThat(e.getValue(Class.class)).isEqualTo(String.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -466,27 +462,27 @@ public class EvaluationTests extends AbstractExpressionTests {
|
||||
EvaluationContext ctx = new StandardEvaluationContext();
|
||||
ctx.setVariable("a", (short) 3);
|
||||
ctx.setVariable("b", (short) 6);
|
||||
assertTrue(e.getValue(ctx, Boolean.class));
|
||||
assertThat(e.getValue(ctx, Boolean.class)).isTrue();
|
||||
ctx.setVariable("b", (byte) 6);
|
||||
assertTrue(e.getValue(ctx, Boolean.class));
|
||||
assertThat(e.getValue(ctx, Boolean.class)).isTrue();
|
||||
ctx.setVariable("a", (byte) 9);
|
||||
ctx.setVariable("b", (byte) 6);
|
||||
assertFalse(e.getValue(ctx, Boolean.class));
|
||||
assertThat(e.getValue(ctx, Boolean.class)).isFalse();
|
||||
ctx.setVariable("a", 10L);
|
||||
ctx.setVariable("b", (short) 30);
|
||||
assertTrue(e.getValue(ctx, Boolean.class));
|
||||
assertThat(e.getValue(ctx, Boolean.class)).isTrue();
|
||||
ctx.setVariable("a", (byte) 3);
|
||||
ctx.setVariable("b", (short) 30);
|
||||
assertTrue(e.getValue(ctx, Boolean.class));
|
||||
assertThat(e.getValue(ctx, Boolean.class)).isTrue();
|
||||
ctx.setVariable("a", (byte) 3);
|
||||
ctx.setVariable("b", 30L);
|
||||
assertTrue(e.getValue(ctx, Boolean.class));
|
||||
assertThat(e.getValue(ctx, Boolean.class)).isTrue();
|
||||
ctx.setVariable("a", (byte) 3);
|
||||
ctx.setVariable("b", 30f);
|
||||
assertTrue(e.getValue(ctx, Boolean.class));
|
||||
assertThat(e.getValue(ctx, Boolean.class)).isTrue();
|
||||
ctx.setVariable("a", new BigInteger("10"));
|
||||
ctx.setVariable("b", new BigInteger("20"));
|
||||
assertTrue(e.getValue(ctx, Boolean.class));
|
||||
assertThat(e.getValue(ctx, Boolean.class)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -523,15 +519,15 @@ public class EvaluationTests extends AbstractExpressionTests {
|
||||
@Test
|
||||
public void testAdvancedNumerics() {
|
||||
int twentyFour = parser.parseExpression("2.0 * 3e0 * 4").getValue(Integer.class);
|
||||
assertEquals(24, twentyFour);
|
||||
assertThat(twentyFour).isEqualTo(24);
|
||||
double one = parser.parseExpression("8.0 / 5e0 % 2").getValue(Double.class);
|
||||
assertEquals(1.6d, one, 0d);
|
||||
assertThat((float) one).isCloseTo((float) 1.6d, within((float) 0d));
|
||||
int o = parser.parseExpression("8.0 / 5e0 % 2").getValue(Integer.class);
|
||||
assertEquals(1, o);
|
||||
assertThat(o).isEqualTo(1);
|
||||
int sixteen = parser.parseExpression("-2 ^ 4").getValue(Integer.class);
|
||||
assertEquals(16, sixteen);
|
||||
assertThat(sixteen).isEqualTo(16);
|
||||
int minusFortyFive = parser.parseExpression("1+2-3*8^2/2/2").getValue(Integer.class);
|
||||
assertEquals(-45, minusFortyFive);
|
||||
assertThat(minusFortyFive).isEqualTo(-45);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -539,7 +535,7 @@ public class EvaluationTests extends AbstractExpressionTests {
|
||||
EvaluationContext context = TestScenarioCreator.getTestEvaluationContext();
|
||||
boolean trueValue = parser.parseExpression("T(java.util.Date) == Birthdate.Class").getValue(
|
||||
context, Boolean.class);
|
||||
assertTrue(trueValue);
|
||||
assertThat(trueValue).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -548,13 +544,13 @@ public class EvaluationTests extends AbstractExpressionTests {
|
||||
assertThatExceptionOfType(EvaluationException.class).isThrownBy(() ->
|
||||
parser.parseExpression("T(List)!=null").getValue(context, Boolean.class));
|
||||
((StandardTypeLocator) context.getTypeLocator()).registerImport("java.util");
|
||||
assertTrue(parser.parseExpression("T(List)!=null").getValue(context, Boolean.class));
|
||||
assertThat(parser.parseExpression("T(List)!=null").getValue(context, Boolean.class)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolvingString() {
|
||||
Class<?> stringClass = parser.parseExpression("T(String)").getValue(Class.class);
|
||||
assertEquals(String.class, stringClass);
|
||||
assertThat(stringClass).isEqualTo(String.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -569,20 +565,20 @@ public class EvaluationTests extends AbstractExpressionTests {
|
||||
ExpressionParser parser = new SpelExpressionParser(config);
|
||||
Expression e = parser.parseExpression("name");
|
||||
e.setValue(context, "Oleg");
|
||||
assertEquals("Oleg", person.getName());
|
||||
assertThat(person.getName()).isEqualTo("Oleg");
|
||||
|
||||
e = parser.parseExpression("address.street");
|
||||
e.setValue(context, "123 High St");
|
||||
assertEquals("123 High St", person.getAddress().getStreet());
|
||||
assertThat(person.getAddress().getStreet()).isEqualTo("123 High St");
|
||||
|
||||
e = parser.parseExpression("address.crossStreets[0]");
|
||||
e.setValue(context, "Blah");
|
||||
assertEquals("Blah", person.getAddress().getCrossStreets().get(0));
|
||||
assertThat(person.getAddress().getCrossStreets().get(0)).isEqualTo("Blah");
|
||||
|
||||
e = parser.parseExpression("address.crossStreets[3]");
|
||||
e.setValue(context, "Wibble");
|
||||
assertEquals("Blah", person.getAddress().getCrossStreets().get(0));
|
||||
assertEquals("Wibble", person.getAddress().getCrossStreets().get(3));
|
||||
assertThat(person.getAddress().getCrossStreets().get(0)).isEqualTo("Blah");
|
||||
assertThat(person.getAddress().getCrossStreets().get(3)).isEqualTo("Wibble");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -593,13 +589,13 @@ public class EvaluationTests extends AbstractExpressionTests {
|
||||
ExpressionParser parser = new SpelExpressionParser();
|
||||
|
||||
Expression e = parser.parseExpression("null");
|
||||
assertNull(e.getValue());
|
||||
assertThat(e.getValue()).isNull();
|
||||
|
||||
e = parser.parseExpression("NULL");
|
||||
assertNull(e.getValue());
|
||||
assertThat(e.getValue()).isNull();
|
||||
|
||||
e = parser.parseExpression("NuLl");
|
||||
assertNull(e.getValue());
|
||||
assertThat(e.getValue()).isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -637,21 +633,21 @@ public class EvaluationTests extends AbstractExpressionTests {
|
||||
ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
|
||||
Expression e = parser.parseExpression("listOfStrings[++index3]='def'");
|
||||
e.getValue(ctx);
|
||||
assertEquals(2,instance.listOfStrings.size());
|
||||
assertEquals("def",instance.listOfStrings.get(1));
|
||||
assertThat(instance.listOfStrings.size()).isEqualTo(2);
|
||||
assertThat(instance.listOfStrings.get(1)).isEqualTo("def");
|
||||
|
||||
// Check reference beyond end of collection
|
||||
ctx = new StandardEvaluationContext(instance);
|
||||
parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
|
||||
e = parser.parseExpression("listOfStrings[0]");
|
||||
String value = e.getValue(ctx, String.class);
|
||||
assertEquals("abc",value);
|
||||
assertThat(value).isEqualTo("abc");
|
||||
e = parser.parseExpression("listOfStrings[1]");
|
||||
value = e.getValue(ctx, String.class);
|
||||
assertEquals("def",value);
|
||||
assertThat(value).isEqualTo("def");
|
||||
e = parser.parseExpression("listOfStrings[2]");
|
||||
value = e.getValue(ctx, String.class);
|
||||
assertEquals("",value);
|
||||
assertThat(value).isEqualTo("");
|
||||
|
||||
// Now turn off growing and reference off the end
|
||||
StandardEvaluationContext failCtx = new StandardEvaluationContext(instance);
|
||||
@@ -675,7 +671,7 @@ public class EvaluationTests extends AbstractExpressionTests {
|
||||
e.setValue(ctx, "3");
|
||||
}
|
||||
catch (SpelEvaluationException see) {
|
||||
assertEquals(SpelMessage.UNABLE_TO_GROW_COLLECTION, see.getMessageCode());
|
||||
assertThat(see.getMessageCode()).isEqualTo(SpelMessage.UNABLE_TO_GROW_COLLECTION);
|
||||
assertThat(instance.getFoo().size()).isEqualTo(3);
|
||||
}
|
||||
}
|
||||
@@ -687,7 +683,7 @@ public class EvaluationTests extends AbstractExpressionTests {
|
||||
StandardEvaluationContext ctx = new StandardEvaluationContext(i);
|
||||
ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
|
||||
Expression e = parser.parseExpression("#this++");
|
||||
assertEquals(42,i.intValue());
|
||||
assertThat(i.intValue()).isEqualTo(42);
|
||||
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() ->
|
||||
e.getValue(ctx, Integer.class))
|
||||
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.NOT_ASSIGNABLE));
|
||||
@@ -702,48 +698,48 @@ public class EvaluationTests extends AbstractExpressionTests {
|
||||
|
||||
// BigDecimal
|
||||
e = parser.parseExpression("bd++");
|
||||
assertTrue(new BigDecimal("2").equals(helper.bd));
|
||||
assertThat(new BigDecimal("2").equals(helper.bd)).isTrue();
|
||||
BigDecimal return_bd = e.getValue(ctx, BigDecimal.class);
|
||||
assertTrue(new BigDecimal("2").equals(return_bd));
|
||||
assertTrue(new BigDecimal("3").equals(helper.bd));
|
||||
assertThat(new BigDecimal("2").equals(return_bd)).isTrue();
|
||||
assertThat(new BigDecimal("3").equals(helper.bd)).isTrue();
|
||||
|
||||
// double
|
||||
e = parser.parseExpression("ddd++");
|
||||
assertEquals(2.0d, helper.ddd,0d);
|
||||
assertThat((float) helper.ddd).isCloseTo((float) 2.0d, within((float) 0d));
|
||||
double return_ddd = e.getValue(ctx, Double.TYPE);
|
||||
assertEquals(2.0d, return_ddd,0d);
|
||||
assertEquals(3.0d, helper.ddd,0d);
|
||||
assertThat((float) return_ddd).isCloseTo((float) 2.0d, within((float) 0d));
|
||||
assertThat((float) helper.ddd).isCloseTo((float) 3.0d, within((float) 0d));
|
||||
|
||||
// float
|
||||
e = parser.parseExpression("fff++");
|
||||
assertEquals(3.0f, helper.fff,0d);
|
||||
assertThat(helper.fff).isCloseTo(3.0f, within((float) 0d));
|
||||
float return_fff = e.getValue(ctx, Float.TYPE);
|
||||
assertEquals(3.0f, return_fff,0d);
|
||||
assertEquals(4.0f, helper.fff,0d);
|
||||
assertThat(return_fff).isCloseTo(3.0f, within((float) 0d));
|
||||
assertThat(helper.fff).isCloseTo(4.0f, within((float) 0d));
|
||||
|
||||
// long
|
||||
e = parser.parseExpression("lll++");
|
||||
assertEquals(66666L, helper.lll);
|
||||
assertThat(helper.lll).isEqualTo(66666L);
|
||||
long return_lll = e.getValue(ctx, Long.TYPE);
|
||||
assertEquals(66666L, return_lll);
|
||||
assertEquals(66667L, helper.lll);
|
||||
assertThat(return_lll).isEqualTo(66666L);
|
||||
assertThat(helper.lll).isEqualTo(66667L);
|
||||
|
||||
// int
|
||||
e = parser.parseExpression("iii++");
|
||||
assertEquals(42, helper.iii);
|
||||
assertThat(helper.iii).isEqualTo(42);
|
||||
int return_iii = e.getValue(ctx, Integer.TYPE);
|
||||
assertEquals(42, return_iii);
|
||||
assertEquals(43, helper.iii);
|
||||
assertThat(return_iii).isEqualTo(42);
|
||||
assertThat(helper.iii).isEqualTo(43);
|
||||
return_iii = e.getValue(ctx, Integer.TYPE);
|
||||
assertEquals(43, return_iii);
|
||||
assertEquals(44, helper.iii);
|
||||
assertThat(return_iii).isEqualTo(43);
|
||||
assertThat(helper.iii).isEqualTo(44);
|
||||
|
||||
// short
|
||||
e = parser.parseExpression("sss++");
|
||||
assertEquals(15, helper.sss);
|
||||
assertThat(helper.sss).isEqualTo((short) 15);
|
||||
short return_sss = e.getValue(ctx, Short.TYPE);
|
||||
assertEquals(15, return_sss);
|
||||
assertEquals(16, helper.sss);
|
||||
assertThat(return_sss).isEqualTo((short) 15);
|
||||
assertThat(helper.sss).isEqualTo((short) 16);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -756,48 +752,48 @@ public class EvaluationTests extends AbstractExpressionTests {
|
||||
|
||||
// BigDecimal
|
||||
e = parser.parseExpression("++bd");
|
||||
assertTrue(new BigDecimal("2").equals(helper.bd));
|
||||
assertThat(new BigDecimal("2").equals(helper.bd)).isTrue();
|
||||
BigDecimal return_bd = e.getValue(ctx, BigDecimal.class);
|
||||
assertTrue(new BigDecimal("3").equals(return_bd));
|
||||
assertTrue(new BigDecimal("3").equals(helper.bd));
|
||||
assertThat(new BigDecimal("3").equals(return_bd)).isTrue();
|
||||
assertThat(new BigDecimal("3").equals(helper.bd)).isTrue();
|
||||
|
||||
// double
|
||||
e = parser.parseExpression("++ddd");
|
||||
assertEquals(2.0d, helper.ddd ,0d);
|
||||
assertThat((float) helper.ddd).isCloseTo((float) 2.0d, within((float) 0d));
|
||||
double return_ddd = e.getValue(ctx, Double.TYPE);
|
||||
assertEquals(3.0d, return_ddd, 0d);
|
||||
assertEquals(3.0d, helper.ddd, 0d);
|
||||
assertThat((float) return_ddd).isCloseTo((float) 3.0d, within((float) 0d));
|
||||
assertThat((float) helper.ddd).isCloseTo((float) 3.0d, within((float) 0d));
|
||||
|
||||
// float
|
||||
e = parser.parseExpression("++fff");
|
||||
assertEquals(3.0f, helper.fff, 0d);
|
||||
assertThat(helper.fff).isCloseTo(3.0f, within((float) 0d));
|
||||
float return_fff = e.getValue(ctx, Float.TYPE);
|
||||
assertEquals(4.0f, return_fff, 0d);
|
||||
assertEquals(4.0f, helper.fff, 0d);
|
||||
assertThat(return_fff).isCloseTo(4.0f, within((float) 0d));
|
||||
assertThat(helper.fff).isCloseTo(4.0f, within((float) 0d));
|
||||
|
||||
// long
|
||||
e = parser.parseExpression("++lll");
|
||||
assertEquals(66666L, helper.lll);
|
||||
assertThat(helper.lll).isEqualTo(66666L);
|
||||
long return_lll = e.getValue(ctx, Long.TYPE);
|
||||
assertEquals(66667L, return_lll);
|
||||
assertEquals(66667L, helper.lll);
|
||||
assertThat(return_lll).isEqualTo(66667L);
|
||||
assertThat(helper.lll).isEqualTo(66667L);
|
||||
|
||||
// int
|
||||
e = parser.parseExpression("++iii");
|
||||
assertEquals(42, helper.iii);
|
||||
assertThat(helper.iii).isEqualTo(42);
|
||||
int return_iii = e.getValue(ctx, Integer.TYPE);
|
||||
assertEquals(43, return_iii);
|
||||
assertEquals(43, helper.iii);
|
||||
assertThat(return_iii).isEqualTo(43);
|
||||
assertThat(helper.iii).isEqualTo(43);
|
||||
return_iii = e.getValue(ctx, Integer.TYPE);
|
||||
assertEquals(44, return_iii);
|
||||
assertEquals(44, helper.iii);
|
||||
assertThat(return_iii).isEqualTo(44);
|
||||
assertThat(helper.iii).isEqualTo(44);
|
||||
|
||||
// short
|
||||
e = parser.parseExpression("++sss");
|
||||
assertEquals(15, helper.sss);
|
||||
assertThat(helper.sss).isEqualTo((short) 15);
|
||||
int return_sss = (Integer) e.getValue(ctx);
|
||||
assertEquals(16, return_sss);
|
||||
assertEquals(16, helper.sss);
|
||||
assertThat(return_sss).isEqualTo((short) 16);
|
||||
assertThat(helper.sss).isEqualTo((short) 16);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -838,7 +834,7 @@ public class EvaluationTests extends AbstractExpressionTests {
|
||||
StandardEvaluationContext ctx = new StandardEvaluationContext(i);
|
||||
ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
|
||||
Expression e = parser.parseExpression("#this--");
|
||||
assertEquals(42, i.intValue());
|
||||
assertThat(i.intValue()).isEqualTo(42);
|
||||
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() ->
|
||||
e.getValue(ctx, Integer.class))
|
||||
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.NOT_ASSIGNABLE));
|
||||
@@ -853,48 +849,48 @@ public class EvaluationTests extends AbstractExpressionTests {
|
||||
|
||||
// BigDecimal
|
||||
e = parser.parseExpression("bd--");
|
||||
assertTrue(new BigDecimal("2").equals(helper.bd));
|
||||
assertThat(new BigDecimal("2").equals(helper.bd)).isTrue();
|
||||
BigDecimal return_bd = e.getValue(ctx,BigDecimal.class);
|
||||
assertTrue(new BigDecimal("2").equals(return_bd));
|
||||
assertTrue(new BigDecimal("1").equals(helper.bd));
|
||||
assertThat(new BigDecimal("2").equals(return_bd)).isTrue();
|
||||
assertThat(new BigDecimal("1").equals(helper.bd)).isTrue();
|
||||
|
||||
// double
|
||||
e = parser.parseExpression("ddd--");
|
||||
assertEquals(2.0d, helper.ddd,0d);
|
||||
assertThat((float) helper.ddd).isCloseTo((float) 2.0d, within((float) 0d));
|
||||
double return_ddd = e.getValue(ctx, Double.TYPE);
|
||||
assertEquals(2.0d, return_ddd,0d);
|
||||
assertEquals(1.0d, helper.ddd,0d);
|
||||
assertThat((float) return_ddd).isCloseTo((float) 2.0d, within((float) 0d));
|
||||
assertThat((float) helper.ddd).isCloseTo((float) 1.0d, within((float) 0d));
|
||||
|
||||
// float
|
||||
e = parser.parseExpression("fff--");
|
||||
assertEquals(3.0f, helper.fff,0d);
|
||||
assertThat(helper.fff).isCloseTo(3.0f, within((float) 0d));
|
||||
float return_fff = e.getValue(ctx, Float.TYPE);
|
||||
assertEquals(3.0f, return_fff,0d);
|
||||
assertEquals(2.0f, helper.fff,0d);
|
||||
assertThat(return_fff).isCloseTo(3.0f, within((float) 0d));
|
||||
assertThat(helper.fff).isCloseTo(2.0f, within((float) 0d));
|
||||
|
||||
// long
|
||||
e = parser.parseExpression("lll--");
|
||||
assertEquals(66666L, helper.lll);
|
||||
assertThat(helper.lll).isEqualTo(66666L);
|
||||
long return_lll = e.getValue(ctx, Long.TYPE);
|
||||
assertEquals(66666L, return_lll);
|
||||
assertEquals(66665L, helper.lll);
|
||||
assertThat(return_lll).isEqualTo(66666L);
|
||||
assertThat(helper.lll).isEqualTo(66665L);
|
||||
|
||||
// int
|
||||
e = parser.parseExpression("iii--");
|
||||
assertEquals(42, helper.iii);
|
||||
assertThat(helper.iii).isEqualTo(42);
|
||||
int return_iii = e.getValue(ctx, Integer.TYPE);
|
||||
assertEquals(42, return_iii);
|
||||
assertEquals(41, helper.iii);
|
||||
assertThat(return_iii).isEqualTo(42);
|
||||
assertThat(helper.iii).isEqualTo(41);
|
||||
return_iii = e.getValue(ctx, Integer.TYPE);
|
||||
assertEquals(41, return_iii);
|
||||
assertEquals(40, helper.iii);
|
||||
assertThat(return_iii).isEqualTo(41);
|
||||
assertThat(helper.iii).isEqualTo(40);
|
||||
|
||||
// short
|
||||
e = parser.parseExpression("sss--");
|
||||
assertEquals(15, helper.sss);
|
||||
assertThat(helper.sss).isEqualTo((short) 15);
|
||||
short return_sss = e.getValue(ctx, Short.TYPE);
|
||||
assertEquals(15, return_sss);
|
||||
assertEquals(14, helper.sss);
|
||||
assertThat(return_sss).isEqualTo((short) 15);
|
||||
assertThat(helper.sss).isEqualTo((short) 14);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -906,48 +902,48 @@ public class EvaluationTests extends AbstractExpressionTests {
|
||||
|
||||
// BigDecimal
|
||||
e = parser.parseExpression("--bd");
|
||||
assertTrue(new BigDecimal("2").equals(helper.bd));
|
||||
assertThat(new BigDecimal("2").equals(helper.bd)).isTrue();
|
||||
BigDecimal return_bd = e.getValue(ctx,BigDecimal.class);
|
||||
assertTrue(new BigDecimal("1").equals(return_bd));
|
||||
assertTrue(new BigDecimal("1").equals(helper.bd));
|
||||
assertThat(new BigDecimal("1").equals(return_bd)).isTrue();
|
||||
assertThat(new BigDecimal("1").equals(helper.bd)).isTrue();
|
||||
|
||||
// double
|
||||
e = parser.parseExpression("--ddd");
|
||||
assertEquals(2.0d, helper.ddd,0d);
|
||||
assertThat((float) helper.ddd).isCloseTo((float) 2.0d, within((float) 0d));
|
||||
double return_ddd = e.getValue(ctx, Double.TYPE);
|
||||
assertEquals(1.0d, return_ddd,0d);
|
||||
assertEquals(1.0d, helper.ddd,0d);
|
||||
assertThat((float) return_ddd).isCloseTo((float) 1.0d, within((float) 0d));
|
||||
assertThat((float) helper.ddd).isCloseTo((float) 1.0d, within((float) 0d));
|
||||
|
||||
// float
|
||||
e = parser.parseExpression("--fff");
|
||||
assertEquals(3.0f, helper.fff,0d);
|
||||
assertThat(helper.fff).isCloseTo(3.0f, within((float) 0d));
|
||||
float return_fff = e.getValue(ctx, Float.TYPE);
|
||||
assertEquals(2.0f, return_fff,0d);
|
||||
assertEquals(2.0f, helper.fff,0d);
|
||||
assertThat(return_fff).isCloseTo(2.0f, within((float) 0d));
|
||||
assertThat(helper.fff).isCloseTo(2.0f, within((float) 0d));
|
||||
|
||||
// long
|
||||
e = parser.parseExpression("--lll");
|
||||
assertEquals(66666L, helper.lll);
|
||||
assertThat(helper.lll).isEqualTo(66666L);
|
||||
long return_lll = e.getValue(ctx, Long.TYPE);
|
||||
assertEquals(66665L, return_lll);
|
||||
assertEquals(66665L, helper.lll);
|
||||
assertThat(return_lll).isEqualTo(66665L);
|
||||
assertThat(helper.lll).isEqualTo(66665L);
|
||||
|
||||
// int
|
||||
e = parser.parseExpression("--iii");
|
||||
assertEquals(42, helper.iii);
|
||||
assertThat(helper.iii).isEqualTo(42);
|
||||
int return_iii = e.getValue(ctx, Integer.TYPE);
|
||||
assertEquals(41, return_iii);
|
||||
assertEquals(41, helper.iii);
|
||||
assertThat(return_iii).isEqualTo(41);
|
||||
assertThat(helper.iii).isEqualTo(41);
|
||||
return_iii = e.getValue(ctx, Integer.TYPE);
|
||||
assertEquals(40, return_iii);
|
||||
assertEquals(40, helper.iii);
|
||||
assertThat(return_iii).isEqualTo(40);
|
||||
assertThat(helper.iii).isEqualTo(40);
|
||||
|
||||
// short
|
||||
e = parser.parseExpression("--sss");
|
||||
assertEquals(15, helper.sss);
|
||||
assertThat(helper.sss).isEqualTo((short) 15);
|
||||
int return_sss = (Integer)e.getValue(ctx);
|
||||
assertEquals(14, return_sss);
|
||||
assertEquals(14, helper.sss);
|
||||
assertThat(return_sss).isEqualTo(14);
|
||||
assertThat(helper.sss).isEqualTo((short) 14);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -995,20 +991,20 @@ public class EvaluationTests extends AbstractExpressionTests {
|
||||
// intArray[2] is 3
|
||||
e = parser.parseExpression("intArray[#root.index1++]++");
|
||||
e.getValue(ctx, Integer.class);
|
||||
assertEquals(3, helper.index1);
|
||||
assertEquals(4, helper.intArray[2]);
|
||||
assertThat(helper.index1).isEqualTo(3);
|
||||
assertThat(helper.intArray[2]).isEqualTo(4);
|
||||
|
||||
// index1 is 3 intArray[3] is 4
|
||||
e = parser.parseExpression("intArray[#root.index1++]--");
|
||||
assertEquals(4, e.getValue(ctx, Integer.class).intValue());
|
||||
assertEquals(4, helper.index1);
|
||||
assertEquals(3, helper.intArray[3]);
|
||||
assertThat(e.getValue(ctx, Integer.class).intValue()).isEqualTo(4);
|
||||
assertThat(helper.index1).isEqualTo(4);
|
||||
assertThat(helper.intArray[3]).isEqualTo(3);
|
||||
|
||||
// index1 is 4, intArray[3] is 3
|
||||
e = parser.parseExpression("intArray[--#root.index1]++");
|
||||
assertEquals(3, e.getValue(ctx, Integer.class).intValue());
|
||||
assertEquals(3, helper.index1);
|
||||
assertEquals(4, helper.intArray[3]);
|
||||
assertThat(e.getValue(ctx, Integer.class).intValue()).isEqualTo(3);
|
||||
assertThat(helper.index1).isEqualTo(3);
|
||||
assertThat(helper.intArray[3]).isEqualTo(4);
|
||||
}
|
||||
|
||||
|
||||
@@ -1167,49 +1163,49 @@ public class EvaluationTests extends AbstractExpressionTests {
|
||||
// Assign
|
||||
// iii=42
|
||||
e = parser.parseExpression("iii=iii++");
|
||||
assertEquals(42, helper.iii);
|
||||
assertThat(helper.iii).isEqualTo(42);
|
||||
int return_iii = e.getValue(ctx, Integer.TYPE);
|
||||
assertEquals(42, helper.iii);
|
||||
assertEquals(42, return_iii);
|
||||
assertThat(helper.iii).isEqualTo(42);
|
||||
assertThat(return_iii).isEqualTo(42);
|
||||
|
||||
// Identifier
|
||||
e = parser.parseExpression("iii++");
|
||||
assertEquals(42, helper.iii);
|
||||
assertThat(helper.iii).isEqualTo(42);
|
||||
return_iii = e.getValue(ctx, Integer.TYPE);
|
||||
assertEquals(42, return_iii);
|
||||
assertEquals(43, helper.iii);
|
||||
assertThat(return_iii).isEqualTo(42);
|
||||
assertThat(helper.iii).isEqualTo(43);
|
||||
|
||||
e = parser.parseExpression("--iii");
|
||||
assertEquals(43, helper.iii);
|
||||
assertThat(helper.iii).isEqualTo(43);
|
||||
return_iii = e.getValue(ctx, Integer.TYPE);
|
||||
assertEquals(42, return_iii);
|
||||
assertEquals(42, helper.iii);
|
||||
assertThat(return_iii).isEqualTo(42);
|
||||
assertThat(helper.iii).isEqualTo(42);
|
||||
|
||||
e = parser.parseExpression("iii=99");
|
||||
assertEquals(42, helper.iii);
|
||||
assertThat(helper.iii).isEqualTo(42);
|
||||
return_iii = e.getValue(ctx, Integer.TYPE);
|
||||
assertEquals(99, return_iii);
|
||||
assertEquals(99, helper.iii);
|
||||
assertThat(return_iii).isEqualTo(99);
|
||||
assertThat(helper.iii).isEqualTo(99);
|
||||
|
||||
// CompoundExpression
|
||||
// foo.iii == 99
|
||||
e = parser.parseExpression("foo.iii++");
|
||||
assertEquals(99, helper.foo.iii);
|
||||
assertThat(helper.foo.iii).isEqualTo(99);
|
||||
int return_foo_iii = e.getValue(ctx, Integer.TYPE);
|
||||
assertEquals(99, return_foo_iii);
|
||||
assertEquals(100, helper.foo.iii);
|
||||
assertThat(return_foo_iii).isEqualTo(99);
|
||||
assertThat(helper.foo.iii).isEqualTo(100);
|
||||
|
||||
e = parser.parseExpression("--foo.iii");
|
||||
assertEquals(100, helper.foo.iii);
|
||||
assertThat(helper.foo.iii).isEqualTo(100);
|
||||
return_foo_iii = e.getValue(ctx, Integer.TYPE);
|
||||
assertEquals(99, return_foo_iii);
|
||||
assertEquals(99, helper.foo.iii);
|
||||
assertThat(return_foo_iii).isEqualTo(99);
|
||||
assertThat(helper.foo.iii).isEqualTo(99);
|
||||
|
||||
e = parser.parseExpression("foo.iii=999");
|
||||
assertEquals(99, helper.foo.iii);
|
||||
assertThat(helper.foo.iii).isEqualTo(99);
|
||||
return_foo_iii = e.getValue(ctx, Integer.TYPE);
|
||||
assertEquals(999, return_foo_iii);
|
||||
assertEquals(999, helper.foo.iii);
|
||||
assertThat(return_foo_iii).isEqualTo(999);
|
||||
assertThat(helper.foo.iii).isEqualTo(999);
|
||||
|
||||
// ConstructorReference
|
||||
expectFailNotAssignable(parser, ctx, "(new String('abc'))++");
|
||||
@@ -1253,27 +1249,27 @@ public class EvaluationTests extends AbstractExpressionTests {
|
||||
expectFailNotDecrementable(parser, ctx, "--#wibble");
|
||||
e = parser.parseExpression("#wibble=#wibble+#wibble");
|
||||
String s = e.getValue(ctx, String.class);
|
||||
assertEquals("hello worldhello world", s);
|
||||
assertEquals("hello worldhello world",ctx.lookupVariable("wibble"));
|
||||
assertThat(s).isEqualTo("hello worldhello world");
|
||||
assertThat(ctx.lookupVariable("wibble")).isEqualTo("hello worldhello world");
|
||||
|
||||
ctx.setVariable("wobble", 3);
|
||||
e = parser.parseExpression("#wobble++");
|
||||
assertEquals(3, ((Integer) ctx.lookupVariable("wobble")).intValue());
|
||||
assertThat(((Integer) ctx.lookupVariable("wobble")).intValue()).isEqualTo(3);
|
||||
int r = e.getValue(ctx, Integer.TYPE);
|
||||
assertEquals(3, r);
|
||||
assertEquals(4, ((Integer) ctx.lookupVariable("wobble")).intValue());
|
||||
assertThat(r).isEqualTo(3);
|
||||
assertThat(((Integer) ctx.lookupVariable("wobble")).intValue()).isEqualTo(4);
|
||||
|
||||
e = parser.parseExpression("--#wobble");
|
||||
assertEquals(4, ((Integer) ctx.lookupVariable("wobble")).intValue());
|
||||
assertThat(((Integer) ctx.lookupVariable("wobble")).intValue()).isEqualTo(4);
|
||||
r = e.getValue(ctx, Integer.TYPE);
|
||||
assertEquals(3, r);
|
||||
assertEquals(3, ((Integer) ctx.lookupVariable("wobble")).intValue());
|
||||
assertThat(r).isEqualTo(3);
|
||||
assertThat(((Integer) ctx.lookupVariable("wobble")).intValue()).isEqualTo(3);
|
||||
|
||||
e = parser.parseExpression("#wobble=34");
|
||||
assertEquals(3, ((Integer) ctx.lookupVariable("wobble")).intValue());
|
||||
assertThat(((Integer) ctx.lookupVariable("wobble")).intValue()).isEqualTo(3);
|
||||
r = e.getValue(ctx, Integer.TYPE);
|
||||
assertEquals(34, r);
|
||||
assertEquals(34, ((Integer) ctx.lookupVariable("wobble")).intValue());
|
||||
assertThat(r).isEqualTo(34);
|
||||
assertThat(((Integer) ctx.lookupVariable("wobble")).intValue()).isEqualTo(34);
|
||||
|
||||
// Projection
|
||||
expectFailNotIncrementable(parser, ctx, "({1,2,3}.![#isEven(#this)])++"); // projection would be {false,true,false}
|
||||
@@ -1299,22 +1295,22 @@ public class EvaluationTests extends AbstractExpressionTests {
|
||||
// PropertyOrFieldReference
|
||||
helper.iii = 42;
|
||||
e = parser.parseExpression("iii++");
|
||||
assertEquals(42, helper.iii);
|
||||
assertThat(helper.iii).isEqualTo(42);
|
||||
r = e.getValue(ctx, Integer.TYPE);
|
||||
assertEquals(42, r);
|
||||
assertEquals(43, helper.iii);
|
||||
assertThat(r).isEqualTo(42);
|
||||
assertThat(helper.iii).isEqualTo(43);
|
||||
|
||||
e = parser.parseExpression("--iii");
|
||||
assertEquals(43, helper.iii);
|
||||
assertThat(helper.iii).isEqualTo(43);
|
||||
r = e.getValue(ctx, Integer.TYPE);
|
||||
assertEquals(42, r);
|
||||
assertEquals(42, helper.iii);
|
||||
assertThat(r).isEqualTo(42);
|
||||
assertThat(helper.iii).isEqualTo(42);
|
||||
|
||||
e = parser.parseExpression("iii=100");
|
||||
assertEquals(42, helper.iii);
|
||||
assertThat(helper.iii).isEqualTo(42);
|
||||
r = e.getValue(ctx, Integer.TYPE);
|
||||
assertEquals(100, r);
|
||||
assertEquals(100, helper.iii);
|
||||
assertThat(r).isEqualTo(100);
|
||||
assertThat(helper.iii).isEqualTo(100);
|
||||
}
|
||||
|
||||
private void expectFailNotAssignable(ExpressionParser parser, EvaluationContext eContext, String expressionString) {
|
||||
|
||||
@@ -37,7 +37,6 @@ import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
///CLOVER:OFF
|
||||
|
||||
@@ -79,8 +78,8 @@ public class ExpressionLanguageScenarioTests extends AbstractExpressionTests {
|
||||
// They are reusable
|
||||
value = expr.getValue();
|
||||
|
||||
assertEquals("hello world", value);
|
||||
assertEquals(String.class, value.getClass());
|
||||
assertThat(value).isEqualTo("hello world");
|
||||
assertThat(value.getClass()).isEqualTo(String.class);
|
||||
}
|
||||
catch (EvaluationException | ParseException ex) {
|
||||
throw new AssertionError(ex.getMessage(), ex);
|
||||
@@ -103,16 +102,16 @@ public class ExpressionLanguageScenarioTests extends AbstractExpressionTests {
|
||||
|
||||
Expression expr = parser.parseRaw("#favouriteColour");
|
||||
Object value = expr.getValue(ctx);
|
||||
assertEquals("blue", value);
|
||||
assertThat(value).isEqualTo("blue");
|
||||
|
||||
expr = parser.parseRaw("#primes.get(1)");
|
||||
value = expr.getValue(ctx);
|
||||
assertEquals(3, value);
|
||||
assertThat(value).isEqualTo(3);
|
||||
|
||||
// all prime numbers > 10 from the list (using selection ?{...})
|
||||
expr = parser.parseRaw("#primes.?[#this>10]");
|
||||
value = expr.getValue(ctx);
|
||||
assertEquals("[11, 13, 17]", value.toString());
|
||||
assertThat(value.toString()).isEqualTo("[11, 13, 17]");
|
||||
}
|
||||
|
||||
|
||||
@@ -141,30 +140,30 @@ public class ExpressionLanguageScenarioTests extends AbstractExpressionTests {
|
||||
// read it, set it, read it again
|
||||
Expression expr = parser.parseRaw("str");
|
||||
Object value = expr.getValue(ctx);
|
||||
assertEquals("wibble", value);
|
||||
assertThat(value).isEqualTo("wibble");
|
||||
expr = parser.parseRaw("str");
|
||||
expr.setValue(ctx, "wobble");
|
||||
expr = parser.parseRaw("str");
|
||||
value = expr.getValue(ctx);
|
||||
assertEquals("wobble", value);
|
||||
assertThat(value).isEqualTo("wobble");
|
||||
// or using assignment within the expression
|
||||
expr = parser.parseRaw("str='wabble'");
|
||||
value = expr.getValue(ctx);
|
||||
expr = parser.parseRaw("str");
|
||||
value = expr.getValue(ctx);
|
||||
assertEquals("wabble", value);
|
||||
assertThat(value).isEqualTo("wabble");
|
||||
|
||||
// private property will be accessed through getter()
|
||||
expr = parser.parseRaw("property");
|
||||
value = expr.getValue(ctx);
|
||||
assertEquals(42, value);
|
||||
assertThat(value).isEqualTo(42);
|
||||
|
||||
// ... and set through setter
|
||||
expr = parser.parseRaw("property=4");
|
||||
value = expr.getValue(ctx);
|
||||
expr = parser.parseRaw("property");
|
||||
value = expr.getValue(ctx);
|
||||
assertEquals(4,value);
|
||||
assertThat(value).isEqualTo(4);
|
||||
}
|
||||
|
||||
public static String repeat(String s) { return s+s; }
|
||||
@@ -183,7 +182,7 @@ public class ExpressionLanguageScenarioTests extends AbstractExpressionTests {
|
||||
|
||||
Expression expr = parser.parseRaw("#repeat('hello')");
|
||||
Object value = expr.getValue(ctx);
|
||||
assertEquals("hellohello", value);
|
||||
assertThat(value).isEqualTo("hellohello");
|
||||
|
||||
}
|
||||
catch (EvaluationException | ParseException ex) {
|
||||
@@ -204,7 +203,7 @@ public class ExpressionLanguageScenarioTests extends AbstractExpressionTests {
|
||||
ctx.addPropertyAccessor(new FruitColourAccessor());
|
||||
Expression expr = parser.parseRaw("orange");
|
||||
Object value = expr.getValue(ctx);
|
||||
assertEquals(Color.orange, value);
|
||||
assertThat(value).isEqualTo(Color.orange);
|
||||
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() ->
|
||||
expr.setValue(ctx, Color.blue))
|
||||
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.PROPERTY_OR_FIELD_NOT_WRITABLE_ON_NULL));
|
||||
@@ -220,7 +219,7 @@ public class ExpressionLanguageScenarioTests extends AbstractExpressionTests {
|
||||
ctx.addPropertyAccessor(new VegetableColourAccessor());
|
||||
Expression expr = parser.parseRaw("pea");
|
||||
Object value = expr.getValue(ctx);
|
||||
assertEquals(Color.green, value);
|
||||
assertThat(value).isEqualTo(Color.green);
|
||||
|
||||
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() ->
|
||||
expr.setValue(ctx, Color.blue))
|
||||
|
||||
@@ -32,9 +32,6 @@ import org.springframework.expression.spel.testresources.Inventor;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
/**
|
||||
* Tests for the expression state object - some features are not yet exploited in the language (eg nested scopes)
|
||||
@@ -48,7 +45,7 @@ public class ExpressionStateTests extends AbstractExpressionTests {
|
||||
public void testConstruction() {
|
||||
EvaluationContext context = TestScenarioCreator.getTestEvaluationContext();
|
||||
ExpressionState state = new ExpressionState(context);
|
||||
assertEquals(context, state.getEvaluationContext());
|
||||
assertThat(state.getEvaluationContext()).isEqualTo(context);
|
||||
}
|
||||
|
||||
// Local variables are in variable scopes which come and go during evaluation. Normal variables are
|
||||
@@ -59,125 +56,128 @@ public class ExpressionStateTests extends AbstractExpressionTests {
|
||||
ExpressionState state = getState();
|
||||
|
||||
Object value = state.lookupLocalVariable("foo");
|
||||
assertNull(value);
|
||||
assertThat(value).isNull();
|
||||
|
||||
state.setLocalVariable("foo",34);
|
||||
value = state.lookupLocalVariable("foo");
|
||||
assertEquals(34, value);
|
||||
assertThat(value).isEqualTo(34);
|
||||
|
||||
state.setLocalVariable("foo", null);
|
||||
value = state.lookupLocalVariable("foo");
|
||||
assertEquals(null, value);
|
||||
assertThat(value).isEqualTo(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVariables() {
|
||||
ExpressionState state = getState();
|
||||
TypedValue typedValue = state.lookupVariable("foo");
|
||||
assertEquals(TypedValue.NULL, typedValue);
|
||||
assertThat(typedValue).isEqualTo(TypedValue.NULL);
|
||||
|
||||
state.setVariable("foo",34);
|
||||
typedValue = state.lookupVariable("foo");
|
||||
assertEquals(34, typedValue.getValue());
|
||||
assertEquals(Integer.class, typedValue.getTypeDescriptor().getType());
|
||||
assertThat(typedValue.getValue()).isEqualTo(34);
|
||||
assertThat(typedValue.getTypeDescriptor().getType()).isEqualTo(Integer.class);
|
||||
|
||||
state.setVariable("foo","abc");
|
||||
typedValue = state.lookupVariable("foo");
|
||||
assertEquals("abc", typedValue.getValue());
|
||||
assertEquals(String.class, typedValue.getTypeDescriptor().getType());
|
||||
assertThat(typedValue.getValue()).isEqualTo("abc");
|
||||
assertThat(typedValue.getTypeDescriptor().getType()).isEqualTo(String.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoVariableInterference() {
|
||||
ExpressionState state = getState();
|
||||
TypedValue typedValue = state.lookupVariable("foo");
|
||||
assertEquals(TypedValue.NULL, typedValue);
|
||||
assertThat(typedValue).isEqualTo(TypedValue.NULL);
|
||||
|
||||
state.setLocalVariable("foo",34);
|
||||
typedValue = state.lookupVariable("foo");
|
||||
assertEquals(TypedValue.NULL, typedValue);
|
||||
assertThat(typedValue).isEqualTo(TypedValue.NULL);
|
||||
|
||||
state.setVariable("goo", "hello");
|
||||
assertNull(state.lookupLocalVariable("goo"));
|
||||
assertThat(state.lookupLocalVariable("goo")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocalVariableNestedScopes() {
|
||||
ExpressionState state = getState();
|
||||
assertEquals(null, state.lookupLocalVariable("foo"));
|
||||
assertThat(state.lookupLocalVariable("foo")).isEqualTo(null);
|
||||
|
||||
state.setLocalVariable("foo",12);
|
||||
assertEquals(12, state.lookupLocalVariable("foo"));
|
||||
assertThat(state.lookupLocalVariable("foo")).isEqualTo(12);
|
||||
|
||||
state.enterScope(null);
|
||||
assertEquals(12, state.lookupLocalVariable("foo")); // found in upper scope
|
||||
// found in upper scope
|
||||
assertThat(state.lookupLocalVariable("foo")).isEqualTo(12);
|
||||
|
||||
state.setLocalVariable("foo","abc");
|
||||
assertEquals("abc", state.lookupLocalVariable("foo")); // found in nested scope
|
||||
// found in nested scope
|
||||
assertThat(state.lookupLocalVariable("foo")).isEqualTo("abc");
|
||||
|
||||
state.exitScope();
|
||||
assertEquals(12, state.lookupLocalVariable("foo")); // found in nested scope
|
||||
// found in nested scope
|
||||
assertThat(state.lookupLocalVariable("foo")).isEqualTo(12);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRootContextObject() {
|
||||
ExpressionState state = getState();
|
||||
assertEquals(Inventor.class, state.getRootContextObject().getValue().getClass());
|
||||
assertThat(state.getRootContextObject().getValue().getClass()).isEqualTo(Inventor.class);
|
||||
|
||||
// although the root object is being set on the evaluation context, the value in the 'state' remains what it was when constructed
|
||||
((StandardEvaluationContext) state.getEvaluationContext()).setRootObject(null);
|
||||
assertEquals(Inventor.class, state.getRootContextObject().getValue().getClass());
|
||||
assertThat(state.getRootContextObject().getValue().getClass()).isEqualTo(Inventor.class);
|
||||
// assertEquals(null, state.getRootContextObject().getValue());
|
||||
|
||||
state = new ExpressionState(new StandardEvaluationContext());
|
||||
assertEquals(TypedValue.NULL, state.getRootContextObject());
|
||||
assertThat(state.getRootContextObject()).isEqualTo(TypedValue.NULL);
|
||||
|
||||
|
||||
((StandardEvaluationContext) state.getEvaluationContext()).setRootObject(null);
|
||||
assertEquals(null, state.getRootContextObject().getValue());
|
||||
assertThat(state.getRootContextObject().getValue()).isEqualTo(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testActiveContextObject() {
|
||||
ExpressionState state = getState();
|
||||
assertEquals(state.getRootContextObject().getValue(), state.getActiveContextObject().getValue());
|
||||
assertThat(state.getActiveContextObject().getValue()).isEqualTo(state.getRootContextObject().getValue());
|
||||
|
||||
assertThatIllegalStateException().isThrownBy(
|
||||
state::popActiveContextObject);
|
||||
|
||||
state.pushActiveContextObject(new TypedValue(34));
|
||||
assertEquals(34, state.getActiveContextObject().getValue());
|
||||
assertThat(state.getActiveContextObject().getValue()).isEqualTo(34);
|
||||
|
||||
state.pushActiveContextObject(new TypedValue("hello"));
|
||||
assertEquals("hello", state.getActiveContextObject().getValue());
|
||||
assertThat(state.getActiveContextObject().getValue()).isEqualTo("hello");
|
||||
|
||||
state.popActiveContextObject();
|
||||
assertEquals(34, state.getActiveContextObject().getValue());
|
||||
assertThat(state.getActiveContextObject().getValue()).isEqualTo(34);
|
||||
|
||||
state.popActiveContextObject();
|
||||
assertEquals(state.getRootContextObject().getValue(), state.getActiveContextObject().getValue());
|
||||
assertThat(state.getActiveContextObject().getValue()).isEqualTo(state.getRootContextObject().getValue());
|
||||
|
||||
state = new ExpressionState(new StandardEvaluationContext());
|
||||
assertEquals(TypedValue.NULL, state.getActiveContextObject());
|
||||
assertThat(state.getActiveContextObject()).isEqualTo(TypedValue.NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPopulatedNestedScopes() {
|
||||
ExpressionState state = getState();
|
||||
assertNull(state.lookupLocalVariable("foo"));
|
||||
assertThat(state.lookupLocalVariable("foo")).isNull();
|
||||
|
||||
state.enterScope("foo",34);
|
||||
assertEquals(34, state.lookupLocalVariable("foo"));
|
||||
assertThat(state.lookupLocalVariable("foo")).isEqualTo(34);
|
||||
|
||||
state.enterScope(null);
|
||||
state.setLocalVariable("foo", 12);
|
||||
assertEquals(12, state.lookupLocalVariable("foo"));
|
||||
assertThat(state.lookupLocalVariable("foo")).isEqualTo(12);
|
||||
|
||||
state.exitScope();
|
||||
assertEquals(34, state.lookupLocalVariable("foo"));
|
||||
assertThat(state.lookupLocalVariable("foo")).isEqualTo(34);
|
||||
|
||||
state.exitScope();
|
||||
assertNull(state.lookupLocalVariable("goo"));
|
||||
assertThat(state.lookupLocalVariable("goo")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -187,33 +187,33 @@ public class ExpressionStateTests extends AbstractExpressionTests {
|
||||
// supplied should override root on context
|
||||
ExpressionState state = new ExpressionState(ctx,new TypedValue("i am a string"));
|
||||
TypedValue stateRoot = state.getRootContextObject();
|
||||
assertEquals(String.class, stateRoot.getTypeDescriptor().getType());
|
||||
assertEquals("i am a string", stateRoot.getValue());
|
||||
assertThat(stateRoot.getTypeDescriptor().getType()).isEqualTo(String.class);
|
||||
assertThat(stateRoot.getValue()).isEqualTo("i am a string");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPopulatedNestedScopesMap() {
|
||||
ExpressionState state = getState();
|
||||
assertNull(state.lookupLocalVariable("foo"));
|
||||
assertNull(state.lookupLocalVariable("goo"));
|
||||
assertThat(state.lookupLocalVariable("foo")).isNull();
|
||||
assertThat(state.lookupLocalVariable("goo")).isNull();
|
||||
|
||||
Map<String,Object> m = new HashMap<>();
|
||||
m.put("foo", 34);
|
||||
m.put("goo", "abc");
|
||||
|
||||
state.enterScope(m);
|
||||
assertEquals(34, state.lookupLocalVariable("foo"));
|
||||
assertEquals("abc", state.lookupLocalVariable("goo"));
|
||||
assertThat(state.lookupLocalVariable("foo")).isEqualTo(34);
|
||||
assertThat(state.lookupLocalVariable("goo")).isEqualTo("abc");
|
||||
|
||||
state.enterScope(null);
|
||||
state.setLocalVariable("foo",12);
|
||||
assertEquals(12, state.lookupLocalVariable("foo"));
|
||||
assertEquals("abc", state.lookupLocalVariable("goo"));
|
||||
assertThat(state.lookupLocalVariable("foo")).isEqualTo(12);
|
||||
assertThat(state.lookupLocalVariable("goo")).isEqualTo("abc");
|
||||
|
||||
state.exitScope();
|
||||
state.exitScope();
|
||||
assertNull(state.lookupLocalVariable("foo"));
|
||||
assertNull(state.lookupLocalVariable("goo"));
|
||||
assertThat(state.lookupLocalVariable("foo")).isNull();
|
||||
assertThat(state.lookupLocalVariable("goo")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -231,14 +231,14 @@ public class ExpressionStateTests extends AbstractExpressionTests {
|
||||
@Test
|
||||
public void testComparator() {
|
||||
ExpressionState state = getState();
|
||||
assertEquals(state.getEvaluationContext().getTypeComparator(), state.getTypeComparator());
|
||||
assertThat(state.getTypeComparator()).isEqualTo(state.getEvaluationContext().getTypeComparator());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypeLocator() throws EvaluationException {
|
||||
ExpressionState state = getState();
|
||||
assertNotNull(state.getEvaluationContext().getTypeLocator());
|
||||
assertEquals(Integer.class, state.findType("java.lang.Integer"));
|
||||
assertThat(state.getEvaluationContext().getTypeLocator()).isNotNull();
|
||||
assertThat(state.findType("java.lang.Integer")).isEqualTo(Integer.class);
|
||||
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() ->
|
||||
state.findType("someMadeUpName"))
|
||||
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.TYPE_NOT_FOUND));
|
||||
@@ -249,16 +249,16 @@ public class ExpressionStateTests extends AbstractExpressionTests {
|
||||
public void testTypeConversion() throws EvaluationException {
|
||||
ExpressionState state = getState();
|
||||
String s = (String) state.convertValue(34, TypeDescriptor.valueOf(String.class));
|
||||
assertEquals("34", s);
|
||||
assertThat(s).isEqualTo("34");
|
||||
|
||||
s = (String)state.convertValue(new TypedValue(34), TypeDescriptor.valueOf(String.class));
|
||||
assertEquals("34", s);
|
||||
assertThat(s).isEqualTo("34");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyAccessors() {
|
||||
ExpressionState state = getState();
|
||||
assertEquals(state.getEvaluationContext().getPropertyAccessors(), state.getPropertyAccessors());
|
||||
assertThat(state.getPropertyAccessors()).isEqualTo(state.getEvaluationContext().getPropertyAccessors());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,9 +33,7 @@ import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.TypeConverter;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Expression evaluation where the TypeConverter plugged in is the
|
||||
@@ -76,29 +74,30 @@ public class ExpressionWithConversionTests extends AbstractExpressionTests {
|
||||
|
||||
// ArrayList containing List<Integer> to List<String>
|
||||
Class<?> clazz = typeDescriptorForListOfString.getElementTypeDescriptor().getType();
|
||||
assertEquals(String.class,clazz);
|
||||
assertThat(clazz).isEqualTo(String.class);
|
||||
List<?> l = (List<?>) tcs.convertValue(listOfInteger, TypeDescriptor.forObject(listOfInteger), typeDescriptorForListOfString);
|
||||
assertNotNull(l);
|
||||
assertThat(l).isNotNull();
|
||||
|
||||
// ArrayList containing List<String> to List<Integer>
|
||||
clazz = typeDescriptorForListOfInteger.getElementTypeDescriptor().getType();
|
||||
assertEquals(Integer.class,clazz);
|
||||
assertThat(clazz).isEqualTo(Integer.class);
|
||||
|
||||
l = (List<?>) tcs.convertValue(listOfString, TypeDescriptor.forObject(listOfString), typeDescriptorForListOfString);
|
||||
assertNotNull(l);
|
||||
assertThat(l).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetParameterizedList() throws Exception {
|
||||
StandardEvaluationContext context = TestScenarioCreator.getTestEvaluationContext();
|
||||
Expression e = parser.parseExpression("listOfInteger.size()");
|
||||
assertEquals(0,e.getValue(context,Integer.class).intValue());
|
||||
assertThat(e.getValue(context, Integer.class).intValue()).isEqualTo(0);
|
||||
context.setTypeConverter(new TypeConvertorUsingConversionService());
|
||||
// Assign a List<String> to the List<Integer> field - the component elements should be converted
|
||||
parser.parseExpression("listOfInteger").setValue(context,listOfString);
|
||||
assertEquals(3,e.getValue(context,Integer.class).intValue()); // size now 3
|
||||
// size now 3
|
||||
assertThat(e.getValue(context, Integer.class).intValue()).isEqualTo(3);
|
||||
Class<?> clazz = parser.parseExpression("listOfInteger[1].getClass()").getValue(context, Class.class); // element type correctly Integer
|
||||
assertEquals(Integer.class,clazz);
|
||||
assertThat(clazz).isEqualTo(Integer.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -120,17 +119,17 @@ public class ExpressionWithConversionTests extends AbstractExpressionTests {
|
||||
TypeDescriptor collectionType = new TypeDescriptor(new MethodParameter(TestTarget.class.getDeclaredMethod(
|
||||
"sum", Collection.class), 0));
|
||||
// The type conversion is possible
|
||||
assertTrue(evaluationContext.getTypeConverter()
|
||||
.canConvert(TypeDescriptor.valueOf(String.class), collectionType));
|
||||
assertThat(evaluationContext.getTypeConverter()
|
||||
.canConvert(TypeDescriptor.valueOf(String.class), collectionType)).isTrue();
|
||||
// ... and it can be done successfully
|
||||
assertEquals("[1, 2, 3, 4]", evaluationContext.getTypeConverter().convertValue("1,2,3,4", TypeDescriptor.valueOf(String.class), collectionType).toString());
|
||||
assertThat(evaluationContext.getTypeConverter().convertValue("1,2,3,4", TypeDescriptor.valueOf(String.class), collectionType).toString()).isEqualTo("[1, 2, 3, 4]");
|
||||
|
||||
evaluationContext.setVariable("target", new TestTarget());
|
||||
|
||||
// OK up to here, so the evaluation should be fine...
|
||||
// ... but this fails
|
||||
int result = (Integer) parser.parseExpression("#target.sum(#root)").getValue(evaluationContext, "1,2,3,4");
|
||||
assertEquals("Wrong result: " + result, 10, result);
|
||||
assertThat(result).as("Wrong result: " + result).isEqualTo(10);
|
||||
|
||||
}
|
||||
|
||||
@@ -145,26 +144,26 @@ public class ExpressionWithConversionTests extends AbstractExpressionTests {
|
||||
Expression expression = parser.parseExpression("foos");
|
||||
expression.setValue(context, foos);
|
||||
Foo baz = root.getFoos().iterator().next();
|
||||
assertEquals("baz", baz.value);
|
||||
assertThat(baz.value).isEqualTo("baz");
|
||||
|
||||
// method call
|
||||
expression = parser.parseExpression("setFoos(#foos)");
|
||||
context.setVariable("foos", foos);
|
||||
expression.getValue(context);
|
||||
baz = root.getFoos().iterator().next();
|
||||
assertEquals("baz", baz.value);
|
||||
assertThat(baz.value).isEqualTo("baz");
|
||||
|
||||
// method call with result from method call
|
||||
expression = parser.parseExpression("setFoos(getFoosAsStrings())");
|
||||
expression.getValue(context);
|
||||
baz = root.getFoos().iterator().next();
|
||||
assertEquals("baz", baz.value);
|
||||
assertThat(baz.value).isEqualTo("baz");
|
||||
|
||||
// method call with result from method call
|
||||
expression = parser.parseExpression("setFoos(getFoosAsObjects())");
|
||||
expression.getValue(context);
|
||||
baz = root.getFoos().iterator().next();
|
||||
assertEquals("baz", baz.value);
|
||||
assertThat(baz.value).isEqualTo("baz");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.expression.spel.standard.SpelExpression;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* These are tests for language features that are not yet considered 'live'. Either missing implementation or
|
||||
@@ -79,7 +79,7 @@ public class InProgressTests extends AbstractExpressionTests {
|
||||
@Test
|
||||
public void testProjection06() throws Exception {
|
||||
SpelExpression expr = (SpelExpression) parser.parseExpression("'abc'.![true]");
|
||||
assertEquals("'abc'.![true]", expr.toStringAST());
|
||||
assertThat(expr.toStringAST()).isEqualTo("'abc'.![true]");
|
||||
}
|
||||
|
||||
// SELECTION
|
||||
@@ -142,11 +142,11 @@ public class InProgressTests extends AbstractExpressionTests {
|
||||
@Test
|
||||
public void testSelectionAST() throws Exception {
|
||||
SpelExpression expr = (SpelExpression) parser.parseExpression("'abc'.^[true]");
|
||||
assertEquals("'abc'.^[true]", expr.toStringAST());
|
||||
assertThat(expr.toStringAST()).isEqualTo("'abc'.^[true]");
|
||||
expr = (SpelExpression) parser.parseExpression("'abc'.?[true]");
|
||||
assertEquals("'abc'.?[true]", expr.toStringAST());
|
||||
assertThat(expr.toStringAST()).isEqualTo("'abc'.?[true]");
|
||||
expr = (SpelExpression) parser.parseExpression("'abc'.$[true]");
|
||||
assertEquals("'abc'.$[true]", expr.toStringAST());
|
||||
assertThat(expr.toStringAST()).isEqualTo("'abc'.$[true]");
|
||||
}
|
||||
|
||||
// Constructor invocation
|
||||
|
||||
@@ -37,8 +37,7 @@ import org.springframework.expression.TypedValue;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class IndexingTests {
|
||||
@@ -50,11 +49,11 @@ public class IndexingTests {
|
||||
this.property = property;
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
Expression expression = parser.parseExpression("property");
|
||||
assertEquals("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.util.HashMap<?, ?>", expression.getValueTypeDescriptor(this).toString());
|
||||
assertEquals(property, expression.getValue(this));
|
||||
assertEquals(property, expression.getValue(this, Map.class));
|
||||
assertThat(expression.getValueTypeDescriptor(this).toString()).isEqualTo("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.util.HashMap<?, ?>");
|
||||
assertThat(expression.getValue(this)).isEqualTo(property);
|
||||
assertThat(expression.getValue(this, Map.class)).isEqualTo(property);
|
||||
expression = parser.parseExpression("property['foo']");
|
||||
assertEquals("bar", expression.getValue(this));
|
||||
assertThat(expression.getValue(this)).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@FieldAnnotation
|
||||
@@ -71,11 +70,11 @@ public class IndexingTests {
|
||||
context.addPropertyAccessor(new MapAccessor());
|
||||
context.setRootObject(property);
|
||||
Expression expression = parser.parseExpression("property");
|
||||
assertEquals("java.util.HashMap<?, ?>", expression.getValueTypeDescriptor(context).toString());
|
||||
assertEquals(map, expression.getValue(context));
|
||||
assertEquals(map, expression.getValue(context, Map.class));
|
||||
assertThat(expression.getValueTypeDescriptor(context).toString()).isEqualTo("java.util.HashMap<?, ?>");
|
||||
assertThat(expression.getValue(context)).isEqualTo(map);
|
||||
assertThat(expression.getValue(context, Map.class)).isEqualTo(map);
|
||||
expression = parser.parseExpression("property['foo']");
|
||||
assertEquals("bar", expression.getValue(context));
|
||||
assertThat(expression.getValue(context)).isEqualTo("bar");
|
||||
}
|
||||
|
||||
public static class MapAccessor implements PropertyAccessor {
|
||||
@@ -116,12 +115,12 @@ public class IndexingTests {
|
||||
this.property = property;
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
Expression expression = parser.parseExpression("property");
|
||||
assertEquals("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.util.HashMap<?, ?>", expression.getValueTypeDescriptor(this).toString());
|
||||
assertEquals(property, expression.getValue(this));
|
||||
assertThat(expression.getValueTypeDescriptor(this).toString()).isEqualTo("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.util.HashMap<?, ?>");
|
||||
assertThat(expression.getValue(this)).isEqualTo(property);
|
||||
expression = parser.parseExpression("property['foo']");
|
||||
assertEquals("bar", expression.getValue(this));
|
||||
assertThat(expression.getValue(this)).isEqualTo("bar");
|
||||
expression.setValue(this, "baz");
|
||||
assertEquals("baz", expression.getValue(this));
|
||||
assertThat(expression.getValue(this)).isEqualTo("baz");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -131,12 +130,12 @@ public class IndexingTests {
|
||||
this.parameterizedMap = property;
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
Expression expression = parser.parseExpression("parameterizedMap");
|
||||
assertEquals("java.util.HashMap<java.lang.Integer, java.lang.Integer>", expression.getValueTypeDescriptor(this).toString());
|
||||
assertEquals(property, expression.getValue(this));
|
||||
assertThat(expression.getValueTypeDescriptor(this).toString()).isEqualTo("java.util.HashMap<java.lang.Integer, java.lang.Integer>");
|
||||
assertThat(expression.getValue(this)).isEqualTo(property);
|
||||
expression = parser.parseExpression("parameterizedMap['9']");
|
||||
assertEquals(3, expression.getValue(this));
|
||||
assertThat(expression.getValue(this)).isEqualTo(3);
|
||||
expression.setValue(this, "37");
|
||||
assertEquals(37, expression.getValue(this));
|
||||
assertThat(expression.getValue(this)).isEqualTo(37);
|
||||
}
|
||||
|
||||
public Map<Integer, Integer> parameterizedMap;
|
||||
@@ -145,12 +144,12 @@ public class IndexingTests {
|
||||
public void setPropertyContainingMapAutoGrow() {
|
||||
SpelExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, false));
|
||||
Expression expression = parser.parseExpression("parameterizedMap");
|
||||
assertEquals("java.util.Map<java.lang.Integer, java.lang.Integer>", expression.getValueTypeDescriptor(this).toString());
|
||||
assertEquals(property, expression.getValue(this));
|
||||
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']");
|
||||
assertEquals(null, expression.getValue(this));
|
||||
assertThat(expression.getValue(this)).isEqualTo(null);
|
||||
expression.setValue(this, "37");
|
||||
assertEquals(37, expression.getValue(this));
|
||||
assertThat(expression.getValue(this)).isEqualTo(37);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -160,10 +159,10 @@ public class IndexingTests {
|
||||
this.property = property;
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
Expression expression = parser.parseExpression("property");
|
||||
assertEquals("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.util.ArrayList<?>", expression.getValueTypeDescriptor(this).toString());
|
||||
assertEquals(property, expression.getValue(this));
|
||||
assertThat(expression.getValueTypeDescriptor(this).toString()).isEqualTo("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.util.ArrayList<?>");
|
||||
assertThat(expression.getValue(this)).isEqualTo(property);
|
||||
expression = parser.parseExpression("property[0]");
|
||||
assertEquals("bar", expression.getValue(this));
|
||||
assertThat(expression.getValue(this)).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -173,12 +172,12 @@ public class IndexingTests {
|
||||
this.property = property;
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
Expression expression = parser.parseExpression("property");
|
||||
assertEquals("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.util.ArrayList<?>", expression.getValueTypeDescriptor(this).toString());
|
||||
assertEquals(property, expression.getValue(this));
|
||||
assertThat(expression.getValueTypeDescriptor(this).toString()).isEqualTo("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.util.ArrayList<?>");
|
||||
assertThat(expression.getValue(this)).isEqualTo(property);
|
||||
expression = parser.parseExpression("property[0]");
|
||||
assertEquals(3, expression.getValue(this));
|
||||
assertThat(expression.getValue(this)).isEqualTo(3);
|
||||
expression.setValue(this, "4");
|
||||
assertEquals("4", expression.getValue(this));
|
||||
assertThat(expression.getValue(this)).isEqualTo("4");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -187,14 +186,14 @@ public class IndexingTests {
|
||||
this.property = property;
|
||||
SpelExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
|
||||
Expression expression = parser.parseExpression("property");
|
||||
assertEquals("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.util.ArrayList<?>", expression.getValueTypeDescriptor(this).toString());
|
||||
assertEquals(property, expression.getValue(this));
|
||||
assertThat(expression.getValueTypeDescriptor(this).toString()).isEqualTo("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.util.ArrayList<?>");
|
||||
assertThat(expression.getValue(this)).isEqualTo(property);
|
||||
expression = parser.parseExpression("property[0]");
|
||||
try {
|
||||
expression.setValue(this, "4");
|
||||
}
|
||||
catch (EvaluationException ex) {
|
||||
assertTrue(ex.getMessage().startsWith("EL1053E"));
|
||||
assertThat(ex.getMessage().startsWith("EL1053E")).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,10 +204,10 @@ public class IndexingTests {
|
||||
this.parameterizedList = property;
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
Expression expression = parser.parseExpression("parameterizedList");
|
||||
assertEquals("java.util.ArrayList<java.lang.Integer>", expression.getValueTypeDescriptor(this).toString());
|
||||
assertEquals(property, expression.getValue(this));
|
||||
assertThat(expression.getValueTypeDescriptor(this).toString()).isEqualTo("java.util.ArrayList<java.lang.Integer>");
|
||||
assertThat(expression.getValue(this)).isEqualTo(property);
|
||||
expression = parser.parseExpression("parameterizedList[0]");
|
||||
assertEquals(3, expression.getValue(this));
|
||||
assertThat(expression.getValue(this)).isEqualTo(3);
|
||||
}
|
||||
|
||||
public List<Integer> parameterizedList;
|
||||
@@ -220,10 +219,10 @@ public class IndexingTests {
|
||||
this.parameterizedListOfList = property;
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
Expression expression = parser.parseExpression("parameterizedListOfList[0]");
|
||||
assertEquals("java.util.Arrays$ArrayList<java.lang.Integer>", expression.getValueTypeDescriptor(this).toString());
|
||||
assertEquals(property.get(0), expression.getValue(this));
|
||||
assertThat(expression.getValueTypeDescriptor(this).toString()).isEqualTo("java.util.Arrays$ArrayList<java.lang.Integer>");
|
||||
assertThat(expression.getValue(this)).isEqualTo(property.get(0));
|
||||
expression = parser.parseExpression("parameterizedListOfList[0][0]");
|
||||
assertEquals(3, expression.getValue(this));
|
||||
assertThat(expression.getValue(this)).isEqualTo(3);
|
||||
}
|
||||
|
||||
public List<List<Integer>> parameterizedListOfList;
|
||||
@@ -235,12 +234,12 @@ public class IndexingTests {
|
||||
this.parameterizedList = property;
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
Expression expression = parser.parseExpression("parameterizedList");
|
||||
assertEquals("java.util.ArrayList<java.lang.Integer>", expression.getValueTypeDescriptor(this).toString());
|
||||
assertEquals(property, expression.getValue(this));
|
||||
assertThat(expression.getValueTypeDescriptor(this).toString()).isEqualTo("java.util.ArrayList<java.lang.Integer>");
|
||||
assertThat(expression.getValue(this)).isEqualTo(property);
|
||||
expression = parser.parseExpression("parameterizedList[0]");
|
||||
assertEquals(3, expression.getValue(this));
|
||||
assertThat(expression.getValue(this)).isEqualTo(3);
|
||||
expression.setValue(this, "4");
|
||||
assertEquals(4, expression.getValue(this));
|
||||
assertThat(expression.getValue(this)).isEqualTo(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -248,14 +247,14 @@ public class IndexingTests {
|
||||
SpelParserConfiguration configuration = new SpelParserConfiguration(true, true);
|
||||
SpelExpressionParser parser = new SpelExpressionParser(configuration);
|
||||
Expression expression = parser.parseExpression("property");
|
||||
assertEquals("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.lang.Object", expression.getValueTypeDescriptor(this).toString());
|
||||
assertEquals(property, expression.getValue(this));
|
||||
assertThat(expression.getValueTypeDescriptor(this).toString()).isEqualTo("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.lang.Object");
|
||||
assertThat(expression.getValue(this)).isEqualTo(property);
|
||||
expression = parser.parseExpression("property[0]");
|
||||
try {
|
||||
assertEquals("bar", expression.getValue(this));
|
||||
assertThat(expression.getValue(this)).isEqualTo("bar");
|
||||
}
|
||||
catch (EvaluationException ex) {
|
||||
assertTrue(ex.getMessage().startsWith("EL1027E"));
|
||||
assertThat(ex.getMessage().startsWith("EL1027E")).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,14 +265,14 @@ public class IndexingTests {
|
||||
SpelParserConfiguration configuration = new SpelParserConfiguration(true, true);
|
||||
SpelExpressionParser parser = new SpelExpressionParser(configuration);
|
||||
Expression expression = parser.parseExpression("property");
|
||||
assertEquals("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.util.ArrayList<?>", expression.getValueTypeDescriptor(this).toString());
|
||||
assertEquals(property, expression.getValue(this));
|
||||
assertThat(expression.getValueTypeDescriptor(this).toString()).isEqualTo("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.util.ArrayList<?>");
|
||||
assertThat(expression.getValue(this)).isEqualTo(property);
|
||||
expression = parser.parseExpression("property[0]");
|
||||
try {
|
||||
assertEquals("bar", expression.getValue(this));
|
||||
assertThat(expression.getValue(this)).isEqualTo("bar");
|
||||
}
|
||||
catch (EvaluationException ex) {
|
||||
assertTrue(ex.getMessage().startsWith("EL1053E"));
|
||||
assertThat(ex.getMessage().startsWith("EL1053E")).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,14 +283,14 @@ public class IndexingTests {
|
||||
SpelParserConfiguration configuration = new SpelParserConfiguration(true, true);
|
||||
SpelExpressionParser parser = new SpelExpressionParser(configuration);
|
||||
Expression expression = parser.parseExpression("property2");
|
||||
assertEquals("java.util.ArrayList<?>", expression.getValueTypeDescriptor(this).toString());
|
||||
assertEquals(property2, expression.getValue(this));
|
||||
assertThat(expression.getValueTypeDescriptor(this).toString()).isEqualTo("java.util.ArrayList<?>");
|
||||
assertThat(expression.getValue(this)).isEqualTo(property2);
|
||||
expression = parser.parseExpression("property2[0]");
|
||||
try {
|
||||
assertEquals("bar", expression.getValue(this));
|
||||
assertThat(expression.getValue(this)).isEqualTo("bar");
|
||||
}
|
||||
catch (EvaluationException ex) {
|
||||
assertTrue(ex.getMessage().startsWith("EL1053E"));
|
||||
assertThat(ex.getMessage().startsWith("EL1053E")).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -303,10 +302,10 @@ public class IndexingTests {
|
||||
this.property = property;
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
Expression expression = parser.parseExpression("property");
|
||||
assertEquals("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.lang.String[]", expression.getValueTypeDescriptor(this).toString());
|
||||
assertEquals(property, expression.getValue(this));
|
||||
assertThat(expression.getValueTypeDescriptor(this).toString()).isEqualTo("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.lang.String[]");
|
||||
assertThat(expression.getValue(this)).isEqualTo(property);
|
||||
expression = parser.parseExpression("property[0]");
|
||||
assertEquals("bar", expression.getValue(this));
|
||||
assertThat(expression.getValue(this)).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -314,8 +313,8 @@ public class IndexingTests {
|
||||
listOfScalarNotGeneric = new ArrayList();
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
Expression expression = parser.parseExpression("listOfScalarNotGeneric");
|
||||
assertEquals("java.util.ArrayList<?>", expression.getValueTypeDescriptor(this).toString());
|
||||
assertEquals("", expression.getValue(this, String.class));
|
||||
assertThat(expression.getValueTypeDescriptor(this).toString()).isEqualTo("java.util.ArrayList<?>");
|
||||
assertThat(expression.getValue(this, String.class)).isEqualTo("");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -326,15 +325,15 @@ public class IndexingTests {
|
||||
listNotGeneric.add(6);
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
Expression expression = parser.parseExpression("listNotGeneric");
|
||||
assertEquals("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.util.ArrayList<?>", expression.getValueTypeDescriptor(this).toString());
|
||||
assertEquals("5,6", expression.getValue(this, String.class));
|
||||
assertThat(expression.getValueTypeDescriptor(this).toString()).isEqualTo("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.util.ArrayList<?>");
|
||||
assertThat(expression.getValue(this, String.class)).isEqualTo("5,6");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveCollectionElementTypeNull() {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
Expression expression = parser.parseExpression("listNotGeneric");
|
||||
assertEquals("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.util.List<?>", expression.getValueTypeDescriptor(this).toString());
|
||||
assertThat(expression.getValueTypeDescriptor(this).toString()).isEqualTo("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.util.List<?>");
|
||||
}
|
||||
|
||||
@FieldAnnotation
|
||||
@@ -354,7 +353,7 @@ public class IndexingTests {
|
||||
mapNotGeneric.put("bonusAmount", 7.17);
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
Expression expression = parser.parseExpression("mapNotGeneric");
|
||||
assertEquals("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.util.HashMap<?, ?>", expression.getValueTypeDescriptor(this).toString());
|
||||
assertThat(expression.getValueTypeDescriptor(this).toString()).isEqualTo("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.util.HashMap<?, ?>");
|
||||
}
|
||||
|
||||
@FieldAnnotation
|
||||
@@ -367,7 +366,7 @@ public class IndexingTests {
|
||||
listOfScalarNotGeneric.add("5");
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
Expression expression = parser.parseExpression("listOfScalarNotGeneric[0]");
|
||||
assertEquals(new Integer(5), expression.getValue(this, Integer.class));
|
||||
assertThat(expression.getValue(this, Integer.class)).isEqualTo(new Integer(5));
|
||||
}
|
||||
|
||||
public List listOfScalarNotGeneric;
|
||||
@@ -382,7 +381,7 @@ public class IndexingTests {
|
||||
listOfMapsNotGeneric.add(map);
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
Expression expression = parser.parseExpression("listOfMapsNotGeneric[0]['fruit']");
|
||||
assertEquals("apple", expression.getValue(this, String.class));
|
||||
assertThat(expression.getValue(this, String.class)).isEqualTo("apple");
|
||||
}
|
||||
|
||||
public List listOfMapsNotGeneric;
|
||||
|
||||
@@ -25,9 +25,8 @@ import org.springframework.expression.spel.ast.InlineList;
|
||||
import org.springframework.expression.spel.standard.SpelExpression;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Test usage of inline lists.
|
||||
@@ -147,13 +146,14 @@ public class ListTests extends AbstractExpressionTests {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
SpelExpression expression = (SpelExpression) parser.parseExpression(expressionText);
|
||||
SpelNode node = expression.getAST();
|
||||
assertTrue(node instanceof InlineList);
|
||||
boolean condition = node instanceof InlineList;
|
||||
assertThat(condition).isTrue();
|
||||
InlineList inlineList = (InlineList) node;
|
||||
if (expectedToBeConstant) {
|
||||
assertTrue(inlineList.isConstant());
|
||||
assertThat(inlineList.isConstant()).isTrue();
|
||||
}
|
||||
else {
|
||||
assertFalse(inlineList.isConstant());
|
||||
assertThat(inlineList.isConstant()).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,8 +25,6 @@ import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
/**
|
||||
* @author Andy Clement
|
||||
@@ -45,10 +43,10 @@ public class LiteralExpressionTests {
|
||||
assertThat(lEx.getValue(new Rooty(), String.class)).isInstanceOf(String.class).isEqualTo("somevalue");
|
||||
assertThat(lEx.getValue(ctx, new Rooty())).isInstanceOf(String.class).isEqualTo("somevalue");
|
||||
assertThat(lEx.getValue(ctx, new Rooty(),String.class)).isInstanceOf(String.class).isEqualTo("somevalue");
|
||||
assertEquals("somevalue", lEx.getExpressionString());
|
||||
assertFalse(lEx.isWritable(new StandardEvaluationContext()));
|
||||
assertFalse(lEx.isWritable(new Rooty()));
|
||||
assertFalse(lEx.isWritable(new StandardEvaluationContext(), new Rooty()));
|
||||
assertThat(lEx.getExpressionString()).isEqualTo("somevalue");
|
||||
assertThat(lEx.isWritable(new StandardEvaluationContext())).isFalse();
|
||||
assertThat(lEx.isWritable(new Rooty())).isFalse();
|
||||
assertThat(lEx.isWritable(new StandardEvaluationContext(), new Rooty())).isFalse();
|
||||
}
|
||||
|
||||
static class Rooty {}
|
||||
@@ -69,14 +67,14 @@ public class LiteralExpressionTests {
|
||||
@Test
|
||||
public void testGetValueType() throws Exception {
|
||||
LiteralExpression lEx = new LiteralExpression("somevalue");
|
||||
assertEquals(String.class, lEx.getValueType());
|
||||
assertEquals(String.class, lEx.getValueType(new StandardEvaluationContext()));
|
||||
assertEquals(String.class, lEx.getValueType(new Rooty()));
|
||||
assertEquals(String.class, lEx.getValueType(new StandardEvaluationContext(), new Rooty()));
|
||||
assertEquals(String.class, lEx.getValueTypeDescriptor().getType());
|
||||
assertEquals(String.class, lEx.getValueTypeDescriptor(new StandardEvaluationContext()).getType());
|
||||
assertEquals(String.class, lEx.getValueTypeDescriptor(new Rooty()).getType());
|
||||
assertEquals(String.class, lEx.getValueTypeDescriptor(new StandardEvaluationContext(), new Rooty()).getType());
|
||||
assertThat(lEx.getValueType()).isEqualTo(String.class);
|
||||
assertThat(lEx.getValueType(new StandardEvaluationContext())).isEqualTo(String.class);
|
||||
assertThat(lEx.getValueType(new Rooty())).isEqualTo(String.class);
|
||||
assertThat(lEx.getValueType(new StandardEvaluationContext(), new Rooty())).isEqualTo(String.class);
|
||||
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);
|
||||
assertThat(lEx.getValueTypeDescriptor(new StandardEvaluationContext(), new Rooty()).getType()).isEqualTo(String.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.junit.Test;
|
||||
import org.springframework.expression.spel.standard.SpelExpression;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests the evaluation of basic literals: boolean, integer, hex integer, long, real, null, date
|
||||
@@ -165,10 +165,10 @@ public class LiteralTests extends AbstractExpressionTests {
|
||||
@Test
|
||||
public void testNotWritable() throws Exception {
|
||||
SpelExpression expr = (SpelExpression)parser.parseExpression("37");
|
||||
assertFalse(expr.isWritable(new StandardEvaluationContext()));
|
||||
assertThat(expr.isWritable(new StandardEvaluationContext())).isFalse();
|
||||
expr = (SpelExpression)parser.parseExpression("37L");
|
||||
assertFalse(expr.isWritable(new StandardEvaluationContext()));
|
||||
assertThat(expr.isWritable(new StandardEvaluationContext())).isFalse();
|
||||
expr = (SpelExpression)parser.parseExpression("true");
|
||||
assertFalse(expr.isWritable(new StandardEvaluationContext()));
|
||||
assertThat(expr.isWritable(new StandardEvaluationContext())).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ import org.springframework.tests.TestGroup;
|
||||
import org.springframework.util.StopWatch;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Testing variations on map access.
|
||||
@@ -61,7 +60,7 @@ public class MapAccessTests extends AbstractExpressionTests {
|
||||
|
||||
Expression expr = parser.parseExpression("testMap.monday");
|
||||
Object value = expr.getValue(ctx, String.class);
|
||||
assertEquals("montag", value);
|
||||
assertThat(value).isEqualTo("montag");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -72,7 +71,7 @@ public class MapAccessTests extends AbstractExpressionTests {
|
||||
|
||||
Expression expr = parser.parseExpression("testMap[#day]");
|
||||
Object value = expr.getValue(ctx, String.class);
|
||||
assertEquals("samstag", value);
|
||||
assertThat(value).isEqualTo("samstag");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -86,7 +85,7 @@ public class MapAccessTests extends AbstractExpressionTests {
|
||||
|
||||
ExpressionParser parser = new SpelExpressionParser();
|
||||
Expression expr = parser.parseExpression("testBean.properties['key2']");
|
||||
assertEquals("value2", expr.getValue(bean));
|
||||
assertThat(expr.getValue(bean)).isEqualTo("value2");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -96,7 +95,7 @@ public class MapAccessTests extends AbstractExpressionTests {
|
||||
|
||||
ExpressionParser spelExpressionParser = new SpelExpressionParser();
|
||||
Expression expr = spelExpressionParser.parseExpression("#root['key']");
|
||||
assertEquals("value", expr.getValue(map));
|
||||
assertThat(expr.getValue(map)).isEqualTo("value");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -28,10 +28,8 @@ import org.springframework.expression.spel.ast.InlineMap;
|
||||
import org.springframework.expression.spel.standard.SpelExpression;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Test usage of inline maps.
|
||||
@@ -125,13 +123,14 @@ public class MapTests extends AbstractExpressionTests {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
SpelExpression expression = (SpelExpression) parser.parseExpression(expressionText);
|
||||
SpelNode node = expression.getAST();
|
||||
assertTrue(node instanceof InlineMap);
|
||||
boolean condition = node instanceof InlineMap;
|
||||
assertThat(condition).isTrue();
|
||||
InlineMap inlineMap = (InlineMap) node;
|
||||
if (expectedToBeConstant) {
|
||||
assertTrue(inlineMap.isConstant());
|
||||
assertThat(inlineMap.isConstant()).isTrue();
|
||||
}
|
||||
else {
|
||||
assertFalse(inlineMap.isConstant());
|
||||
assertThat(inlineMap.isConstant()).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,35 +153,35 @@ public class MapTests extends AbstractExpressionTests {
|
||||
|
||||
expression = (SpelExpression) parser.parseExpression("foo[T]");
|
||||
o = expression.getValue(new MapHolder());
|
||||
assertEquals("TV", o);
|
||||
assertThat(o).isEqualTo("TV");
|
||||
|
||||
expression = (SpelExpression) parser.parseExpression("foo[t]");
|
||||
o = expression.getValue(new MapHolder());
|
||||
assertEquals("tv", o);
|
||||
assertThat(o).isEqualTo("tv");
|
||||
|
||||
expression = (SpelExpression) parser.parseExpression("foo[NEW]");
|
||||
o = expression.getValue(new MapHolder());
|
||||
assertEquals("VALUE", o);
|
||||
assertThat(o).isEqualTo("VALUE");
|
||||
|
||||
expression = (SpelExpression) parser.parseExpression("foo[new]");
|
||||
o = expression.getValue(new MapHolder());
|
||||
assertEquals("value", o);
|
||||
assertThat(o).isEqualTo("value");
|
||||
|
||||
expression = (SpelExpression) parser.parseExpression("foo['abc.def']");
|
||||
o = expression.getValue(new MapHolder());
|
||||
assertEquals("value", o);
|
||||
assertThat(o).isEqualTo("value");
|
||||
|
||||
expression = (SpelExpression)parser.parseExpression("foo[foo[NEW]]");
|
||||
o = expression.getValue(new MapHolder());
|
||||
assertEquals("37",o);
|
||||
assertThat(o).isEqualTo("37");
|
||||
|
||||
expression = (SpelExpression)parser.parseExpression("foo[foo[new]]");
|
||||
o = expression.getValue(new MapHolder());
|
||||
assertEquals("38",o);
|
||||
assertThat(o).isEqualTo("38");
|
||||
|
||||
expression = (SpelExpression)parser.parseExpression("foo[foo[foo[T]]]");
|
||||
o = expression.getValue(new MapHolder());
|
||||
assertEquals("value",o);
|
||||
assertThat(o).isEqualTo("value");
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
|
||||
@@ -41,10 +41,6 @@ import org.springframework.expression.spel.testresources.PlaceOfBirth;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests invocation of methods.
|
||||
@@ -103,15 +99,15 @@ public class MethodInvocationTests extends AbstractExpressionTests {
|
||||
StandardEvaluationContext eContext = TestScenarioCreator.getTestEvaluationContext();
|
||||
eContext.setVariable("bar", 3);
|
||||
Object o = expr.getValue(eContext);
|
||||
assertEquals(3, o);
|
||||
assertEquals(1, parser.parseExpression("counter").getValue(eContext));
|
||||
assertThat(o).isEqualTo(3);
|
||||
assertThat(parser.parseExpression("counter").getValue(eContext)).isEqualTo(1);
|
||||
|
||||
// Now the expression has cached that throwException(int) is the right thing to call
|
||||
// Let's change 'bar' to be a PlaceOfBirth which indicates the cached reference is
|
||||
// out of date.
|
||||
eContext.setVariable("bar", new PlaceOfBirth("London"));
|
||||
o = expr.getValue(eContext);
|
||||
assertEquals("London", o);
|
||||
assertThat(o).isEqualTo("London");
|
||||
// That confirms the logic to mark the cached reference stale and retry is working
|
||||
|
||||
// Now let's cause the method to exit via exception and ensure it doesn't cause a retry.
|
||||
@@ -119,8 +115,8 @@ public class MethodInvocationTests extends AbstractExpressionTests {
|
||||
// First, switch back to throwException(int)
|
||||
eContext.setVariable("bar", 3);
|
||||
o = expr.getValue(eContext);
|
||||
assertEquals(3, o);
|
||||
assertEquals(2, parser.parseExpression("counter").getValue(eContext));
|
||||
assertThat(o).isEqualTo(3);
|
||||
assertThat(parser.parseExpression("counter").getValue(eContext)).isEqualTo(2);
|
||||
|
||||
|
||||
// Now cause it to throw an exception:
|
||||
@@ -130,14 +126,14 @@ public class MethodInvocationTests extends AbstractExpressionTests {
|
||||
.isNotInstanceOf(SpelEvaluationException.class);
|
||||
|
||||
// If counter is 4 then the method got called twice!
|
||||
assertEquals(3, parser.parseExpression("counter").getValue(eContext));
|
||||
assertThat(parser.parseExpression("counter").getValue(eContext)).isEqualTo(3);
|
||||
|
||||
eContext.setVariable("bar", 4);
|
||||
assertThatExceptionOfType(ExpressionInvocationTargetException.class).isThrownBy(() ->
|
||||
expr.getValue(eContext));
|
||||
|
||||
// If counter is 5 then the method got called twice!
|
||||
assertEquals(4, parser.parseExpression("counter").getValue(eContext));
|
||||
assertThat(parser.parseExpression("counter").getValue(eContext)).isEqualTo(4);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -189,24 +185,24 @@ public class MethodInvocationTests extends AbstractExpressionTests {
|
||||
// Filter will be called but not do anything, so first doit() will be invoked
|
||||
SpelExpression expr = (SpelExpression) parser.parseExpression("doit(1)");
|
||||
String result = expr.getValue(context, String.class);
|
||||
assertEquals("1", result);
|
||||
assertTrue(filter.filterCalled);
|
||||
assertThat(result).isEqualTo("1");
|
||||
assertThat(filter.filterCalled).isTrue();
|
||||
|
||||
// Filter will now remove non @Anno annotated methods
|
||||
filter.removeIfNotAnnotated = true;
|
||||
filter.filterCalled = false;
|
||||
expr = (SpelExpression) parser.parseExpression("doit(1)");
|
||||
result = expr.getValue(context, String.class);
|
||||
assertEquals("double 1.0", result);
|
||||
assertTrue(filter.filterCalled);
|
||||
assertThat(result).isEqualTo("double 1.0");
|
||||
assertThat(filter.filterCalled).isTrue();
|
||||
|
||||
// check not called for other types
|
||||
filter.filterCalled = false;
|
||||
context.setRootObject(new String("abc"));
|
||||
expr = (SpelExpression) parser.parseExpression("charAt(0)");
|
||||
result = expr.getValue(context, String.class);
|
||||
assertEquals("a", result);
|
||||
assertFalse(filter.filterCalled);
|
||||
assertThat(result).isEqualTo("a");
|
||||
assertThat(filter.filterCalled).isFalse();
|
||||
|
||||
// check de-registration works
|
||||
filter.filterCalled = false;
|
||||
@@ -214,8 +210,8 @@ public class MethodInvocationTests extends AbstractExpressionTests {
|
||||
context.setRootObject(new TestObject());
|
||||
expr = (SpelExpression) parser.parseExpression("doit(1)");
|
||||
result = expr.getValue(context, String.class);
|
||||
assertEquals("1", result);
|
||||
assertFalse(filter.filterCalled);
|
||||
assertThat(result).isEqualTo("1");
|
||||
assertThat(filter.filterCalled).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -224,20 +220,20 @@ public class MethodInvocationTests extends AbstractExpressionTests {
|
||||
|
||||
// reflective method accessor is the only one by default
|
||||
List<MethodResolver> methodResolvers = ctx.getMethodResolvers();
|
||||
assertEquals(1, methodResolvers.size());
|
||||
assertThat(methodResolvers.size()).isEqualTo(1);
|
||||
|
||||
MethodResolver dummy = new DummyMethodResolver();
|
||||
ctx.addMethodResolver(dummy);
|
||||
assertEquals(2, ctx.getMethodResolvers().size());
|
||||
assertThat(ctx.getMethodResolvers().size()).isEqualTo(2);
|
||||
|
||||
List<MethodResolver> copy = new ArrayList<>();
|
||||
copy.addAll(ctx.getMethodResolvers());
|
||||
assertTrue(ctx.removeMethodResolver(dummy));
|
||||
assertFalse(ctx.removeMethodResolver(dummy));
|
||||
assertEquals(1, ctx.getMethodResolvers().size());
|
||||
assertThat(ctx.removeMethodResolver(dummy)).isTrue();
|
||||
assertThat(ctx.removeMethodResolver(dummy)).isFalse();
|
||||
assertThat(ctx.getMethodResolvers().size()).isEqualTo(1);
|
||||
|
||||
ctx.setMethodResolvers(copy);
|
||||
assertEquals(2, ctx.getMethodResolvers().size());
|
||||
assertThat(ctx.getMethodResolvers().size()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -273,7 +269,7 @@ public class MethodInvocationTests extends AbstractExpressionTests {
|
||||
public void testMethodOfClass() throws Exception {
|
||||
Expression expression = parser.parseExpression("getName()");
|
||||
Object value = expression.getValue(new StandardEvaluationContext(String.class));
|
||||
assertEquals("java.lang.String", value);
|
||||
assertThat(value).isEqualTo("java.lang.String");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -292,7 +288,7 @@ public class MethodInvocationTests extends AbstractExpressionTests {
|
||||
});
|
||||
Expression expression = parser.parseExpression("@service.handleBytes(#root)");
|
||||
byte[] outBytes = expression.getValue(context, byte[].class);
|
||||
assertSame(bytes, outBytes);
|
||||
assertThat(outBytes).isSameAs(bytes);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.springframework.expression.OperatorOverloader;
|
||||
import org.springframework.expression.spel.standard.SpelExpression;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Test providing operator support
|
||||
@@ -42,13 +42,13 @@ public class OperatorOverloaderTests extends AbstractExpressionTests {
|
||||
eContext.setOperatorOverloader(new StringAndBooleanAddition());
|
||||
|
||||
SpelExpression expr = (SpelExpression)parser.parseExpression("'abc'+true");
|
||||
assertEquals("abctrue",expr.getValue(eContext));
|
||||
assertThat(expr.getValue(eContext)).isEqualTo("abctrue");
|
||||
|
||||
expr = (SpelExpression)parser.parseExpression("'abc'-true");
|
||||
assertEquals("abc",expr.getValue(eContext));
|
||||
assertThat(expr.getValue(eContext)).isEqualTo("abc");
|
||||
|
||||
expr = (SpelExpression)parser.parseExpression("'abc'+null");
|
||||
assertEquals("abcnull",expr.getValue(eContext));
|
||||
assertThat(expr.getValue(eContext)).isEqualTo("abcnull");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.junit.Test;
|
||||
import org.springframework.expression.spel.ast.Operator;
|
||||
import org.springframework.expression.spel.standard.SpelExpression;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests the evaluation of expressions using relational operators.
|
||||
@@ -401,9 +401,9 @@ public class OperatorTests extends AbstractExpressionTests {
|
||||
|
||||
// AST:
|
||||
SpelExpression expr = (SpelExpression)parser.parseExpression("+3");
|
||||
assertEquals("+3",expr.toStringAST());
|
||||
assertThat(expr.toStringAST()).isEqualTo("+3");
|
||||
expr = (SpelExpression)parser.parseExpression("2+3");
|
||||
assertEquals("(2 + 3)",expr.toStringAST());
|
||||
assertThat(expr.toStringAST()).isEqualTo("(2 + 3)");
|
||||
|
||||
// use as a unary operator
|
||||
evaluate("+5d",5d,Double.class);
|
||||
@@ -425,9 +425,9 @@ public class OperatorTests extends AbstractExpressionTests {
|
||||
evaluateAndCheckError("'ab' - 2", SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES);
|
||||
evaluateAndCheckError("2-'ab'", SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES);
|
||||
SpelExpression expr = (SpelExpression)parser.parseExpression("-3");
|
||||
assertEquals("-3", expr.toStringAST());
|
||||
assertThat(expr.toStringAST()).isEqualTo("-3");
|
||||
expr = (SpelExpression)parser.parseExpression("2-3");
|
||||
assertEquals("(2 - 3)", expr.toStringAST());
|
||||
assertThat(expr.toStringAST()).isEqualTo("(2 - 3)");
|
||||
|
||||
evaluate("-5d",-5d,Double.class);
|
||||
evaluate("-5L",-5L,Long.class);
|
||||
@@ -497,40 +497,40 @@ public class OperatorTests extends AbstractExpressionTests {
|
||||
@Test
|
||||
public void testOperatorNames() throws Exception {
|
||||
Operator node = getOperatorNode((SpelExpression)parser.parseExpression("1==3"));
|
||||
assertEquals("==",node.getOperatorName());
|
||||
assertThat(node.getOperatorName()).isEqualTo("==");
|
||||
|
||||
node = getOperatorNode((SpelExpression)parser.parseExpression("1!=3"));
|
||||
assertEquals("!=",node.getOperatorName());
|
||||
assertThat(node.getOperatorName()).isEqualTo("!=");
|
||||
|
||||
node = getOperatorNode((SpelExpression)parser.parseExpression("3/3"));
|
||||
assertEquals("/",node.getOperatorName());
|
||||
assertThat(node.getOperatorName()).isEqualTo("/");
|
||||
|
||||
node = getOperatorNode((SpelExpression)parser.parseExpression("3+3"));
|
||||
assertEquals("+",node.getOperatorName());
|
||||
assertThat(node.getOperatorName()).isEqualTo("+");
|
||||
|
||||
node = getOperatorNode((SpelExpression)parser.parseExpression("3-3"));
|
||||
assertEquals("-",node.getOperatorName());
|
||||
assertThat(node.getOperatorName()).isEqualTo("-");
|
||||
|
||||
node = getOperatorNode((SpelExpression)parser.parseExpression("3<4"));
|
||||
assertEquals("<",node.getOperatorName());
|
||||
assertThat(node.getOperatorName()).isEqualTo("<");
|
||||
|
||||
node = getOperatorNode((SpelExpression)parser.parseExpression("3<=4"));
|
||||
assertEquals("<=",node.getOperatorName());
|
||||
assertThat(node.getOperatorName()).isEqualTo("<=");
|
||||
|
||||
node = getOperatorNode((SpelExpression)parser.parseExpression("3*4"));
|
||||
assertEquals("*",node.getOperatorName());
|
||||
assertThat(node.getOperatorName()).isEqualTo("*");
|
||||
|
||||
node = getOperatorNode((SpelExpression)parser.parseExpression("3%4"));
|
||||
assertEquals("%",node.getOperatorName());
|
||||
assertThat(node.getOperatorName()).isEqualTo("%");
|
||||
|
||||
node = getOperatorNode((SpelExpression)parser.parseExpression("3>=4"));
|
||||
assertEquals(">=",node.getOperatorName());
|
||||
assertThat(node.getOperatorName()).isEqualTo(">=");
|
||||
|
||||
node = getOperatorNode((SpelExpression)parser.parseExpression("3 between 4"));
|
||||
assertEquals("between",node.getOperatorName());
|
||||
assertThat(node.getOperatorName()).isEqualTo("between");
|
||||
|
||||
node = getOperatorNode((SpelExpression)parser.parseExpression("3 ^ 4"));
|
||||
assertEquals("^",node.getOperatorName());
|
||||
assertThat(node.getOperatorName()).isEqualTo("^");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.tests.Assume;
|
||||
import org.springframework.tests.TestGroup;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
///CLOVER:OFF
|
||||
|
||||
|
||||
@@ -38,11 +38,6 @@ import org.springframework.expression.spel.testresources.Person;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests accessing of properties.
|
||||
@@ -87,7 +82,7 @@ public class PropertyAccessTests extends AbstractExpressionTests {
|
||||
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() ->
|
||||
expr.getValue(context))
|
||||
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.PROPERTY_OR_FIELD_NOT_READABLE_ON_NULL));
|
||||
assertFalse(expr.isWritable(context));
|
||||
assertThat(expr.isWritable(context)).isFalse();
|
||||
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() ->
|
||||
expr.setValue(context, "abc"))
|
||||
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.PROPERTY_OR_FIELD_NOT_WRITABLE_ON_NULL));
|
||||
@@ -105,17 +100,17 @@ public class PropertyAccessTests extends AbstractExpressionTests {
|
||||
ctx.addPropertyAccessor(new StringyPropertyAccessor());
|
||||
Expression expr = parser.parseRaw("new String('hello').flibbles");
|
||||
Integer i = expr.getValue(ctx, Integer.class);
|
||||
assertEquals(7, (int) i);
|
||||
assertThat((int) i).isEqualTo(7);
|
||||
|
||||
// The reflection one will be used for other properties...
|
||||
expr = parser.parseRaw("new String('hello').CASE_INSENSITIVE_ORDER");
|
||||
Object o = expr.getValue(ctx);
|
||||
assertNotNull(o);
|
||||
assertThat(o).isNotNull();
|
||||
|
||||
SpelExpression flibbleexpr = parser.parseRaw("new String('hello').flibbles");
|
||||
flibbleexpr.setValue(ctx, 99);
|
||||
i = flibbleexpr.getValue(ctx, Integer.class);
|
||||
assertEquals(99, (int) i);
|
||||
assertThat((int) i).isEqualTo(99);
|
||||
|
||||
// Cannot set it to a string value
|
||||
assertThatExceptionOfType(EvaluationException.class).isThrownBy(() ->
|
||||
@@ -131,27 +126,27 @@ public class PropertyAccessTests extends AbstractExpressionTests {
|
||||
|
||||
// reflective property accessor is the only one by default
|
||||
List<PropertyAccessor> propertyAccessors = ctx.getPropertyAccessors();
|
||||
assertEquals(1,propertyAccessors.size());
|
||||
assertThat(propertyAccessors.size()).isEqualTo(1);
|
||||
|
||||
StringyPropertyAccessor spa = new StringyPropertyAccessor();
|
||||
ctx.addPropertyAccessor(spa);
|
||||
assertEquals(2,ctx.getPropertyAccessors().size());
|
||||
assertThat(ctx.getPropertyAccessors().size()).isEqualTo(2);
|
||||
|
||||
List<PropertyAccessor> copy = new ArrayList<>();
|
||||
copy.addAll(ctx.getPropertyAccessors());
|
||||
assertTrue(ctx.removePropertyAccessor(spa));
|
||||
assertFalse(ctx.removePropertyAccessor(spa));
|
||||
assertEquals(1,ctx.getPropertyAccessors().size());
|
||||
assertThat(ctx.removePropertyAccessor(spa)).isTrue();
|
||||
assertThat(ctx.removePropertyAccessor(spa)).isFalse();
|
||||
assertThat(ctx.getPropertyAccessors().size()).isEqualTo(1);
|
||||
|
||||
ctx.setPropertyAccessors(copy);
|
||||
assertEquals(2,ctx.getPropertyAccessors().size());
|
||||
assertThat(ctx.getPropertyAccessors().size()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAccessingPropertyOfClass() {
|
||||
Expression expression = parser.parseExpression("name");
|
||||
Object value = expression.getValue(new StandardEvaluationContext(String.class));
|
||||
assertEquals("java.lang.String", value);
|
||||
assertThat(value).isEqualTo("java.lang.String");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -161,16 +156,16 @@ public class PropertyAccessTests extends AbstractExpressionTests {
|
||||
|
||||
StandardEvaluationContext context = new StandardEvaluationContext();
|
||||
context.addPropertyAccessor(new ConfigurablePropertyAccessor(Collections.singletonMap("name", "Ollie")));
|
||||
assertEquals("Ollie", expression.getValue(context));
|
||||
assertThat(expression.getValue(context)).isEqualTo("Ollie");
|
||||
|
||||
context = new StandardEvaluationContext();
|
||||
context.addPropertyAccessor(new ConfigurablePropertyAccessor(Collections.singletonMap("name", "Jens")));
|
||||
assertEquals("Jens", expression.getValue(context));
|
||||
assertThat(expression.getValue(context)).isEqualTo("Jens");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void standardGetClassAccess() {
|
||||
assertEquals(String.class.getName(), parser.parseExpression("'a'.class.name").getValue());
|
||||
assertThat(parser.parseExpression("'a'.class.name").getValue()).isEqualTo(String.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -186,9 +181,9 @@ public class PropertyAccessTests extends AbstractExpressionTests {
|
||||
|
||||
Expression expr = parser.parseExpression("name");
|
||||
Person target = new Person("p1");
|
||||
assertEquals("p1", expr.getValue(context, target));
|
||||
assertThat(expr.getValue(context, target)).isEqualTo("p1");
|
||||
target.setName("p2");
|
||||
assertEquals("p2", expr.getValue(context, target));
|
||||
assertThat(expr.getValue(context, target)).isEqualTo("p2");
|
||||
|
||||
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() ->
|
||||
parser.parseExpression("name='p3'").getValue(context, target));
|
||||
@@ -200,37 +195,37 @@ public class PropertyAccessTests extends AbstractExpressionTests {
|
||||
|
||||
Expression expr = parser.parseExpression("name");
|
||||
Person target = new Person("p1");
|
||||
assertEquals("p1", expr.getValue(context, target));
|
||||
assertThat(expr.getValue(context, target)).isEqualTo("p1");
|
||||
target.setName("p2");
|
||||
assertEquals("p2", expr.getValue(context, target));
|
||||
assertThat(expr.getValue(context, target)).isEqualTo("p2");
|
||||
|
||||
parser.parseExpression("name='p3'").getValue(context, target);
|
||||
assertEquals("p3", target.getName());
|
||||
assertEquals("p3", expr.getValue(context, target));
|
||||
assertThat(target.getName()).isEqualTo("p3");
|
||||
assertThat(expr.getValue(context, target)).isEqualTo("p3");
|
||||
|
||||
expr.setValue(context, target, "p4");
|
||||
assertEquals("p4", target.getName());
|
||||
assertEquals("p4", expr.getValue(context, target));
|
||||
assertThat(target.getName()).isEqualTo("p4");
|
||||
assertThat(expr.getValue(context, target)).isEqualTo("p4");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertyReadWriteWithRootObject() {
|
||||
Person target = new Person("p1");
|
||||
EvaluationContext context = SimpleEvaluationContext.forReadWriteDataBinding().withRootObject(target).build();
|
||||
assertSame(target, context.getRootObject().getValue());
|
||||
assertThat(context.getRootObject().getValue()).isSameAs(target);
|
||||
|
||||
Expression expr = parser.parseExpression("name");
|
||||
assertEquals("p1", expr.getValue(context, target));
|
||||
assertThat(expr.getValue(context, target)).isEqualTo("p1");
|
||||
target.setName("p2");
|
||||
assertEquals("p2", expr.getValue(context, target));
|
||||
assertThat(expr.getValue(context, target)).isEqualTo("p2");
|
||||
|
||||
parser.parseExpression("name='p3'").getValue(context, target);
|
||||
assertEquals("p3", target.getName());
|
||||
assertEquals("p3", expr.getValue(context, target));
|
||||
assertThat(target.getName()).isEqualTo("p3");
|
||||
assertThat(expr.getValue(context, target)).isEqualTo("p3");
|
||||
|
||||
expr.setValue(context, target, "p4");
|
||||
assertEquals("p4", target.getName());
|
||||
assertEquals("p4", expr.getValue(context, target));
|
||||
assertThat(target.getName()).isEqualTo("p4");
|
||||
assertThat(expr.getValue(context, target)).isEqualTo("p4");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -245,7 +240,7 @@ public class PropertyAccessTests extends AbstractExpressionTests {
|
||||
public void propertyAccessWithInstanceMethodResolver() {
|
||||
EvaluationContext context = SimpleEvaluationContext.forReadOnlyDataBinding().withInstanceMethods().build();
|
||||
Person target = new Person("p1");
|
||||
assertEquals("1", parser.parseExpression("name.substring(1)").getValue(context, target));
|
||||
assertThat(parser.parseExpression("name.substring(1)").getValue(context, target)).isEqualTo("1");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -254,9 +249,9 @@ public class PropertyAccessTests extends AbstractExpressionTests {
|
||||
EvaluationContext context = SimpleEvaluationContext.forReadOnlyDataBinding().
|
||||
withInstanceMethods().withTypedRootObject(target, TypeDescriptor.valueOf(Object.class)).build();
|
||||
|
||||
assertEquals("1", parser.parseExpression("name.substring(1)").getValue(context, target));
|
||||
assertSame(target, context.getRootObject().getValue());
|
||||
assertSame(Object.class, context.getRootObject().getTypeDescriptor().getType());
|
||||
assertThat(parser.parseExpression("name.substring(1)").getValue(context, target)).isEqualTo("1");
|
||||
assertThat(context.getRootObject().getValue()).isSameAs(target);
|
||||
assertThat(context.getRootObject().getTypeDescriptor().getType()).isSameAs(Object.class);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -35,8 +35,7 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.expression.spel.support.ReflectionHelper;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
///CLOVER:OFF
|
||||
/**
|
||||
@@ -54,11 +53,11 @@ public class ScenariosForSpringSecurity extends AbstractExpressionTests {
|
||||
|
||||
ctx.setRootObject(new Person("Ben"));
|
||||
Boolean value = expr.getValue(ctx,Boolean.class);
|
||||
assertFalse(value);
|
||||
assertThat((boolean) value).isFalse();
|
||||
|
||||
ctx.setRootObject(new Manager("Luke"));
|
||||
value = expr.getValue(ctx,Boolean.class);
|
||||
assertTrue(value);
|
||||
assertThat((boolean) value).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -74,11 +73,11 @@ public class ScenariosForSpringSecurity extends AbstractExpressionTests {
|
||||
|
||||
ctx.setRootObject(new Person("Andy"));
|
||||
Boolean value = expr.getValue(ctx,Boolean.class);
|
||||
assertTrue(value);
|
||||
assertThat((boolean) value).isTrue();
|
||||
|
||||
ctx.setRootObject(new Person("Christian"));
|
||||
value = expr.getValue(ctx,Boolean.class);
|
||||
assertFalse(value);
|
||||
assertThat((boolean) value).isFalse();
|
||||
|
||||
// (2) Or register an accessor that can understand 'p' and return the right person
|
||||
expr = parser.parseRaw("p.name == principal.name");
|
||||
@@ -89,11 +88,11 @@ public class ScenariosForSpringSecurity extends AbstractExpressionTests {
|
||||
|
||||
pAccessor.setPerson(new Person("Andy"));
|
||||
value = expr.getValue(ctx,Boolean.class);
|
||||
assertTrue(value);
|
||||
assertThat((boolean) value).isTrue();
|
||||
|
||||
pAccessor.setPerson(new Person("Christian"));
|
||||
value = expr.getValue(ctx,Boolean.class);
|
||||
assertFalse(value);
|
||||
assertThat((boolean) value).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -110,12 +109,12 @@ public class ScenariosForSpringSecurity extends AbstractExpressionTests {
|
||||
ctx.setVariable("a",1.0d); // referenced as #a in the expression
|
||||
ctx.setRootObject(new Supervisor("Ben")); // so non-qualified references 'hasRole()' 'hasIpAddress()' are invoked against it
|
||||
value = expr.getValue(ctx,Boolean.class);
|
||||
assertTrue(value);
|
||||
assertThat((boolean) value).isTrue();
|
||||
|
||||
ctx.setRootObject(new Manager("Luke"));
|
||||
ctx.setVariable("a",1.043d);
|
||||
value = expr.getValue(ctx,Boolean.class);
|
||||
assertFalse(value);
|
||||
assertThat((boolean) value).isFalse();
|
||||
}
|
||||
|
||||
// Here i'm going to change which hasRole() executes and make it one of my own Java methods
|
||||
@@ -136,7 +135,7 @@ public class ScenariosForSpringSecurity extends AbstractExpressionTests {
|
||||
|
||||
ctx.setVariable("a",1.0d); // referenced as #a in the expression
|
||||
value = expr.getValue(ctx,Boolean.class);
|
||||
assertTrue(value);
|
||||
assertThat((boolean) value).isTrue();
|
||||
|
||||
// ctx.setRootObject(new Manager("Luke"));
|
||||
// ctx.setVariable("a",1.043d);
|
||||
|
||||
@@ -33,8 +33,7 @@ import org.springframework.expression.TypedValue;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -48,14 +47,15 @@ public class SelectionAndProjectionTests {
|
||||
Expression expression = new SpelExpressionParser().parseRaw("integers.?[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new ListTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
assertTrue(value instanceof List);
|
||||
boolean condition = value instanceof List;
|
||||
assertThat(condition).isTrue();
|
||||
List<?> list = (List<?>) value;
|
||||
assertEquals(5, list.size());
|
||||
assertEquals(0, list.get(0));
|
||||
assertEquals(1, list.get(1));
|
||||
assertEquals(2, list.get(2));
|
||||
assertEquals(3, list.get(3));
|
||||
assertEquals(4, list.get(4));
|
||||
assertThat(list.size()).isEqualTo(5);
|
||||
assertThat(list.get(0)).isEqualTo(0);
|
||||
assertThat(list.get(1)).isEqualTo(1);
|
||||
assertThat(list.get(2)).isEqualTo(2);
|
||||
assertThat(list.get(3)).isEqualTo(3);
|
||||
assertThat(list.get(4)).isEqualTo(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -63,8 +63,9 @@ public class SelectionAndProjectionTests {
|
||||
Expression expression = new SpelExpressionParser().parseRaw("integers.^[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new ListTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
assertTrue(value instanceof Integer);
|
||||
assertEquals(0, value);
|
||||
boolean condition = value instanceof Integer;
|
||||
assertThat(condition).isTrue();
|
||||
assertThat(value).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -72,8 +73,9 @@ public class SelectionAndProjectionTests {
|
||||
Expression expression = new SpelExpressionParser().parseRaw("integers.$[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new ListTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
assertTrue(value instanceof Integer);
|
||||
assertEquals(4, value);
|
||||
boolean condition = value instanceof Integer;
|
||||
assertThat(condition).isTrue();
|
||||
assertThat(value).isEqualTo(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -81,14 +83,15 @@ public class SelectionAndProjectionTests {
|
||||
Expression expression = new SpelExpressionParser().parseRaw("integers.?[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new SetTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
assertTrue(value instanceof List);
|
||||
boolean condition = value instanceof List;
|
||||
assertThat(condition).isTrue();
|
||||
List<?> list = (List<?>) value;
|
||||
assertEquals(5, list.size());
|
||||
assertEquals(0, list.get(0));
|
||||
assertEquals(1, list.get(1));
|
||||
assertEquals(2, list.get(2));
|
||||
assertEquals(3, list.get(3));
|
||||
assertEquals(4, list.get(4));
|
||||
assertThat(list.size()).isEqualTo(5);
|
||||
assertThat(list.get(0)).isEqualTo(0);
|
||||
assertThat(list.get(1)).isEqualTo(1);
|
||||
assertThat(list.get(2)).isEqualTo(2);
|
||||
assertThat(list.get(3)).isEqualTo(3);
|
||||
assertThat(list.get(4)).isEqualTo(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -96,8 +99,9 @@ public class SelectionAndProjectionTests {
|
||||
Expression expression = new SpelExpressionParser().parseRaw("integers.^[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new SetTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
assertTrue(value instanceof Integer);
|
||||
assertEquals(0, value);
|
||||
boolean condition = value instanceof Integer;
|
||||
assertThat(condition).isTrue();
|
||||
assertThat(value).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -105,8 +109,9 @@ public class SelectionAndProjectionTests {
|
||||
Expression expression = new SpelExpressionParser().parseRaw("integers.$[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new SetTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
assertTrue(value instanceof Integer);
|
||||
assertEquals(4, value);
|
||||
boolean condition = value instanceof Integer;
|
||||
assertThat(condition).isTrue();
|
||||
assertThat(value).isEqualTo(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -114,14 +119,15 @@ public class SelectionAndProjectionTests {
|
||||
Expression expression = new SpelExpressionParser().parseRaw("integers.?[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new IterableTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
assertTrue(value instanceof List);
|
||||
boolean condition = value instanceof List;
|
||||
assertThat(condition).isTrue();
|
||||
List<?> list = (List<?>) value;
|
||||
assertEquals(5, list.size());
|
||||
assertEquals(0, list.get(0));
|
||||
assertEquals(1, list.get(1));
|
||||
assertEquals(2, list.get(2));
|
||||
assertEquals(3, list.get(3));
|
||||
assertEquals(4, list.get(4));
|
||||
assertThat(list.size()).isEqualTo(5);
|
||||
assertThat(list.get(0)).isEqualTo(0);
|
||||
assertThat(list.get(1)).isEqualTo(1);
|
||||
assertThat(list.get(2)).isEqualTo(2);
|
||||
assertThat(list.get(3)).isEqualTo(3);
|
||||
assertThat(list.get(4)).isEqualTo(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -129,16 +135,16 @@ public class SelectionAndProjectionTests {
|
||||
Expression expression = new SpelExpressionParser().parseRaw("integers.?[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
assertTrue(value.getClass().isArray());
|
||||
assertThat(value.getClass().isArray()).isTrue();
|
||||
TypedValue typedValue = new TypedValue(value);
|
||||
assertEquals(Integer.class, typedValue.getTypeDescriptor().getElementTypeDescriptor().getType());
|
||||
assertThat(typedValue.getTypeDescriptor().getElementTypeDescriptor().getType()).isEqualTo(Integer.class);
|
||||
Integer[] array = (Integer[]) value;
|
||||
assertEquals(5, array.length);
|
||||
assertEquals(new Integer(0), array[0]);
|
||||
assertEquals(new Integer(1), array[1]);
|
||||
assertEquals(new Integer(2), array[2]);
|
||||
assertEquals(new Integer(3), array[3]);
|
||||
assertEquals(new Integer(4), array[4]);
|
||||
assertThat(array.length).isEqualTo(5);
|
||||
assertThat(array[0]).isEqualTo(new Integer(0));
|
||||
assertThat(array[1]).isEqualTo(new Integer(1));
|
||||
assertThat(array[2]).isEqualTo(new Integer(2));
|
||||
assertThat(array[3]).isEqualTo(new Integer(3));
|
||||
assertThat(array[4]).isEqualTo(new Integer(4));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -146,8 +152,9 @@ public class SelectionAndProjectionTests {
|
||||
Expression expression = new SpelExpressionParser().parseRaw("integers.^[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
assertTrue(value instanceof Integer);
|
||||
assertEquals(0, value);
|
||||
boolean condition = value instanceof Integer;
|
||||
assertThat(condition).isTrue();
|
||||
assertThat(value).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -155,8 +162,9 @@ public class SelectionAndProjectionTests {
|
||||
Expression expression = new SpelExpressionParser().parseRaw("integers.$[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
assertTrue(value instanceof Integer);
|
||||
assertEquals(4, value);
|
||||
boolean condition = value instanceof Integer;
|
||||
assertThat(condition).isTrue();
|
||||
assertThat(value).isEqualTo(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -164,16 +172,16 @@ public class SelectionAndProjectionTests {
|
||||
Expression expression = new SpelExpressionParser().parseRaw("ints.?[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
assertTrue(value.getClass().isArray());
|
||||
assertThat(value.getClass().isArray()).isTrue();
|
||||
TypedValue typedValue = new TypedValue(value);
|
||||
assertEquals(Integer.class, typedValue.getTypeDescriptor().getElementTypeDescriptor().getType());
|
||||
assertThat(typedValue.getTypeDescriptor().getElementTypeDescriptor().getType()).isEqualTo(Integer.class);
|
||||
Integer[] array = (Integer[]) value;
|
||||
assertEquals(5, array.length);
|
||||
assertEquals(new Integer(0), array[0]);
|
||||
assertEquals(new Integer(1), array[1]);
|
||||
assertEquals(new Integer(2), array[2]);
|
||||
assertEquals(new Integer(3), array[3]);
|
||||
assertEquals(new Integer(4), array[4]);
|
||||
assertThat(array.length).isEqualTo(5);
|
||||
assertThat(array[0]).isEqualTo(new Integer(0));
|
||||
assertThat(array[1]).isEqualTo(new Integer(1));
|
||||
assertThat(array[2]).isEqualTo(new Integer(2));
|
||||
assertThat(array[3]).isEqualTo(new Integer(3));
|
||||
assertThat(array[4]).isEqualTo(new Integer(4));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -181,8 +189,9 @@ public class SelectionAndProjectionTests {
|
||||
Expression expression = new SpelExpressionParser().parseRaw("ints.^[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
assertTrue(value instanceof Integer);
|
||||
assertEquals(0, value);
|
||||
boolean condition = value instanceof Integer;
|
||||
assertThat(condition).isTrue();
|
||||
assertThat(value).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -190,8 +199,9 @@ public class SelectionAndProjectionTests {
|
||||
Expression expression = new SpelExpressionParser().parseRaw("ints.$[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
assertTrue(value instanceof Integer);
|
||||
assertEquals(4, value);
|
||||
boolean condition = value instanceof Integer;
|
||||
assertThat(condition).isTrue();
|
||||
assertThat(value).isEqualTo(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -202,10 +212,10 @@ public class SelectionAndProjectionTests {
|
||||
Expression exp = parser.parseExpression("colors.?[key.startsWith('b')]");
|
||||
|
||||
Map<String, String> colorsMap = (Map<String, String>) exp.getValue(context);
|
||||
assertEquals(3, colorsMap.size());
|
||||
assertTrue(colorsMap.containsKey("beige"));
|
||||
assertTrue(colorsMap.containsKey("blue"));
|
||||
assertTrue(colorsMap.containsKey("brown"));
|
||||
assertThat(colorsMap.size()).isEqualTo(3);
|
||||
assertThat(colorsMap.containsKey("beige")).isTrue();
|
||||
assertThat(colorsMap.containsKey("blue")).isTrue();
|
||||
assertThat(colorsMap.containsKey("brown")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -216,8 +226,8 @@ public class SelectionAndProjectionTests {
|
||||
|
||||
Expression exp = parser.parseExpression("colors.^[key.startsWith('b')]");
|
||||
Map<String, String> colorsMap = (Map<String, String>) exp.getValue(context);
|
||||
assertEquals(1, colorsMap.size());
|
||||
assertEquals("beige", colorsMap.keySet().iterator().next());
|
||||
assertThat(colorsMap.size()).isEqualTo(1);
|
||||
assertThat(colorsMap.keySet().iterator().next()).isEqualTo("beige");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -228,8 +238,8 @@ public class SelectionAndProjectionTests {
|
||||
|
||||
Expression exp = parser.parseExpression("colors.$[key.startsWith('b')]");
|
||||
Map<String, String> colorsMap = (Map<String, String>) exp.getValue(context);
|
||||
assertEquals(1, colorsMap.size());
|
||||
assertEquals("brown", colorsMap.keySet().iterator().next());
|
||||
assertThat(colorsMap.size()).isEqualTo(1);
|
||||
assertThat(colorsMap.keySet().iterator().next()).isEqualTo("brown");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -238,12 +248,13 @@ public class SelectionAndProjectionTests {
|
||||
EvaluationContext context = new StandardEvaluationContext();
|
||||
context.setVariable("testList", IntegerTestBean.createList());
|
||||
Object value = expression.getValue(context);
|
||||
assertTrue(value instanceof List);
|
||||
boolean condition = value instanceof List;
|
||||
assertThat(condition).isTrue();
|
||||
List<?> list = (List<?>) value;
|
||||
assertEquals(3, list.size());
|
||||
assertEquals(5, list.get(0));
|
||||
assertEquals(6, list.get(1));
|
||||
assertEquals(7, list.get(2));
|
||||
assertThat(list.size()).isEqualTo(3);
|
||||
assertThat(list.get(0)).isEqualTo(5);
|
||||
assertThat(list.get(1)).isEqualTo(6);
|
||||
assertThat(list.get(2)).isEqualTo(7);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -252,12 +263,13 @@ public class SelectionAndProjectionTests {
|
||||
EvaluationContext context = new StandardEvaluationContext();
|
||||
context.setVariable("testList", IntegerTestBean.createSet());
|
||||
Object value = expression.getValue(context);
|
||||
assertTrue(value instanceof List);
|
||||
boolean condition = value instanceof List;
|
||||
assertThat(condition).isTrue();
|
||||
List<?> list = (List<?>) value;
|
||||
assertEquals(3, list.size());
|
||||
assertEquals(5, list.get(0));
|
||||
assertEquals(6, list.get(1));
|
||||
assertEquals(7, list.get(2));
|
||||
assertThat(list.size()).isEqualTo(3);
|
||||
assertThat(list.get(0)).isEqualTo(5);
|
||||
assertThat(list.get(1)).isEqualTo(6);
|
||||
assertThat(list.get(2)).isEqualTo(7);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -266,12 +278,13 @@ public class SelectionAndProjectionTests {
|
||||
EvaluationContext context = new StandardEvaluationContext();
|
||||
context.setVariable("testList", IntegerTestBean.createIterable());
|
||||
Object value = expression.getValue(context);
|
||||
assertTrue(value instanceof List);
|
||||
boolean condition = value instanceof List;
|
||||
assertThat(condition).isTrue();
|
||||
List<?> list = (List<?>) value;
|
||||
assertEquals(3, list.size());
|
||||
assertEquals(5, list.get(0));
|
||||
assertEquals(6, list.get(1));
|
||||
assertEquals(7, list.get(2));
|
||||
assertThat(list.size()).isEqualTo(3);
|
||||
assertThat(list.get(0)).isEqualTo(5);
|
||||
assertThat(list.get(1)).isEqualTo(6);
|
||||
assertThat(list.get(2)).isEqualTo(7);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -280,14 +293,14 @@ public class SelectionAndProjectionTests {
|
||||
EvaluationContext context = new StandardEvaluationContext();
|
||||
context.setVariable("testArray", IntegerTestBean.createArray());
|
||||
Object value = expression.getValue(context);
|
||||
assertTrue(value.getClass().isArray());
|
||||
assertThat(value.getClass().isArray()).isTrue();
|
||||
TypedValue typedValue = new TypedValue(value);
|
||||
assertEquals(Number.class, typedValue.getTypeDescriptor().getElementTypeDescriptor().getType());
|
||||
assertThat(typedValue.getTypeDescriptor().getElementTypeDescriptor().getType()).isEqualTo(Number.class);
|
||||
Number[] array = (Number[]) value;
|
||||
assertEquals(3, array.length);
|
||||
assertEquals(new Integer(5), array[0]);
|
||||
assertEquals(5.9f, array[1]);
|
||||
assertEquals(new Integer(7), array[2]);
|
||||
assertThat(array.length).isEqualTo(3);
|
||||
assertThat(array[0]).isEqualTo(new Integer(5));
|
||||
assertThat(array[1]).isEqualTo(5.9f);
|
||||
assertThat(array[2]).isEqualTo(new Integer(7));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -29,10 +29,6 @@ import org.springframework.expression.spel.testresources.PlaceOfBirth;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests set value expressions.
|
||||
@@ -90,7 +86,7 @@ public class SetValueTests extends AbstractExpressionTests {
|
||||
// PROPERTYORFIELDREFERENCE
|
||||
// Non existent field (or property):
|
||||
Expression e1 = parser.parseExpression("arrayContainer.wibble");
|
||||
assertFalse("Should not be writable!", e1.isWritable(lContext));
|
||||
assertThat(e1.isWritable(lContext)).as("Should not be writable!").isFalse();
|
||||
|
||||
Expression e2 = parser.parseExpression("arrayContainer.wibble.foo");
|
||||
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() ->
|
||||
@@ -101,10 +97,10 @@ public class SetValueTests extends AbstractExpressionTests {
|
||||
// VARIABLE
|
||||
// the variable does not exist (but that is OK, we should be writable)
|
||||
Expression e3 = parser.parseExpression("#madeup1");
|
||||
assertTrue("Should be writable!",e3.isWritable(lContext));
|
||||
assertThat(e3.isWritable(lContext)).as("Should be writable!").isTrue();
|
||||
|
||||
Expression e4 = parser.parseExpression("#madeup2.bar"); // compound expression
|
||||
assertFalse("Should not be writable!",e4.isWritable(lContext));
|
||||
assertThat(e4.isWritable(lContext)).as("Should not be writable!").isFalse();
|
||||
|
||||
// INDEXER
|
||||
// non existent indexer (wibble made up)
|
||||
@@ -188,8 +184,8 @@ public class SetValueTests extends AbstractExpressionTests {
|
||||
public void testAssign() throws Exception {
|
||||
StandardEvaluationContext eContext = TestScenarioCreator.getTestEvaluationContext();
|
||||
Expression e = parse("publicName='Andy'");
|
||||
assertFalse(e.isWritable(eContext));
|
||||
assertEquals("Andy",e.getValue(eContext));
|
||||
assertThat(e.isWritable(eContext)).isFalse();
|
||||
assertThat(e.getValue(eContext)).isEqualTo("Andy");
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -199,7 +195,7 @@ public class SetValueTests extends AbstractExpressionTests {
|
||||
public void testSetGenericMapElementRequiresCoercion() throws Exception {
|
||||
StandardEvaluationContext eContext = TestScenarioCreator.getTestEvaluationContext();
|
||||
Expression e = parse("mapOfStringToBoolean[42]");
|
||||
assertNull(e.getValue(eContext));
|
||||
assertThat(e.getValue(eContext)).isNull();
|
||||
|
||||
// Key should be coerced to string representation of 42
|
||||
e.setValue(eContext, "true");
|
||||
@@ -207,18 +203,18 @@ public class SetValueTests extends AbstractExpressionTests {
|
||||
// All keys should be strings
|
||||
Set<?> ks = parse("mapOfStringToBoolean.keySet()").getValue(eContext, Set.class);
|
||||
for (Object o: ks) {
|
||||
assertEquals(String.class,o.getClass());
|
||||
assertThat(o.getClass()).isEqualTo(String.class);
|
||||
}
|
||||
|
||||
// All values should be booleans
|
||||
Collection<?> vs = parse("mapOfStringToBoolean.values()").getValue(eContext, Collection.class);
|
||||
for (Object o: vs) {
|
||||
assertEquals(Boolean.class, o.getClass());
|
||||
assertThat(o.getClass()).isEqualTo(Boolean.class);
|
||||
}
|
||||
|
||||
// One final test check coercion on the key for a map lookup
|
||||
Object o = e.getValue(eContext);
|
||||
assertEquals(Boolean.TRUE,o);
|
||||
assertThat(o).isEqualTo(Boolean.TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -248,9 +244,9 @@ public class SetValueTests extends AbstractExpressionTests {
|
||||
SpelUtilities.printAbstractSyntaxTree(System.out, e);
|
||||
}
|
||||
StandardEvaluationContext lContext = TestScenarioCreator.getTestEvaluationContext();
|
||||
assertTrue("Expression is not writeable but should be", e.isWritable(lContext));
|
||||
assertThat(e.isWritable(lContext)).as("Expression is not writeable but should be").isTrue();
|
||||
e.setValue(lContext, value);
|
||||
assertEquals("Retrieved value was not equal to set value", value, e.getValue(lContext,value.getClass()));
|
||||
assertThat(e.getValue(lContext,value.getClass())).as("Retrieved value was not equal to set value").isEqualTo(value);
|
||||
}
|
||||
catch (EvaluationException | ParseException ex) {
|
||||
throw new AssertionError("Unexpected Exception: " + ex.getMessage(), ex);
|
||||
@@ -269,7 +265,7 @@ public class SetValueTests extends AbstractExpressionTests {
|
||||
SpelUtilities.printAbstractSyntaxTree(System.out, e);
|
||||
}
|
||||
StandardEvaluationContext lContext = TestScenarioCreator.getTestEvaluationContext();
|
||||
assertTrue("Expression is not writeable but should be", e.isWritable(lContext));
|
||||
assertThat(e.isWritable(lContext)).as("Expression is not writeable but should be").isTrue();
|
||||
e.setValue(lContext, value);
|
||||
Object a = expectedValue;
|
||||
Object b = e.getValue(lContext);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -22,10 +22,8 @@ import org.junit.Test;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.spel.standard.SpelCompiler;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Checks the speed of compiled SpEL expressions.
|
||||
@@ -57,7 +55,7 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
|
||||
NumberHolder nh = new NumberHolder();
|
||||
expression = parser.parseExpression("(T(Integer).valueOf(payload).doubleValue())/18D");
|
||||
Object o = expression.getValue(nh);
|
||||
assertEquals(2d,o);
|
||||
assertThat(o).isEqualTo(2d);
|
||||
System.out.println("Performance check for SpEL expression: '(T(Integer).valueOf(payload).doubleValue())/18D'");
|
||||
long stime = System.currentTimeMillis();
|
||||
for (int i = 0; i < 1000000; i++) {
|
||||
@@ -77,7 +75,7 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
|
||||
compile(expression);
|
||||
System.out.println("Now compiled:");
|
||||
o = expression.getValue(nh);
|
||||
assertEquals(2d, o);
|
||||
assertThat(o).isEqualTo(2d);
|
||||
|
||||
stime = System.currentTimeMillis();
|
||||
for (int i = 0; i < 1000000; i++) {
|
||||
@@ -97,7 +95,7 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
|
||||
|
||||
expression = parser.parseExpression("payload/18D");
|
||||
o = expression.getValue(nh);
|
||||
assertEquals(2d,o);
|
||||
assertThat(o).isEqualTo(2d);
|
||||
System.out.println("Performance check for SpEL expression: 'payload/18D'");
|
||||
stime = System.currentTimeMillis();
|
||||
for (int i = 0; i < 1000000; i++) {
|
||||
@@ -117,7 +115,7 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
|
||||
compile(expression);
|
||||
System.out.println("Now compiled:");
|
||||
o = expression.getValue(nh);
|
||||
assertEquals(2d, o);
|
||||
assertThat(o).isEqualTo(2d);
|
||||
|
||||
stime = System.currentTimeMillis();
|
||||
for (int i = 0; i < 1000000; i++) {
|
||||
@@ -140,7 +138,7 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
|
||||
public void inlineLists() throws Exception {
|
||||
expression = parser.parseExpression("{'abcde','ijklm'}[0].substring({1,3,4}[0],{1,3,4}[1])");
|
||||
Object o = expression.getValue();
|
||||
assertEquals("bc",o);
|
||||
assertThat(o).isEqualTo("bc");
|
||||
System.out.println("Performance check for SpEL expression: '{'abcde','ijklm'}[0].substring({1,3,4}[0],{1,3,4}[1])'");
|
||||
long stime = System.currentTimeMillis();
|
||||
for (int i = 0; i < 1000000; i++) {
|
||||
@@ -160,7 +158,7 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
|
||||
compile(expression);
|
||||
System.out.println("Now compiled:");
|
||||
o = expression.getValue();
|
||||
assertEquals("bc", o);
|
||||
assertThat(o).isEqualTo("bc");
|
||||
|
||||
stime = System.currentTimeMillis();
|
||||
for (int i = 0; i < 1000000; i++) {
|
||||
@@ -183,7 +181,7 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
|
||||
public void inlineNestedLists() throws Exception {
|
||||
expression = parser.parseExpression("{'abcde',{'ijklm','nopqr'}}[1][0].substring({1,3,4}[0],{1,3,4}[1])");
|
||||
Object o = expression.getValue();
|
||||
assertEquals("jk",o);
|
||||
assertThat(o).isEqualTo("jk");
|
||||
System.out.println("Performance check for SpEL expression: '{'abcde','ijklm'}[0].substring({1,3,4}[0],{1,3,4}[1])'");
|
||||
long stime = System.currentTimeMillis();
|
||||
for (int i = 0; i < 1000000; i++) {
|
||||
@@ -203,7 +201,7 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
|
||||
compile(expression);
|
||||
System.out.println("Now compiled:");
|
||||
o = expression.getValue();
|
||||
assertEquals("jk", o);
|
||||
assertThat(o).isEqualTo("jk");
|
||||
|
||||
stime = System.currentTimeMillis();
|
||||
for (int i = 0; i < 1000000; i++) {
|
||||
@@ -227,7 +225,7 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
|
||||
expression = parser.parseExpression("'hello' + getWorld() + ' spring'");
|
||||
Greeter g = new Greeter();
|
||||
Object o = expression.getValue(g);
|
||||
assertEquals("helloworld spring", o);
|
||||
assertThat(o).isEqualTo("helloworld spring");
|
||||
|
||||
System.out.println("Performance check for SpEL expression: 'hello' + getWorld() + ' spring'");
|
||||
long stime = System.currentTimeMillis();
|
||||
@@ -248,7 +246,7 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
|
||||
compile(expression);
|
||||
System.out.println("Now compiled:");
|
||||
o = expression.getValue(g);
|
||||
assertEquals("helloworld spring", o);
|
||||
assertThat(o).isEqualTo("helloworld spring");
|
||||
|
||||
stime = System.currentTimeMillis();
|
||||
for (int i = 0; i < 1000000; i++) {
|
||||
@@ -311,15 +309,15 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
|
||||
reportPerformance("complex expression",iTotal, cTotal);
|
||||
|
||||
// Verify the result
|
||||
assertFalse(b);
|
||||
assertThat(b).isFalse();
|
||||
|
||||
// Verify the same result for compiled vs interpreted
|
||||
assertEquals(b, bc);
|
||||
assertThat(bc).isEqualTo(b);
|
||||
|
||||
// Verify if the input changes, the result changes
|
||||
payload.DR[0].DRFixedSection.duration = 0.04d;
|
||||
bc = expression.getValue(payload, Boolean.TYPE);
|
||||
assertTrue(bc);
|
||||
assertThat(bc).isTrue();
|
||||
}
|
||||
|
||||
public static class HW {
|
||||
@@ -371,7 +369,7 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
|
||||
}
|
||||
logln();
|
||||
|
||||
assertEquals(interpretedResult,compiledResult);
|
||||
assertThat(compiledResult).isEqualTo(interpretedResult);
|
||||
reportPerformance("method reference", interpretedTotal, compiledTotal);
|
||||
if (compiledTotal >= interpretedTotal) {
|
||||
fail("Compiled version is slower than interpreted!");
|
||||
@@ -423,7 +421,7 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
|
||||
}
|
||||
logln();
|
||||
|
||||
assertEquals(interpretedResult,compiledResult);
|
||||
assertThat(compiledResult).isEqualTo(interpretedResult);
|
||||
reportPerformance("property reference (field)",interpretedTotal, compiledTotal);
|
||||
}
|
||||
|
||||
@@ -469,7 +467,7 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
|
||||
}
|
||||
logln();
|
||||
|
||||
assertEquals(interpretedResult,compiledResult);
|
||||
assertThat(compiledResult).isEqualTo(interpretedResult);
|
||||
reportPerformance("property reference (nested field)",interpretedTotal, compiledTotal);
|
||||
}
|
||||
|
||||
@@ -514,7 +512,7 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
|
||||
}
|
||||
logln();
|
||||
|
||||
assertEquals(interpretedResult,compiledResult);
|
||||
assertThat(compiledResult).isEqualTo(interpretedResult);
|
||||
reportPerformance("nested property reference (mixed field/getter)",interpretedTotal, compiledTotal);
|
||||
}
|
||||
|
||||
@@ -561,7 +559,7 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
|
||||
}
|
||||
logln();
|
||||
|
||||
assertEquals(interpretedResult,compiledResult);
|
||||
assertThat(compiledResult).isEqualTo(interpretedResult);
|
||||
reportPerformance("nested reference (mixed field/method)", interpretedTotal, compiledTotal);
|
||||
}
|
||||
|
||||
@@ -609,7 +607,7 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
|
||||
}
|
||||
logln();
|
||||
|
||||
assertEquals(interpretedResult,compiledResult);
|
||||
assertThat(compiledResult).isEqualTo(interpretedResult);
|
||||
|
||||
reportPerformance("property reference (getter)", interpretedTotal, compiledTotal);
|
||||
if (compiledTotal >= interpretedTotal) {
|
||||
@@ -650,7 +648,7 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
private void compile(Expression expression) {
|
||||
assertTrue(SpelCompiler.compile(expression));
|
||||
assertThat(SpelCompiler.compile(expression)).isTrue();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -35,11 +35,8 @@ import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
import org.springframework.expression.spel.testresources.Inventor;
|
||||
import org.springframework.expression.spel.testresources.PlaceOfBirth;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.within;
|
||||
|
||||
/**
|
||||
* Test the examples specified in the documentation.
|
||||
@@ -128,7 +125,7 @@ public class SpelDocumentationTests extends AbstractExpressionTests {
|
||||
context.setRootObject(tesla);
|
||||
|
||||
String name = (String) exp.getValue(context);
|
||||
assertEquals("Nikola Tesla",name);
|
||||
assertThat(name).isEqualTo("Nikola Tesla");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -140,7 +137,7 @@ public class SpelDocumentationTests extends AbstractExpressionTests {
|
||||
|
||||
Expression exp = parser.parseExpression("name == 'Nikola Tesla'");
|
||||
boolean isEqual = exp.getValue(context, Boolean.class); // evaluates to true
|
||||
assertTrue(isEqual);
|
||||
assertThat(isEqual).isTrue();
|
||||
}
|
||||
|
||||
// Section 7.4.1
|
||||
@@ -156,29 +153,29 @@ public class SpelDocumentationTests extends AbstractExpressionTests {
|
||||
ExpressionParser parser = new SpelExpressionParser();
|
||||
|
||||
String helloWorld = (String) parser.parseExpression("'Hello World'").getValue(); // evals to "Hello World"
|
||||
assertEquals("Hello World",helloWorld);
|
||||
assertThat(helloWorld).isEqualTo("Hello World");
|
||||
|
||||
double avogadrosNumber = (Double) parser.parseExpression("6.0221415E+23").getValue();
|
||||
assertEquals(6.0221415E+23, avogadrosNumber, 0);
|
||||
assertThat(avogadrosNumber).isCloseTo(6.0221415E+23, within((double) 0));
|
||||
|
||||
int maxValue = (Integer) parser.parseExpression("0x7FFFFFFF").getValue(); // evals to 2147483647
|
||||
assertEquals(Integer.MAX_VALUE,maxValue);
|
||||
assertThat(maxValue).isEqualTo(Integer.MAX_VALUE);
|
||||
|
||||
boolean trueValue = (Boolean) parser.parseExpression("true").getValue();
|
||||
assertTrue(trueValue);
|
||||
assertThat(trueValue).isTrue();
|
||||
|
||||
Object nullValue = parser.parseExpression("null").getValue();
|
||||
assertNull(nullValue);
|
||||
assertThat(nullValue).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyAccess() throws Exception {
|
||||
EvaluationContext context = TestScenarioCreator.getTestEvaluationContext();
|
||||
int year = (Integer) parser.parseExpression("Birthdate.Year + 1900").getValue(context); // 1856
|
||||
assertEquals(1856,year);
|
||||
assertThat(year).isEqualTo(1856);
|
||||
|
||||
String city = (String) parser.parseExpression("placeOfBirth.City").getValue(context);
|
||||
assertEquals("SmilJan",city);
|
||||
assertThat(city).isEqualTo("SmilJan");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -191,7 +188,7 @@ public class SpelDocumentationTests extends AbstractExpressionTests {
|
||||
|
||||
// evaluates to "Induction motor"
|
||||
String invention = parser.parseExpression("inventions[3]").getValue(teslaContext, String.class);
|
||||
assertEquals("Induction motor",invention);
|
||||
assertThat(invention).isEqualTo("Induction motor");
|
||||
|
||||
// Members List
|
||||
StandardEvaluationContext societyContext = new StandardEvaluationContext();
|
||||
@@ -201,12 +198,12 @@ public class SpelDocumentationTests extends AbstractExpressionTests {
|
||||
|
||||
// evaluates to "Nikola Tesla"
|
||||
String name = parser.parseExpression("Members[0].Name").getValue(societyContext, String.class);
|
||||
assertEquals("Nikola Tesla",name);
|
||||
assertThat(name).isEqualTo("Nikola Tesla");
|
||||
|
||||
// List and Array navigation
|
||||
// evaluates to "Wireless communication"
|
||||
invention = parser.parseExpression("Members[0].Inventions[6]").getValue(societyContext, String.class);
|
||||
assertEquals("Wireless communication",invention);
|
||||
assertThat(invention).isEqualTo("Wireless communication");
|
||||
}
|
||||
|
||||
|
||||
@@ -216,20 +213,20 @@ public class SpelDocumentationTests extends AbstractExpressionTests {
|
||||
societyContext.setRootObject(new IEEE());
|
||||
// Officer's Dictionary
|
||||
Inventor pupin = parser.parseExpression("officers['president']").getValue(societyContext, Inventor.class);
|
||||
assertNotNull(pupin);
|
||||
assertThat(pupin).isNotNull();
|
||||
|
||||
// evaluates to "Idvor"
|
||||
String city = parser.parseExpression("officers['president'].PlaceOfBirth.city").getValue(societyContext, String.class);
|
||||
assertNotNull(city);
|
||||
assertThat(city).isNotNull();
|
||||
|
||||
// setting values
|
||||
Inventor i = parser.parseExpression("officers['advisors'][0]").getValue(societyContext,Inventor.class);
|
||||
assertEquals("Nikola Tesla",i.getName());
|
||||
assertThat(i.getName()).isEqualTo("Nikola Tesla");
|
||||
|
||||
parser.parseExpression("officers['advisors'][0].PlaceOfBirth.Country").setValue(societyContext, "Croatia");
|
||||
|
||||
Inventor i2 = parser.parseExpression("reverse[0]['advisors'][0]").getValue(societyContext,Inventor.class);
|
||||
assertEquals("Nikola Tesla",i2.getName());
|
||||
assertThat(i2.getName()).isEqualTo("Nikola Tesla");
|
||||
|
||||
}
|
||||
|
||||
@@ -239,13 +236,13 @@ public class SpelDocumentationTests extends AbstractExpressionTests {
|
||||
public void testMethodInvocation2() throws Exception {
|
||||
// string literal, evaluates to "bc"
|
||||
String c = parser.parseExpression("'abc'.substring(1, 3)").getValue(String.class);
|
||||
assertEquals("bc",c);
|
||||
assertThat(c).isEqualTo("bc");
|
||||
|
||||
StandardEvaluationContext societyContext = new StandardEvaluationContext();
|
||||
societyContext.setRootObject(new IEEE());
|
||||
// evaluates to true
|
||||
boolean isMember = parser.parseExpression("isMember('Mihajlo Pupin')").getValue(societyContext, Boolean.class);
|
||||
assertTrue(isMember);
|
||||
assertThat(isMember).isTrue();
|
||||
}
|
||||
|
||||
// 7.5.4.1
|
||||
@@ -253,29 +250,29 @@ public class SpelDocumentationTests extends AbstractExpressionTests {
|
||||
@Test
|
||||
public void testRelationalOperators() throws Exception {
|
||||
boolean result = parser.parseExpression("2 == 2").getValue(Boolean.class);
|
||||
assertTrue(result);
|
||||
assertThat(result).isTrue();
|
||||
// evaluates to false
|
||||
result = parser.parseExpression("2 < -5.0").getValue(Boolean.class);
|
||||
assertFalse(result);
|
||||
assertThat(result).isFalse();
|
||||
|
||||
// evaluates to true
|
||||
result = parser.parseExpression("'black' < 'block'").getValue(Boolean.class);
|
||||
assertTrue(result);
|
||||
assertThat(result).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOtherOperators() throws Exception {
|
||||
// evaluates to false
|
||||
boolean falseValue = parser.parseExpression("'xyz' instanceof T(int)").getValue(Boolean.class);
|
||||
assertFalse(falseValue);
|
||||
assertThat(falseValue).isFalse();
|
||||
|
||||
// evaluates to true
|
||||
boolean trueValue = parser.parseExpression("'5.00' matches '^-?\\d+(\\.\\d{2})?$'").getValue(Boolean.class);
|
||||
assertTrue(trueValue);
|
||||
assertThat(trueValue).isTrue();
|
||||
|
||||
//evaluates to false
|
||||
falseValue = parser.parseExpression("'5.0067' matches '^-?\\d+(\\.\\d{2})?$'").getValue(Boolean.class);
|
||||
assertFalse(falseValue);
|
||||
assertThat(falseValue).isFalse();
|
||||
}
|
||||
|
||||
// 7.5.4.2
|
||||
@@ -290,7 +287,7 @@ public class SpelDocumentationTests extends AbstractExpressionTests {
|
||||
|
||||
// evaluates to false
|
||||
boolean falseValue = parser.parseExpression("true and false").getValue(Boolean.class);
|
||||
assertFalse(falseValue);
|
||||
assertThat(falseValue).isFalse();
|
||||
// evaluates to true
|
||||
String expression = "isMember('Nikola Tesla') and isMember('Mihajlo Pupin')";
|
||||
boolean trueValue = parser.parseExpression(expression).getValue(societyContext, Boolean.class);
|
||||
@@ -299,24 +296,24 @@ public class SpelDocumentationTests extends AbstractExpressionTests {
|
||||
|
||||
// evaluates to true
|
||||
trueValue = parser.parseExpression("true or false").getValue(Boolean.class);
|
||||
assertTrue(trueValue);
|
||||
assertThat(trueValue).isTrue();
|
||||
|
||||
// evaluates to true
|
||||
expression = "isMember('Nikola Tesla') or isMember('Albert Einstien')";
|
||||
trueValue = parser.parseExpression(expression).getValue(societyContext, Boolean.class);
|
||||
assertTrue(trueValue);
|
||||
assertThat(trueValue).isTrue();
|
||||
|
||||
// -- NOT --
|
||||
|
||||
// evaluates to false
|
||||
falseValue = parser.parseExpression("!true").getValue(Boolean.class);
|
||||
assertFalse(falseValue);
|
||||
assertThat(falseValue).isFalse();
|
||||
|
||||
|
||||
// -- AND and NOT --
|
||||
expression = "isMember('Nikola Tesla') and !isMember('Mihajlo Pupin')";
|
||||
falseValue = parser.parseExpression(expression).getValue(societyContext, Boolean.class);
|
||||
assertFalse(falseValue);
|
||||
assertThat(falseValue).isFalse();
|
||||
}
|
||||
|
||||
// 7.5.4.3
|
||||
@@ -325,42 +322,42 @@ public class SpelDocumentationTests extends AbstractExpressionTests {
|
||||
public void testNumericalOperators() throws Exception {
|
||||
// Addition
|
||||
int two = parser.parseExpression("1 + 1").getValue(Integer.class); // 2
|
||||
assertEquals(2,two);
|
||||
assertThat(two).isEqualTo(2);
|
||||
|
||||
String testString = parser.parseExpression("'test' + ' ' + 'string'").getValue(String.class); // 'test string'
|
||||
assertEquals("test string",testString);
|
||||
assertThat(testString).isEqualTo("test string");
|
||||
|
||||
// Subtraction
|
||||
int four = parser.parseExpression("1 - -3").getValue(Integer.class); // 4
|
||||
assertEquals(4,four);
|
||||
assertThat(four).isEqualTo(4);
|
||||
|
||||
double d = parser.parseExpression("1000.00 - 1e4").getValue(Double.class); // -9000
|
||||
assertEquals(-9000.0d, d, 0);
|
||||
assertThat(d).isCloseTo(-9000.0d, within((double) 0));
|
||||
|
||||
// Multiplication
|
||||
int six = parser.parseExpression("-2 * -3").getValue(Integer.class); // 6
|
||||
assertEquals(6,six);
|
||||
assertThat(six).isEqualTo(6);
|
||||
|
||||
double twentyFour = parser.parseExpression("2.0 * 3e0 * 4").getValue(Double.class); // 24.0
|
||||
assertEquals(24.0d, twentyFour, 0);
|
||||
assertThat(twentyFour).isCloseTo(24.0d, within((double) 0));
|
||||
|
||||
// Division
|
||||
int minusTwo = parser.parseExpression("6 / -3").getValue(Integer.class); // -2
|
||||
assertEquals(-2,minusTwo);
|
||||
assertThat(minusTwo).isEqualTo(-2);
|
||||
|
||||
double one = parser.parseExpression("8.0 / 4e0 / 2").getValue(Double.class); // 1.0
|
||||
assertEquals(1.0d, one, 0);
|
||||
assertThat(one).isCloseTo(1.0d, within((double) 0));
|
||||
|
||||
// Modulus
|
||||
int three = parser.parseExpression("7 % 4").getValue(Integer.class); // 3
|
||||
assertEquals(3,three);
|
||||
assertThat(three).isEqualTo(3);
|
||||
|
||||
int oneInt = parser.parseExpression("8 / 5 % 2").getValue(Integer.class); // 1
|
||||
assertEquals(1,oneInt);
|
||||
assertThat(oneInt).isEqualTo(1);
|
||||
|
||||
// Operator precedence
|
||||
int minusTwentyOne = parser.parseExpression("1+2-3*8").getValue(Integer.class); // -21
|
||||
assertEquals(-21,minusTwentyOne);
|
||||
assertThat(minusTwentyOne).isEqualTo(-21);
|
||||
}
|
||||
|
||||
// 7.5.5
|
||||
@@ -373,12 +370,12 @@ public class SpelDocumentationTests extends AbstractExpressionTests {
|
||||
|
||||
parser.parseExpression("foo").setValue(inventorContext, "Alexander Seovic2");
|
||||
|
||||
assertEquals("Alexander Seovic2",parser.parseExpression("foo").getValue(inventorContext,String.class));
|
||||
assertThat(parser.parseExpression("foo").getValue(inventorContext,String.class)).isEqualTo("Alexander Seovic2");
|
||||
// alternatively
|
||||
|
||||
String aleks = parser.parseExpression("foo = 'Alexandar Seovic'").getValue(inventorContext, String.class);
|
||||
assertEquals("Alexandar Seovic",parser.parseExpression("foo").getValue(inventorContext,String.class));
|
||||
assertEquals("Alexandar Seovic",aleks);
|
||||
assertThat(parser.parseExpression("foo").getValue(inventorContext,String.class)).isEqualTo("Alexandar Seovic");
|
||||
assertThat(aleks).isEqualTo("Alexandar Seovic");
|
||||
}
|
||||
|
||||
// 7.5.6
|
||||
@@ -386,9 +383,9 @@ public class SpelDocumentationTests extends AbstractExpressionTests {
|
||||
@Test
|
||||
public void testTypes() throws Exception {
|
||||
Class<?> dateClass = parser.parseExpression("T(java.util.Date)").getValue(Class.class);
|
||||
assertEquals(Date.class, dateClass);
|
||||
assertThat(dateClass).isEqualTo(Date.class);
|
||||
boolean trueValue = parser.parseExpression("T(java.math.RoundingMode).CEILING < T(java.math.RoundingMode).FLOOR").getValue(Boolean.class);
|
||||
assertTrue(trueValue);
|
||||
assertThat(trueValue).isTrue();
|
||||
}
|
||||
|
||||
// 7.5.7
|
||||
@@ -399,7 +396,7 @@ public class SpelDocumentationTests extends AbstractExpressionTests {
|
||||
societyContext.setRootObject(new IEEE());
|
||||
Inventor einstein =
|
||||
parser.parseExpression("new org.springframework.expression.spel.testresources.Inventor('Albert Einstein',new java.util.Date(), 'German')").getValue(Inventor.class);
|
||||
assertEquals("Albert Einstein", einstein.getName());
|
||||
assertThat(einstein.getName()).isEqualTo("Albert Einstein");
|
||||
//create new inventor instance within add method of List
|
||||
parser.parseExpression("Members2.add(new org.springframework.expression.spel.testresources.Inventor('Albert Einstein', 'German'))").getValue(societyContext);
|
||||
}
|
||||
@@ -416,7 +413,7 @@ public class SpelDocumentationTests extends AbstractExpressionTests {
|
||||
|
||||
parser.parseExpression("foo = #newName").getValue(context);
|
||||
|
||||
assertEquals("Mike Tesla",tesla.getFoo());
|
||||
assertThat(tesla.getFoo()).isEqualTo("Mike Tesla");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -433,7 +430,7 @@ public class SpelDocumentationTests extends AbstractExpressionTests {
|
||||
|
||||
// all prime numbers > 10 from the list (using selection ?{...})
|
||||
List<Integer> primesGreaterThanTen = (List<Integer>) parser.parseExpression("#primes.?[#this>10]").getValue(context);
|
||||
assertEquals("[11, 13, 17]",primesGreaterThanTen.toString());
|
||||
assertThat(primesGreaterThanTen.toString()).isEqualTo("[11, 13, 17]");
|
||||
}
|
||||
|
||||
// 7.5.9
|
||||
@@ -445,7 +442,7 @@ public class SpelDocumentationTests extends AbstractExpressionTests {
|
||||
context.registerFunction("reverseString", StringUtils.class.getDeclaredMethod("reverseString", String.class));
|
||||
|
||||
String helloWorldReversed = parser.parseExpression("#reverseString('hello world')").getValue(context, String.class);
|
||||
assertEquals("dlrow olleh",helloWorldReversed);
|
||||
assertThat(helloWorldReversed).isEqualTo("dlrow olleh");
|
||||
}
|
||||
|
||||
// 7.5.10
|
||||
@@ -453,7 +450,7 @@ public class SpelDocumentationTests extends AbstractExpressionTests {
|
||||
@Test
|
||||
public void testTernary() throws Exception {
|
||||
String falseString = parser.parseExpression("false ? 'trueExp' : 'falseExp'").getValue(String.class);
|
||||
assertEquals("falseExp",falseString);
|
||||
assertThat(falseString).isEqualTo("falseExp");
|
||||
|
||||
StandardEvaluationContext societyContext = new StandardEvaluationContext();
|
||||
societyContext.setRootObject(new IEEE());
|
||||
@@ -466,7 +463,7 @@ public class SpelDocumentationTests extends AbstractExpressionTests {
|
||||
+ "+ Name + ' Society' : #queryName + ' is not a member of the ' + Name + ' Society'";
|
||||
|
||||
String queryResultString = parser.parseExpression(expression).getValue(societyContext, String.class);
|
||||
assertEquals("Nikola Tesla is a member of the IEEE Society",queryResultString);
|
||||
assertThat(queryResultString).isEqualTo("Nikola Tesla is a member of the IEEE Society");
|
||||
// queryResultString = "Nikola Tesla is a member of the IEEE Society"
|
||||
}
|
||||
|
||||
@@ -478,8 +475,8 @@ public class SpelDocumentationTests extends AbstractExpressionTests {
|
||||
StandardEvaluationContext societyContext = new StandardEvaluationContext();
|
||||
societyContext.setRootObject(new IEEE());
|
||||
List<Inventor> list = (List<Inventor>) parser.parseExpression("Members2.?[nationality == 'Serbian']").getValue(societyContext);
|
||||
assertEquals(1,list.size());
|
||||
assertEquals("Nikola Tesla",list.get(0).getName());
|
||||
assertThat(list.size()).isEqualTo(1);
|
||||
assertThat(list.get(0).getName()).isEqualTo("Nikola Tesla");
|
||||
}
|
||||
|
||||
// 7.5.12
|
||||
@@ -488,7 +485,7 @@ public class SpelDocumentationTests extends AbstractExpressionTests {
|
||||
public void testTemplating() throws Exception {
|
||||
String randomPhrase =
|
||||
parser.parseExpression("random number is ${T(java.lang.Math).random()}", new TemplatedParserContext()).getValue(String.class);
|
||||
assertTrue(randomPhrase.startsWith("random number"));
|
||||
assertThat(randomPhrase.startsWith("random number")).isTrue();
|
||||
}
|
||||
|
||||
static class TemplatedParserContext implements ParserContext {
|
||||
|
||||
@@ -26,8 +26,8 @@ import org.springframework.expression.ExpressionParser;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* SpelEvaluationException tests (SPR-16544).
|
||||
@@ -72,7 +72,7 @@ public class SpelExceptionTests {
|
||||
}
|
||||
});
|
||||
boolean result = spelExpression.getValue(ctx, Boolean.class);
|
||||
assertTrue(result);
|
||||
assertThat(result).isTrue();
|
||||
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ public class SpelExceptionTests {
|
||||
}
|
||||
});
|
||||
boolean result = spelExpression.getValue(ctx, Boolean.class);
|
||||
assertTrue(result);
|
||||
assertThat(result).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -133,7 +133,7 @@ public class SpelExceptionTests {
|
||||
}
|
||||
});
|
||||
boolean result = spelExpression.getValue(ctx, Boolean.class);
|
||||
assertTrue(result);
|
||||
assertThat(result).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -156,7 +156,7 @@ public class SpelExceptionTests {
|
||||
}
|
||||
});
|
||||
boolean result = spelExpression.getValue(ctx, Boolean.class);
|
||||
assertTrue(result);
|
||||
assertThat(result).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -24,9 +24,6 @@ import org.springframework.expression.spel.support.StandardTypeLocator;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Unit tests for type comparison
|
||||
@@ -38,15 +35,15 @@ public class StandardTypeLocatorTests {
|
||||
@Test
|
||||
public void testImports() throws EvaluationException {
|
||||
StandardTypeLocator locator = new StandardTypeLocator();
|
||||
assertEquals(Integer.class,locator.findType("java.lang.Integer"));
|
||||
assertEquals(String.class,locator.findType("java.lang.String"));
|
||||
assertThat(locator.findType("java.lang.Integer")).isEqualTo(Integer.class);
|
||||
assertThat(locator.findType("java.lang.String")).isEqualTo(String.class);
|
||||
|
||||
List<String> prefixes = locator.getImportPrefixes();
|
||||
assertEquals(1,prefixes.size());
|
||||
assertTrue(prefixes.contains("java.lang"));
|
||||
assertFalse(prefixes.contains("java.util"));
|
||||
assertThat(prefixes.size()).isEqualTo(1);
|
||||
assertThat(prefixes.contains("java.lang")).isTrue();
|
||||
assertThat(prefixes.contains("java.util")).isFalse();
|
||||
|
||||
assertEquals(Boolean.class,locator.findType("Boolean"));
|
||||
assertThat(locator.findType("Boolean")).isEqualTo(Boolean.class);
|
||||
// currently does not know about java.util by default
|
||||
// assertEquals(java.util.List.class,locator.findType("List"));
|
||||
|
||||
@@ -54,7 +51,7 @@ public class StandardTypeLocatorTests {
|
||||
locator.findType("URL"))
|
||||
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.TYPE_NOT_FOUND));
|
||||
locator.registerImport("java.net");
|
||||
assertEquals(java.net.URL.class,locator.findType("URL"));
|
||||
assertThat(locator.findType("URL")).isEqualTo(java.net.URL.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,9 +30,6 @@ import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Andy Clement
|
||||
@@ -76,7 +73,7 @@ public class TemplateExpressionParsingTests extends AbstractExpressionTests {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
Expression expr = parser.parseExpression("hello ${'world'}", DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
Object o = expr.getValue();
|
||||
assertEquals("hello world", o.toString());
|
||||
assertThat(o.toString()).isEqualTo("hello world");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -84,7 +81,7 @@ public class TemplateExpressionParsingTests extends AbstractExpressionTests {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
Expression expr = parser.parseExpression("hello ${'to'} you", DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
Object o = expr.getValue();
|
||||
assertEquals("hello to you", o.toString());
|
||||
assertThat(o.toString()).isEqualTo("hello to you");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -93,7 +90,7 @@ public class TemplateExpressionParsingTests extends AbstractExpressionTests {
|
||||
Expression expr = parser.parseExpression("The quick ${'brown'} fox jumped over the ${'lazy'} dog",
|
||||
DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
Object o = expr.getValue();
|
||||
assertEquals("The quick brown fox jumped over the lazy dog", o.toString());
|
||||
assertThat(o.toString()).isEqualTo("The quick brown fox jumped over the lazy dog");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,19 +98,19 @@ public class TemplateExpressionParsingTests extends AbstractExpressionTests {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
Expression expr = parser.parseExpression("${'hello'} world", DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
Object o = expr.getValue();
|
||||
assertEquals("hello world", o.toString());
|
||||
assertThat(o.toString()).isEqualTo("hello world");
|
||||
|
||||
expr = parser.parseExpression("", DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
o = expr.getValue();
|
||||
assertEquals("", o.toString());
|
||||
assertThat(o.toString()).isEqualTo("");
|
||||
|
||||
expr = parser.parseExpression("abc", DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
o = expr.getValue();
|
||||
assertEquals("abc", o.toString());
|
||||
assertThat(o.toString()).isEqualTo("abc");
|
||||
|
||||
expr = parser.parseExpression("abc", DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
o = expr.getValue((Object)null);
|
||||
assertEquals("abc", o.toString());
|
||||
assertThat(o.toString()).isEqualTo("abc");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -133,19 +130,19 @@ public class TemplateExpressionParsingTests extends AbstractExpressionTests {
|
||||
assertThat(ex.getValue(ctx, new Rooty())).isInstanceOf(String.class).isEqualTo("hello world");
|
||||
assertThat(ex.getValue(ctx, new Rooty(), String.class)).isInstanceOf(String.class).isEqualTo("hello world");
|
||||
assertThat(ex.getValue(ctx, new Rooty(), String.class)).isInstanceOf(String.class).isEqualTo("hello world");
|
||||
assertEquals("hello ${'world'}", ex.getExpressionString());
|
||||
assertFalse(ex.isWritable(new StandardEvaluationContext()));
|
||||
assertFalse(ex.isWritable(new Rooty()));
|
||||
assertFalse(ex.isWritable(new StandardEvaluationContext(), new Rooty()));
|
||||
assertThat(ex.getExpressionString()).isEqualTo("hello ${'world'}");
|
||||
assertThat(ex.isWritable(new StandardEvaluationContext())).isFalse();
|
||||
assertThat(ex.isWritable(new Rooty())).isFalse();
|
||||
assertThat(ex.isWritable(new StandardEvaluationContext(), new Rooty())).isFalse();
|
||||
|
||||
assertEquals(String.class,ex.getValueType());
|
||||
assertEquals(String.class,ex.getValueType(ctx));
|
||||
assertEquals(String.class,ex.getValueTypeDescriptor().getType());
|
||||
assertEquals(String.class,ex.getValueTypeDescriptor(ctx).getType());
|
||||
assertEquals(String.class,ex.getValueType(new Rooty()));
|
||||
assertEquals(String.class,ex.getValueType(ctx, new Rooty()));
|
||||
assertEquals(String.class,ex.getValueTypeDescriptor(new Rooty()).getType());
|
||||
assertEquals(String.class,ex.getValueTypeDescriptor(ctx, new Rooty()).getType());
|
||||
assertThat(ex.getValueType()).isEqualTo(String.class);
|
||||
assertThat(ex.getValueType(ctx)).isEqualTo(String.class);
|
||||
assertThat(ex.getValueTypeDescriptor().getType()).isEqualTo(String.class);
|
||||
assertThat(ex.getValueTypeDescriptor(ctx).getType()).isEqualTo(String.class);
|
||||
assertThat(ex.getValueType(new Rooty())).isEqualTo(String.class);
|
||||
assertThat(ex.getValueType(ctx, new Rooty())).isEqualTo(String.class);
|
||||
assertThat(ex.getValueTypeDescriptor(new Rooty()).getType()).isEqualTo(String.class);
|
||||
assertThat(ex.getValueTypeDescriptor(ctx, new Rooty()).getType()).isEqualTo(String.class);
|
||||
assertThatExceptionOfType(EvaluationException.class).isThrownBy(() ->
|
||||
ex.setValue(ctx, null));
|
||||
assertThatExceptionOfType(EvaluationException.class).isThrownBy(() ->
|
||||
@@ -162,21 +159,21 @@ public class TemplateExpressionParsingTests extends AbstractExpressionTests {
|
||||
// treat the nested ${..} as a part of the expression
|
||||
Expression ex = parser.parseExpression("hello ${listOfNumbersUpToTen.$[#this<5]} world",DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
String s = ex.getValue(TestScenarioCreator.getTestEvaluationContext(),String.class);
|
||||
assertEquals("hello 4 world",s);
|
||||
assertThat(s).isEqualTo("hello 4 world");
|
||||
|
||||
// not a useful expression but tests nested expression syntax that clashes with template prefix/suffix
|
||||
ex = parser.parseExpression("hello ${listOfNumbersUpToTen.$[#root.listOfNumbersUpToTen.$[#this%2==1]==3]} world",DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
assertEquals(CompositeStringExpression.class,ex.getClass());
|
||||
assertThat(ex.getClass()).isEqualTo(CompositeStringExpression.class);
|
||||
CompositeStringExpression cse = (CompositeStringExpression)ex;
|
||||
Expression[] exprs = cse.getExpressions();
|
||||
assertEquals(3,exprs.length);
|
||||
assertEquals("listOfNumbersUpToTen.$[#root.listOfNumbersUpToTen.$[#this%2==1]==3]",exprs[1].getExpressionString());
|
||||
assertThat(exprs.length).isEqualTo(3);
|
||||
assertThat(exprs[1].getExpressionString()).isEqualTo("listOfNumbersUpToTen.$[#root.listOfNumbersUpToTen.$[#this%2==1]==3]");
|
||||
s = ex.getValue(TestScenarioCreator.getTestEvaluationContext(),String.class);
|
||||
assertEquals("hello world",s);
|
||||
assertThat(s).isEqualTo("hello world");
|
||||
|
||||
ex = parser.parseExpression("hello ${listOfNumbersUpToTen.$[#this<5]} ${listOfNumbersUpToTen.$[#this>5]} world",DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
s = ex.getValue(TestScenarioCreator.getTestEvaluationContext(),String.class);
|
||||
assertEquals("hello 4 10 world",s);
|
||||
assertThat(s).isEqualTo("hello 4 10 world");
|
||||
|
||||
assertThatExceptionOfType(ParseException.class).isThrownBy(() ->
|
||||
parser.parseExpression("hello ${listOfNumbersUpToTen.$[#this<5]} ${listOfNumbersUpToTen.$[#this>5] world",DEFAULT_TEMPLATE_PARSER_CONTEXT))
|
||||
@@ -193,21 +190,21 @@ public class TemplateExpressionParsingTests extends AbstractExpressionTests {
|
||||
// Just wanting to use the prefix or suffix within the template:
|
||||
Expression ex = parser.parseExpression("hello ${3+4} world",DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
String s = ex.getValue(TestScenarioCreator.getTestEvaluationContext(),String.class);
|
||||
assertEquals("hello 7 world", s);
|
||||
assertThat(s).isEqualTo("hello 7 world");
|
||||
|
||||
ex = parser.parseExpression("hello ${3+4} wo${'${'}rld",DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
s = ex.getValue(TestScenarioCreator.getTestEvaluationContext(),String.class);
|
||||
assertEquals("hello 7 wo${rld", s);
|
||||
assertThat(s).isEqualTo("hello 7 wo${rld");
|
||||
|
||||
ex = parser.parseExpression("hello ${3+4} wo}rld",DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
s = ex.getValue(TestScenarioCreator.getTestEvaluationContext(),String.class);
|
||||
assertEquals("hello 7 wo}rld", s);
|
||||
assertThat(s).isEqualTo("hello 7 wo}rld");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParsingNormalExpressionThroughTemplateParser() throws Exception {
|
||||
Expression expr = parser.parseExpression("1+2+3");
|
||||
assertEquals(6, expr.getValue());
|
||||
assertThat(expr.getValue()).isEqualTo(6);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -229,19 +226,19 @@ public class TemplateExpressionParsingTests extends AbstractExpressionTests {
|
||||
@Test
|
||||
public void testTemplateParserContext() {
|
||||
TemplateParserContext tpc = new TemplateParserContext("abc","def");
|
||||
assertEquals("abc", tpc.getExpressionPrefix());
|
||||
assertEquals("def", tpc.getExpressionSuffix());
|
||||
assertTrue(tpc.isTemplate());
|
||||
assertThat(tpc.getExpressionPrefix()).isEqualTo("abc");
|
||||
assertThat(tpc.getExpressionSuffix()).isEqualTo("def");
|
||||
assertThat(tpc.isTemplate()).isTrue();
|
||||
|
||||
tpc = new TemplateParserContext();
|
||||
assertEquals("#{", tpc.getExpressionPrefix());
|
||||
assertEquals("}", tpc.getExpressionSuffix());
|
||||
assertTrue(tpc.isTemplate());
|
||||
assertThat(tpc.getExpressionPrefix()).isEqualTo("#{");
|
||||
assertThat(tpc.getExpressionSuffix()).isEqualTo("}");
|
||||
assertThat(tpc.isTemplate()).isTrue();
|
||||
|
||||
ParserContext pc = ParserContext.TEMPLATE_EXPRESSION;
|
||||
assertEquals("#{", pc.getExpressionPrefix());
|
||||
assertEquals("}", pc.getExpressionSuffix());
|
||||
assertTrue(pc.isTemplate());
|
||||
assertThat(pc.getExpressionPrefix()).isEqualTo("#{");
|
||||
assertThat(pc.getExpressionSuffix()).isEqualTo("}");
|
||||
assertThat(pc.isTemplate()).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Andy Wilkinson
|
||||
@@ -32,13 +32,13 @@ public class FormatHelperTests {
|
||||
@Test
|
||||
public void formatMethodWithSingleArgumentForMessage() {
|
||||
String message = FormatHelper.formatMethodForMessage("foo", Arrays.asList(TypeDescriptor.forObject("a string")));
|
||||
assertEquals("foo(java.lang.String)", message);
|
||||
assertThat(message).isEqualTo("foo(java.lang.String)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void formatMethodWithMultipleArgumentsForMessage() {
|
||||
String message = FormatHelper.formatMethodForMessage("foo", Arrays.asList(TypeDescriptor.forObject("a string"), TypeDescriptor.forObject(Integer.valueOf(5))));
|
||||
assertEquals("foo(java.lang.String,java.lang.Integer)", message);
|
||||
assertThat(message).isEqualTo("foo(java.lang.String,java.lang.Integer)");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,9 +30,9 @@ import org.springframework.expression.spel.SpelEvaluationException;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
import org.springframework.expression.spel.support.StandardTypeConverter;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Unit tests for SpEL's plus operator.
|
||||
@@ -70,9 +70,9 @@ public class OpPlusTests {
|
||||
OpPlus o = new OpPlus(-1, -1, realLiteral);
|
||||
TypedValue value = o.getValueInternal(expressionState);
|
||||
|
||||
assertEquals(Double.class, value.getTypeDescriptor().getObjectType());
|
||||
assertEquals(Double.class, value.getTypeDescriptor().getType());
|
||||
assertEquals(realLiteral.getLiteralValue().getValue(), value.getValue());
|
||||
assertThat(value.getTypeDescriptor().getObjectType()).isEqualTo(Double.class);
|
||||
assertThat(value.getTypeDescriptor().getType()).isEqualTo(Double.class);
|
||||
assertThat(value.getValue()).isEqualTo(realLiteral.getLiteralValue().getValue());
|
||||
}
|
||||
|
||||
{
|
||||
@@ -80,9 +80,9 @@ public class OpPlusTests {
|
||||
OpPlus o = new OpPlus(-1, -1, intLiteral);
|
||||
TypedValue value = o.getValueInternal(expressionState);
|
||||
|
||||
assertEquals(Integer.class, value.getTypeDescriptor().getObjectType());
|
||||
assertEquals(Integer.class, value.getTypeDescriptor().getType());
|
||||
assertEquals(intLiteral.getLiteralValue().getValue(), value.getValue());
|
||||
assertThat(value.getTypeDescriptor().getObjectType()).isEqualTo(Integer.class);
|
||||
assertThat(value.getTypeDescriptor().getType()).isEqualTo(Integer.class);
|
||||
assertThat(value.getValue()).isEqualTo(intLiteral.getLiteralValue().getValue());
|
||||
}
|
||||
|
||||
{
|
||||
@@ -90,9 +90,9 @@ public class OpPlusTests {
|
||||
OpPlus o = new OpPlus(-1, -1, longLiteral);
|
||||
TypedValue value = o.getValueInternal(expressionState);
|
||||
|
||||
assertEquals(Long.class, value.getTypeDescriptor().getObjectType());
|
||||
assertEquals(Long.class, value.getTypeDescriptor().getType());
|
||||
assertEquals(longLiteral.getLiteralValue().getValue(), value.getValue());
|
||||
assertThat(value.getTypeDescriptor().getObjectType()).isEqualTo(Long.class);
|
||||
assertThat(value.getTypeDescriptor().getType()).isEqualTo(Long.class);
|
||||
assertThat(value.getValue()).isEqualTo(longLiteral.getLiteralValue().getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,9 +106,9 @@ public class OpPlusTests {
|
||||
OpPlus o = new OpPlus(-1, -1, n1, n2);
|
||||
TypedValue value = o.getValueInternal(expressionState);
|
||||
|
||||
assertEquals(Double.class, value.getTypeDescriptor().getObjectType());
|
||||
assertEquals(Double.class, value.getTypeDescriptor().getType());
|
||||
assertEquals(Double.valueOf(123.0 + 456.0), value.getValue());
|
||||
assertThat(value.getTypeDescriptor().getObjectType()).isEqualTo(Double.class);
|
||||
assertThat(value.getTypeDescriptor().getType()).isEqualTo(Double.class);
|
||||
assertThat(value.getValue()).isEqualTo(Double.valueOf(123.0 + 456.0));
|
||||
}
|
||||
|
||||
{
|
||||
@@ -117,9 +117,9 @@ public class OpPlusTests {
|
||||
OpPlus o = new OpPlus(-1, -1, n1, n2);
|
||||
TypedValue value = o.getValueInternal(expressionState);
|
||||
|
||||
assertEquals(Long.class, value.getTypeDescriptor().getObjectType());
|
||||
assertEquals(Long.class, value.getTypeDescriptor().getType());
|
||||
assertEquals(Long.valueOf(123L + 456L), value.getValue());
|
||||
assertThat(value.getTypeDescriptor().getObjectType()).isEqualTo(Long.class);
|
||||
assertThat(value.getTypeDescriptor().getType()).isEqualTo(Long.class);
|
||||
assertThat(value.getValue()).isEqualTo(Long.valueOf(123L + 456L));
|
||||
}
|
||||
|
||||
{
|
||||
@@ -128,9 +128,9 @@ public class OpPlusTests {
|
||||
OpPlus o = new OpPlus(-1, -1, n1, n2);
|
||||
TypedValue value = o.getValueInternal(expressionState);
|
||||
|
||||
assertEquals(Integer.class, value.getTypeDescriptor().getObjectType());
|
||||
assertEquals(Integer.class, value.getTypeDescriptor().getType());
|
||||
assertEquals(Integer.valueOf(123 + 456), value.getValue());
|
||||
assertThat(value.getTypeDescriptor().getObjectType()).isEqualTo(Integer.class);
|
||||
assertThat(value.getTypeDescriptor().getType()).isEqualTo(Integer.class);
|
||||
assertThat(value.getValue()).isEqualTo(Integer.valueOf(123 + 456));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,9 +143,9 @@ public class OpPlusTests {
|
||||
OpPlus o = new OpPlus(-1, -1, n1, n2);
|
||||
TypedValue value = o.getValueInternal(expressionState);
|
||||
|
||||
assertEquals(String.class, value.getTypeDescriptor().getObjectType());
|
||||
assertEquals(String.class, value.getTypeDescriptor().getType());
|
||||
assertEquals("foobar", value.getValue());
|
||||
assertThat(value.getTypeDescriptor().getObjectType()).isEqualTo(String.class);
|
||||
assertThat(value.getTypeDescriptor().getType()).isEqualTo(String.class);
|
||||
assertThat(value.getValue()).isEqualTo("foobar");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -157,9 +157,9 @@ public class OpPlusTests {
|
||||
OpPlus o = new OpPlus(-1, -1, n1, n2);
|
||||
TypedValue value = o.getValueInternal(expressionState);
|
||||
|
||||
assertEquals(String.class, value.getTypeDescriptor().getObjectType());
|
||||
assertEquals(String.class, value.getTypeDescriptor().getType());
|
||||
assertEquals("number is 123", value.getValue());
|
||||
assertThat(value.getTypeDescriptor().getObjectType()).isEqualTo(String.class);
|
||||
assertThat(value.getTypeDescriptor().getType()).isEqualTo(String.class);
|
||||
assertThat(value.getValue()).isEqualTo("number is 123");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -171,9 +171,9 @@ public class OpPlusTests {
|
||||
OpPlus o = new OpPlus(-1, -1, n1, n2);
|
||||
TypedValue value = o.getValueInternal(expressionState);
|
||||
|
||||
assertEquals(String.class, value.getTypeDescriptor().getObjectType());
|
||||
assertEquals(String.class, value.getTypeDescriptor().getType());
|
||||
assertEquals("123 is a number", value.getValue());
|
||||
assertThat(value.getTypeDescriptor().getObjectType()).isEqualTo(String.class);
|
||||
assertThat(value.getTypeDescriptor().getType()).isEqualTo(String.class);
|
||||
assertThat(value.getValue()).isEqualTo("123 is a number");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -188,9 +188,9 @@ public class OpPlusTests {
|
||||
OpPlus o = new OpPlus(-1, -1, var, n2);
|
||||
TypedValue value = o.getValueInternal(expressionState);
|
||||
|
||||
assertEquals(String.class, value.getTypeDescriptor().getObjectType());
|
||||
assertEquals(String.class, value.getTypeDescriptor().getType());
|
||||
assertEquals(time + " is now", value.getValue());
|
||||
assertThat(value.getTypeDescriptor().getObjectType()).isEqualTo(String.class);
|
||||
assertThat(value.getTypeDescriptor().getType()).isEqualTo(String.class);
|
||||
assertThat(value.getValue()).isEqualTo((time + " is now"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -213,9 +213,9 @@ public class OpPlusTests {
|
||||
OpPlus o = new OpPlus(-1, -1, var, n2);
|
||||
TypedValue value = o.getValueInternal(expressionState);
|
||||
|
||||
assertEquals(String.class, value.getTypeDescriptor().getObjectType());
|
||||
assertEquals(String.class, value.getTypeDescriptor().getType());
|
||||
assertEquals(format.format(time) + " is now", value.getValue());
|
||||
assertThat(value.getTypeDescriptor().getObjectType()).isEqualTo(String.class);
|
||||
assertThat(value.getTypeDescriptor().getType()).isEqualTo(String.class);
|
||||
assertThat(value.getValue()).isEqualTo((format.format(time) + " is now"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.junit.Test;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -45,7 +45,7 @@ public class PropertiesConversionSpelTests {
|
||||
StandardEvaluationContext context = new StandardEvaluationContext();
|
||||
context.setVariable("props", props);
|
||||
String result = expression.getValue(context, new TestBean(), String.class);
|
||||
assertEquals("123", result);
|
||||
assertThat(result).isEqualTo("123");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -58,7 +58,7 @@ public class PropertiesConversionSpelTests {
|
||||
StandardEvaluationContext context = new StandardEvaluationContext();
|
||||
context.setVariable("props", map);
|
||||
String result = expression.getValue(context, new TestBean(), String.class);
|
||||
assertEquals("123", result);
|
||||
assertThat(result).isEqualTo("123");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -72,7 +72,7 @@ public class PropertiesConversionSpelTests {
|
||||
StandardEvaluationContext context = new StandardEvaluationContext();
|
||||
context.setVariable("props", map);
|
||||
String result = expression.getValue(context, new TestBean(), String.class);
|
||||
assertEquals("1null3", result);
|
||||
assertThat(result).isEqualTo("1null3");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,7 +85,7 @@ public class PropertiesConversionSpelTests {
|
||||
StandardEvaluationContext context = new StandardEvaluationContext();
|
||||
context.setVariable("props", map);
|
||||
String result = expression.getValue(context, new TestBean(), String.class);
|
||||
assertEquals("1null3", result);
|
||||
assertThat(result).isEqualTo("1null3");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -31,11 +31,6 @@ import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Andy Clement
|
||||
@@ -47,11 +42,11 @@ public class SpelParserTests {
|
||||
public void theMostBasic() {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
SpelExpression expr = parser.parseRaw("2");
|
||||
assertNotNull(expr);
|
||||
assertNotNull(expr.getAST());
|
||||
assertEquals(2, expr.getValue());
|
||||
assertEquals(Integer.class, expr.getValueType());
|
||||
assertEquals(2, expr.getAST().getValue(null));
|
||||
assertThat(expr).isNotNull();
|
||||
assertThat(expr.getAST()).isNotNull();
|
||||
assertThat(expr.getValue()).isEqualTo(2);
|
||||
assertThat(expr.getValueType()).isEqualTo(Integer.class);
|
||||
assertThat(expr.getAST().getValue(null)).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -59,61 +54,61 @@ public class SpelParserTests {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
EvaluationContext ctx = new StandardEvaluationContext();
|
||||
Class<?> c = parser.parseRaw("2").getValueType();
|
||||
assertEquals(Integer.class, c);
|
||||
assertThat(c).isEqualTo(Integer.class);
|
||||
c = parser.parseRaw("12").getValueType(ctx);
|
||||
assertEquals(Integer.class, c);
|
||||
assertThat(c).isEqualTo(Integer.class);
|
||||
c = parser.parseRaw("null").getValueType();
|
||||
assertNull(c);
|
||||
assertThat(c).isNull();
|
||||
c = parser.parseRaw("null").getValueType(ctx);
|
||||
assertNull(c);
|
||||
assertThat(c).isNull();
|
||||
Object o = parser.parseRaw("null").getValue(ctx, Integer.class);
|
||||
assertNull(o);
|
||||
assertThat(o).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whitespace() {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
SpelExpression expr = parser.parseRaw("2 + 3");
|
||||
assertEquals(5, expr.getValue());
|
||||
assertThat(expr.getValue()).isEqualTo(5);
|
||||
expr = parser.parseRaw("2 + 3");
|
||||
assertEquals(5, expr.getValue());
|
||||
assertThat(expr.getValue()).isEqualTo(5);
|
||||
expr = parser.parseRaw("2\n+\t3");
|
||||
assertEquals(5, expr.getValue());
|
||||
assertThat(expr.getValue()).isEqualTo(5);
|
||||
expr = parser.parseRaw("2\r\n+\t3");
|
||||
assertEquals(5, expr.getValue());
|
||||
assertThat(expr.getValue()).isEqualTo(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void arithmeticPlus1() {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
SpelExpression expr = parser.parseRaw("2+2");
|
||||
assertNotNull(expr);
|
||||
assertNotNull(expr.getAST());
|
||||
assertEquals(4, expr.getValue());
|
||||
assertThat(expr).isNotNull();
|
||||
assertThat(expr.getAST()).isNotNull();
|
||||
assertThat(expr.getValue()).isEqualTo(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void arithmeticPlus2() {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
SpelExpression expr = parser.parseRaw("37+41");
|
||||
assertEquals(78, expr.getValue());
|
||||
assertThat(expr.getValue()).isEqualTo(78);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void arithmeticMultiply1() {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
SpelExpression expr = parser.parseRaw("2*3");
|
||||
assertNotNull(expr);
|
||||
assertNotNull(expr.getAST());
|
||||
assertThat(expr).isNotNull();
|
||||
assertThat(expr.getAST()).isNotNull();
|
||||
// printAst(expr.getAST(),0);
|
||||
assertEquals(6, expr.getValue());
|
||||
assertThat(expr.getValue()).isEqualTo(6);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void arithmeticPrecedence1() {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
SpelExpression expr = parser.parseRaw("2*3+5");
|
||||
assertEquals(11, expr.getValue());
|
||||
assertThat(expr.getValue()).isEqualTo(11);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -169,89 +164,89 @@ public class SpelParserTests {
|
||||
public void arithmeticPrecedence2() {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
SpelExpression expr = parser.parseRaw("2+3*5");
|
||||
assertEquals(17, expr.getValue());
|
||||
assertThat(expr.getValue()).isEqualTo(17);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void arithmeticPrecedence3() {
|
||||
SpelExpression expr = new SpelExpressionParser().parseRaw("3+10/2");
|
||||
assertEquals(8, expr.getValue());
|
||||
assertThat(expr.getValue()).isEqualTo(8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void arithmeticPrecedence4() {
|
||||
SpelExpression expr = new SpelExpressionParser().parseRaw("10/2+3");
|
||||
assertEquals(8, expr.getValue());
|
||||
assertThat(expr.getValue()).isEqualTo(8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void arithmeticPrecedence5() {
|
||||
SpelExpression expr = new SpelExpressionParser().parseRaw("(4+10)/2");
|
||||
assertEquals(7, expr.getValue());
|
||||
assertThat(expr.getValue()).isEqualTo(7);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void arithmeticPrecedence6() {
|
||||
SpelExpression expr = new SpelExpressionParser().parseRaw("(3+2)*2");
|
||||
assertEquals(10, expr.getValue());
|
||||
assertThat(expr.getValue()).isEqualTo(10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void booleanOperators() {
|
||||
SpelExpression expr = new SpelExpressionParser().parseRaw("true");
|
||||
assertEquals(Boolean.TRUE, expr.getValue(Boolean.class));
|
||||
assertThat(expr.getValue(Boolean.class)).isEqualTo(Boolean.TRUE);
|
||||
expr = new SpelExpressionParser().parseRaw("false");
|
||||
assertEquals(Boolean.FALSE, expr.getValue(Boolean.class));
|
||||
assertThat(expr.getValue(Boolean.class)).isEqualTo(Boolean.FALSE);
|
||||
expr = new SpelExpressionParser().parseRaw("false and false");
|
||||
assertEquals(Boolean.FALSE, expr.getValue(Boolean.class));
|
||||
assertThat(expr.getValue(Boolean.class)).isEqualTo(Boolean.FALSE);
|
||||
expr = new SpelExpressionParser().parseRaw("true and (true or false)");
|
||||
assertEquals(Boolean.TRUE, expr.getValue(Boolean.class));
|
||||
assertThat(expr.getValue(Boolean.class)).isEqualTo(Boolean.TRUE);
|
||||
expr = new SpelExpressionParser().parseRaw("true and true or false");
|
||||
assertEquals(Boolean.TRUE, expr.getValue(Boolean.class));
|
||||
assertThat(expr.getValue(Boolean.class)).isEqualTo(Boolean.TRUE);
|
||||
expr = new SpelExpressionParser().parseRaw("!true");
|
||||
assertEquals(Boolean.FALSE, expr.getValue(Boolean.class));
|
||||
assertThat(expr.getValue(Boolean.class)).isEqualTo(Boolean.FALSE);
|
||||
expr = new SpelExpressionParser().parseRaw("!(false or true)");
|
||||
assertEquals(Boolean.FALSE, expr.getValue(Boolean.class));
|
||||
assertThat(expr.getValue(Boolean.class)).isEqualTo(Boolean.FALSE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void booleanOperators_symbolic_spr9614() {
|
||||
SpelExpression expr = new SpelExpressionParser().parseRaw("true");
|
||||
assertEquals(Boolean.TRUE, expr.getValue(Boolean.class));
|
||||
assertThat(expr.getValue(Boolean.class)).isEqualTo(Boolean.TRUE);
|
||||
expr = new SpelExpressionParser().parseRaw("false");
|
||||
assertEquals(Boolean.FALSE, expr.getValue(Boolean.class));
|
||||
assertThat(expr.getValue(Boolean.class)).isEqualTo(Boolean.FALSE);
|
||||
expr = new SpelExpressionParser().parseRaw("false && false");
|
||||
assertEquals(Boolean.FALSE, expr.getValue(Boolean.class));
|
||||
assertThat(expr.getValue(Boolean.class)).isEqualTo(Boolean.FALSE);
|
||||
expr = new SpelExpressionParser().parseRaw("true && (true || false)");
|
||||
assertEquals(Boolean.TRUE, expr.getValue(Boolean.class));
|
||||
assertThat(expr.getValue(Boolean.class)).isEqualTo(Boolean.TRUE);
|
||||
expr = new SpelExpressionParser().parseRaw("true && true || false");
|
||||
assertEquals(Boolean.TRUE, expr.getValue(Boolean.class));
|
||||
assertThat(expr.getValue(Boolean.class)).isEqualTo(Boolean.TRUE);
|
||||
expr = new SpelExpressionParser().parseRaw("!true");
|
||||
assertEquals(Boolean.FALSE, expr.getValue(Boolean.class));
|
||||
assertThat(expr.getValue(Boolean.class)).isEqualTo(Boolean.FALSE);
|
||||
expr = new SpelExpressionParser().parseRaw("!(false || true)");
|
||||
assertEquals(Boolean.FALSE, expr.getValue(Boolean.class));
|
||||
assertThat(expr.getValue(Boolean.class)).isEqualTo(Boolean.FALSE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stringLiterals() {
|
||||
SpelExpression expr = new SpelExpressionParser().parseRaw("'howdy'");
|
||||
assertEquals("howdy", expr.getValue());
|
||||
assertThat(expr.getValue()).isEqualTo("howdy");
|
||||
expr = new SpelExpressionParser().parseRaw("'hello '' world'");
|
||||
assertEquals("hello ' world", expr.getValue());
|
||||
assertThat(expr.getValue()).isEqualTo("hello ' world");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stringLiterals2() {
|
||||
SpelExpression expr = new SpelExpressionParser().parseRaw("'howdy'.substring(0,2)");
|
||||
assertEquals("ho", expr.getValue());
|
||||
assertThat(expr.getValue()).isEqualTo("ho");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringLiterals_DoubleQuotes_spr9620() {
|
||||
SpelExpression expr = new SpelExpressionParser().parseRaw("\"double quote: \"\".\"");
|
||||
assertEquals("double quote: \".", expr.getValue());
|
||||
assertThat(expr.getValue()).isEqualTo("double quote: \".");
|
||||
expr = new SpelExpressionParser().parseRaw("\"hello \"\" world\"");
|
||||
assertEquals("hello \" world", expr.getValue());
|
||||
assertThat(expr.getValue()).isEqualTo("hello \" world");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -273,72 +268,72 @@ public class SpelParserTests {
|
||||
SpelNode rightOrOperand = operatorOr.getRightOperand();
|
||||
|
||||
// check position for final 'false'
|
||||
assertEquals(17, rightOrOperand.getStartPosition());
|
||||
assertEquals(22, rightOrOperand.getEndPosition());
|
||||
assertThat(rightOrOperand.getStartPosition()).isEqualTo(17);
|
||||
assertThat(rightOrOperand.getEndPosition()).isEqualTo(22);
|
||||
|
||||
// check position for first 'true'
|
||||
assertEquals(0, operatorAnd.getLeftOperand().getStartPosition());
|
||||
assertEquals(4, operatorAnd.getLeftOperand().getEndPosition());
|
||||
assertThat(operatorAnd.getLeftOperand().getStartPosition()).isEqualTo(0);
|
||||
assertThat(operatorAnd.getLeftOperand().getEndPosition()).isEqualTo(4);
|
||||
|
||||
// check position for second 'true'
|
||||
assertEquals(9, operatorAnd.getRightOperand().getStartPosition());
|
||||
assertEquals(13, operatorAnd.getRightOperand().getEndPosition());
|
||||
assertThat(operatorAnd.getRightOperand().getStartPosition()).isEqualTo(9);
|
||||
assertThat(operatorAnd.getRightOperand().getEndPosition()).isEqualTo(13);
|
||||
|
||||
// check position for OperatorAnd
|
||||
assertEquals(5, operatorAnd.getStartPosition());
|
||||
assertEquals(8, operatorAnd.getEndPosition());
|
||||
assertThat(operatorAnd.getStartPosition()).isEqualTo(5);
|
||||
assertThat(operatorAnd.getEndPosition()).isEqualTo(8);
|
||||
|
||||
// check position for OperatorOr
|
||||
assertEquals(14, operatorOr.getStartPosition());
|
||||
assertEquals(16, operatorOr.getEndPosition());
|
||||
assertThat(operatorOr.getStartPosition()).isEqualTo(14);
|
||||
assertThat(operatorOr.getEndPosition()).isEqualTo(16);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tokenKind() {
|
||||
TokenKind tk = TokenKind.NOT;
|
||||
assertFalse(tk.hasPayload());
|
||||
assertEquals("NOT(!)", tk.toString());
|
||||
assertThat(tk.hasPayload()).isFalse();
|
||||
assertThat(tk.toString()).isEqualTo("NOT(!)");
|
||||
|
||||
tk = TokenKind.MINUS;
|
||||
assertFalse(tk.hasPayload());
|
||||
assertEquals("MINUS(-)", tk.toString());
|
||||
assertThat(tk.hasPayload()).isFalse();
|
||||
assertThat(tk.toString()).isEqualTo("MINUS(-)");
|
||||
|
||||
tk = TokenKind.LITERAL_STRING;
|
||||
assertEquals("LITERAL_STRING", tk.toString());
|
||||
assertTrue(tk.hasPayload());
|
||||
assertThat(tk.toString()).isEqualTo("LITERAL_STRING");
|
||||
assertThat(tk.hasPayload()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void token() {
|
||||
Token token = new Token(TokenKind.NOT, 0, 3);
|
||||
assertEquals(TokenKind.NOT, token.kind);
|
||||
assertEquals(0, token.startPos);
|
||||
assertEquals(3, token.endPos);
|
||||
assertEquals("[NOT(!)](0,3)", token.toString());
|
||||
assertThat(token.kind).isEqualTo(TokenKind.NOT);
|
||||
assertThat(token.startPos).isEqualTo(0);
|
||||
assertThat(token.endPos).isEqualTo(3);
|
||||
assertThat(token.toString()).isEqualTo("[NOT(!)](0,3)");
|
||||
|
||||
token = new Token(TokenKind.LITERAL_STRING, "abc".toCharArray(), 0, 3);
|
||||
assertEquals(TokenKind.LITERAL_STRING, token.kind);
|
||||
assertEquals(0, token.startPos);
|
||||
assertEquals(3, token.endPos);
|
||||
assertEquals("[LITERAL_STRING:abc](0,3)", token.toString());
|
||||
assertThat(token.kind).isEqualTo(TokenKind.LITERAL_STRING);
|
||||
assertThat(token.startPos).isEqualTo(0);
|
||||
assertThat(token.endPos).isEqualTo(3);
|
||||
assertThat(token.toString()).isEqualTo("[LITERAL_STRING:abc](0,3)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exceptions() {
|
||||
ExpressionException exprEx = new ExpressionException("test");
|
||||
assertEquals("test", exprEx.getSimpleMessage());
|
||||
assertEquals("test", exprEx.toDetailedString());
|
||||
assertEquals("test", exprEx.getMessage());
|
||||
assertThat(exprEx.getSimpleMessage()).isEqualTo("test");
|
||||
assertThat(exprEx.toDetailedString()).isEqualTo("test");
|
||||
assertThat(exprEx.getMessage()).isEqualTo("test");
|
||||
|
||||
exprEx = new ExpressionException("wibble", "test");
|
||||
assertEquals("test", exprEx.getSimpleMessage());
|
||||
assertEquals("Expression [wibble]: test", exprEx.toDetailedString());
|
||||
assertEquals("Expression [wibble]: test", exprEx.getMessage());
|
||||
assertThat(exprEx.getSimpleMessage()).isEqualTo("test");
|
||||
assertThat(exprEx.toDetailedString()).isEqualTo("Expression [wibble]: test");
|
||||
assertThat(exprEx.getMessage()).isEqualTo("Expression [wibble]: test");
|
||||
|
||||
exprEx = new ExpressionException("wibble", 3, "test");
|
||||
assertEquals("test", exprEx.getSimpleMessage());
|
||||
assertEquals("Expression [wibble] @3: test", exprEx.toDetailedString());
|
||||
assertEquals("Expression [wibble] @3: test", exprEx.getMessage());
|
||||
assertThat(exprEx.getSimpleMessage()).isEqualTo("test");
|
||||
assertThat(exprEx.toDetailedString()).isEqualTo("Expression [wibble] @3: test");
|
||||
assertThat(exprEx.getMessage()).isEqualTo("Expression [wibble] @3: test");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -380,8 +375,8 @@ public class SpelParserTests {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
SpelExpression expr = parser.parseRaw(expression);
|
||||
Object exprVal = expr.getValue();
|
||||
assertEquals(value, exprVal);
|
||||
assertEquals(type, exprVal.getClass());
|
||||
assertThat(exprVal).isEqualTo(value);
|
||||
assertThat(exprVal.getClass()).isEqualTo(type);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new AssertionError(ex.getMessage(), ex);
|
||||
|
||||
@@ -34,13 +34,8 @@ import org.springframework.expression.spel.SpelUtilities;
|
||||
import org.springframework.expression.spel.standard.SpelExpression;
|
||||
import org.springframework.expression.spel.support.ReflectionHelper.ArgumentsMatchKind;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests for reflection helper code.
|
||||
@@ -76,8 +71,8 @@ public class ReflectionHelperTests extends AbstractExpressionTests {
|
||||
// CompoundExpression value:2
|
||||
// IntLiteral value:2
|
||||
// ===> Expression '3+4+5+6+7-2' - AST end
|
||||
assertTrue(s.contains("===> Expression '3+4+5+6+7-2' - AST start"));
|
||||
assertTrue(s.contains(" OpPlus value:((((3 + 4) + 5) + 6) + 7) #children:2"));
|
||||
assertThat(s.contains("===> Expression '3+4+5+6+7-2' - AST start")).isTrue();
|
||||
assertThat(s.contains(" OpPlus value:((((3 + 4) + 5) + 6) + 7) #children:2")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,17 +80,17 @@ public class ReflectionHelperTests extends AbstractExpressionTests {
|
||||
TypedValue tv1 = new TypedValue("hello");
|
||||
TypedValue tv2 = new TypedValue("hello");
|
||||
TypedValue tv3 = new TypedValue("bye");
|
||||
assertEquals(String.class, tv1.getTypeDescriptor().getType());
|
||||
assertEquals("TypedValue: 'hello' of [java.lang.String]", tv1.toString());
|
||||
assertEquals(tv1, tv2);
|
||||
assertEquals(tv2, tv1);
|
||||
assertNotEquals(tv1, tv3);
|
||||
assertNotEquals(tv2, tv3);
|
||||
assertNotEquals(tv3, tv1);
|
||||
assertNotEquals(tv3, tv2);
|
||||
assertEquals(tv1.hashCode(), tv2.hashCode());
|
||||
assertNotEquals(tv1.hashCode(), tv3.hashCode());
|
||||
assertNotEquals(tv2.hashCode(), tv3.hashCode());
|
||||
assertThat(tv1.getTypeDescriptor().getType()).isEqualTo(String.class);
|
||||
assertThat(tv1.toString()).isEqualTo("TypedValue: 'hello' of [java.lang.String]");
|
||||
assertThat(tv2).isEqualTo(tv1);
|
||||
assertThat(tv1).isEqualTo(tv2);
|
||||
assertThat(tv3).isNotEqualTo(tv1);
|
||||
assertThat(tv3).isNotEqualTo(tv2);
|
||||
assertThat(tv1).isNotEqualTo(tv3);
|
||||
assertThat(tv2).isNotEqualTo(tv3);
|
||||
assertThat(tv2.hashCode()).isEqualTo(tv1.hashCode());
|
||||
assertThat(tv3.hashCode()).isNotEqualTo((long) tv1.hashCode());
|
||||
assertThat(tv3.hashCode()).isNotEqualTo((long) tv2.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -258,14 +253,14 @@ public class ReflectionHelperTests extends AbstractExpressionTests {
|
||||
Object[] newArray = ReflectionHelper.setupArgumentsForVarargsInvocation(
|
||||
new Class<?>[] {String[].class}, "a", "b", "c");
|
||||
|
||||
assertEquals(1, newArray.length);
|
||||
assertThat(newArray.length).isEqualTo(1);
|
||||
Object firstParam = newArray[0];
|
||||
assertEquals(String.class,firstParam.getClass().getComponentType());
|
||||
assertThat(firstParam.getClass().getComponentType()).isEqualTo(String.class);
|
||||
Object[] firstParamArray = (Object[]) firstParam;
|
||||
assertEquals(3,firstParamArray.length);
|
||||
assertEquals("a",firstParamArray[0]);
|
||||
assertEquals("b",firstParamArray[1]);
|
||||
assertEquals("c",firstParamArray[2]);
|
||||
assertThat(firstParamArray.length).isEqualTo(3);
|
||||
assertThat(firstParamArray[0]).isEqualTo("a");
|
||||
assertThat(firstParamArray[1]).isEqualTo("b");
|
||||
assertThat(firstParamArray[2]).isEqualTo("c");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -274,19 +269,21 @@ public class ReflectionHelperTests extends AbstractExpressionTests {
|
||||
Tester t = new Tester();
|
||||
t.setProperty("hello");
|
||||
EvaluationContext ctx = new StandardEvaluationContext(t);
|
||||
assertTrue(rpa.canRead(ctx, t, "property"));
|
||||
assertEquals("hello",rpa.read(ctx, t, "property").getValue());
|
||||
assertEquals("hello",rpa.read(ctx, t, "property").getValue()); // cached accessor used
|
||||
assertThat(rpa.canRead(ctx, t, "property")).isTrue();
|
||||
assertThat(rpa.read(ctx, t, "property").getValue()).isEqualTo("hello");
|
||||
// cached accessor used
|
||||
assertThat(rpa.read(ctx, t, "property").getValue()).isEqualTo("hello");
|
||||
|
||||
assertTrue(rpa.canRead(ctx, t, "field"));
|
||||
assertEquals(3,rpa.read(ctx, t, "field").getValue());
|
||||
assertEquals(3,rpa.read(ctx, t, "field").getValue()); // cached accessor used
|
||||
assertThat(rpa.canRead(ctx, t, "field")).isTrue();
|
||||
assertThat(rpa.read(ctx, t, "field").getValue()).isEqualTo(3);
|
||||
// cached accessor used
|
||||
assertThat(rpa.read(ctx, t, "field").getValue()).isEqualTo(3);
|
||||
|
||||
assertTrue(rpa.canWrite(ctx, t, "property"));
|
||||
assertThat(rpa.canWrite(ctx, t, "property")).isTrue();
|
||||
rpa.write(ctx, t, "property", "goodbye");
|
||||
rpa.write(ctx, t, "property", "goodbye"); // cached accessor used
|
||||
|
||||
assertTrue(rpa.canWrite(ctx, t, "field"));
|
||||
assertThat(rpa.canWrite(ctx, t, "field")).isTrue();
|
||||
rpa.write(ctx, t, "field", 12);
|
||||
rpa.write(ctx, t, "field", 12);
|
||||
|
||||
@@ -294,37 +291,37 @@ public class ReflectionHelperTests extends AbstractExpressionTests {
|
||||
// of populating type descriptor cache
|
||||
rpa.write(ctx, t, "field2", 3);
|
||||
rpa.write(ctx, t, "property2", "doodoo");
|
||||
assertEquals(3,rpa.read(ctx, t, "field2").getValue());
|
||||
assertThat(rpa.read(ctx, t, "field2").getValue()).isEqualTo(3);
|
||||
|
||||
// Attempted read as first activity on this field and property (no canRead before them)
|
||||
assertEquals(0,rpa.read(ctx, t, "field3").getValue());
|
||||
assertEquals("doodoo",rpa.read(ctx, t, "property3").getValue());
|
||||
assertThat(rpa.read(ctx, t, "field3").getValue()).isEqualTo(0);
|
||||
assertThat(rpa.read(ctx, t, "property3").getValue()).isEqualTo("doodoo");
|
||||
|
||||
// Access through is method
|
||||
assertEquals(0,rpa .read(ctx, t, "field3").getValue());
|
||||
assertEquals(false,rpa.read(ctx, t, "property4").getValue());
|
||||
assertTrue(rpa.canRead(ctx, t, "property4"));
|
||||
assertThat(rpa .read(ctx, t, "field3").getValue()).isEqualTo(0);
|
||||
assertThat(rpa.read(ctx, t, "property4").getValue()).isEqualTo(false);
|
||||
assertThat(rpa.canRead(ctx, t, "property4")).isTrue();
|
||||
|
||||
// repro SPR-9123, ReflectivePropertyAccessor JavaBean property names compliance tests
|
||||
assertEquals("iD",rpa.read(ctx, t, "iD").getValue());
|
||||
assertTrue(rpa.canRead(ctx, t, "iD"));
|
||||
assertEquals("id",rpa.read(ctx, t, "id").getValue());
|
||||
assertTrue(rpa.canRead(ctx, t, "id"));
|
||||
assertEquals("ID",rpa.read(ctx, t, "ID").getValue());
|
||||
assertTrue(rpa.canRead(ctx, t, "ID"));
|
||||
assertThat(rpa.read(ctx, t, "iD").getValue()).isEqualTo("iD");
|
||||
assertThat(rpa.canRead(ctx, t, "iD")).isTrue();
|
||||
assertThat(rpa.read(ctx, t, "id").getValue()).isEqualTo("id");
|
||||
assertThat(rpa.canRead(ctx, t, "id")).isTrue();
|
||||
assertThat(rpa.read(ctx, t, "ID").getValue()).isEqualTo("ID");
|
||||
assertThat(rpa.canRead(ctx, t, "ID")).isTrue();
|
||||
// note: "Id" is not a valid JavaBean name, nevertheless it is treated as "id"
|
||||
assertEquals("id",rpa.read(ctx, t, "Id").getValue());
|
||||
assertTrue(rpa.canRead(ctx, t, "Id"));
|
||||
assertThat(rpa.read(ctx, t, "Id").getValue()).isEqualTo("id");
|
||||
assertThat(rpa.canRead(ctx, t, "Id")).isTrue();
|
||||
|
||||
// repro SPR-10994
|
||||
assertEquals("xyZ",rpa.read(ctx, t, "xyZ").getValue());
|
||||
assertTrue(rpa.canRead(ctx, t, "xyZ"));
|
||||
assertEquals("xY",rpa.read(ctx, t, "xY").getValue());
|
||||
assertTrue(rpa.canRead(ctx, t, "xY"));
|
||||
assertThat(rpa.read(ctx, t, "xyZ").getValue()).isEqualTo("xyZ");
|
||||
assertThat(rpa.canRead(ctx, t, "xyZ")).isTrue();
|
||||
assertThat(rpa.read(ctx, t, "xY").getValue()).isEqualTo("xY");
|
||||
assertThat(rpa.canRead(ctx, t, "xY")).isTrue();
|
||||
|
||||
// SPR-10122, ReflectivePropertyAccessor JavaBean property names compliance tests - setters
|
||||
rpa.write(ctx, t, "pEBS", "Test String");
|
||||
assertEquals("Test String",rpa.read(ctx, t, "pEBS").getValue());
|
||||
assertThat(rpa.read(ctx, t, "pEBS").getValue()).isEqualTo("Test String");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -333,33 +330,36 @@ public class ReflectionHelperTests extends AbstractExpressionTests {
|
||||
Tester tester = new Tester();
|
||||
tester.setProperty("hello");
|
||||
EvaluationContext ctx = new StandardEvaluationContext(tester);
|
||||
assertTrue(reflective.canRead(ctx, tester, "property"));
|
||||
assertEquals("hello", reflective.read(ctx, tester, "property").getValue());
|
||||
assertEquals("hello", reflective.read(ctx, tester, "property").getValue()); // cached accessor used
|
||||
assertThat(reflective.canRead(ctx, tester, "property")).isTrue();
|
||||
assertThat(reflective.read(ctx, tester, "property").getValue()).isEqualTo("hello");
|
||||
// cached accessor used
|
||||
assertThat(reflective.read(ctx, tester, "property").getValue()).isEqualTo("hello");
|
||||
|
||||
PropertyAccessor property = reflective.createOptimalAccessor(ctx, tester, "property");
|
||||
assertTrue(property.canRead(ctx, tester, "property"));
|
||||
assertFalse(property.canRead(ctx, tester, "property2"));
|
||||
assertThat(property.canRead(ctx, tester, "property")).isTrue();
|
||||
assertThat(property.canRead(ctx, tester, "property2")).isFalse();
|
||||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
|
||||
property.canWrite(ctx, tester, "property"));
|
||||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
|
||||
property.canWrite(ctx, tester, "property2"));
|
||||
assertEquals("hello",property.read(ctx, tester, "property").getValue());
|
||||
assertEquals("hello",property.read(ctx, tester, "property").getValue()); // cached accessor used
|
||||
assertThat(property.read(ctx, tester, "property").getValue()).isEqualTo("hello");
|
||||
// cached accessor used
|
||||
assertThat(property.read(ctx, tester, "property").getValue()).isEqualTo("hello");
|
||||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
|
||||
property.getSpecificTargetClasses());
|
||||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
|
||||
property.write(ctx, tester, "property", null));
|
||||
|
||||
PropertyAccessor field = reflective.createOptimalAccessor(ctx, tester, "field");
|
||||
assertTrue(field.canRead(ctx, tester, "field"));
|
||||
assertFalse(field.canRead(ctx, tester, "field2"));
|
||||
assertThat(field.canRead(ctx, tester, "field")).isTrue();
|
||||
assertThat(field.canRead(ctx, tester, "field2")).isFalse();
|
||||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
|
||||
field.canWrite(ctx, tester, "field"));
|
||||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
|
||||
field.canWrite(ctx, tester, "field2"));
|
||||
assertEquals(3,field.read(ctx, tester, "field").getValue());
|
||||
assertEquals(3,field.read(ctx, tester, "field").getValue()); // cached accessor used
|
||||
assertThat(field.read(ctx, tester, "field").getValue()).isEqualTo(3);
|
||||
// cached accessor used
|
||||
assertThat(field.read(ctx, tester, "field").getValue()).isEqualTo(3);
|
||||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
|
||||
field.getSpecificTargetClasses());
|
||||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
|
||||
@@ -373,20 +373,20 @@ public class ReflectionHelperTests extends AbstractExpressionTests {
|
||||
private void checkMatch(Class<?>[] inputTypes, Class<?>[] expectedTypes, StandardTypeConverter typeConverter, ArgumentsMatchKind expectedMatchKind) {
|
||||
ReflectionHelper.ArgumentsMatchInfo matchInfo = ReflectionHelper.compareArguments(getTypeDescriptors(expectedTypes), getTypeDescriptors(inputTypes), typeConverter);
|
||||
if (expectedMatchKind == null) {
|
||||
assertNull("Did not expect them to match in any way", matchInfo);
|
||||
assertThat(matchInfo).as("Did not expect them to match in any way").isNull();
|
||||
}
|
||||
else {
|
||||
assertNotNull("Should not be a null match", matchInfo);
|
||||
assertThat(matchInfo).as("Should not be a null match").isNotNull();
|
||||
}
|
||||
|
||||
if (expectedMatchKind == ArgumentsMatchKind.EXACT) {
|
||||
assertTrue(matchInfo.isExactMatch());
|
||||
assertThat(matchInfo.isExactMatch()).isTrue();
|
||||
}
|
||||
else if (expectedMatchKind == ArgumentsMatchKind.CLOSE) {
|
||||
assertTrue(matchInfo.isCloseMatch());
|
||||
assertThat(matchInfo.isCloseMatch()).isTrue();
|
||||
}
|
||||
else if (expectedMatchKind == ArgumentsMatchKind.REQUIRES_CONVERSION) {
|
||||
assertTrue("expected to be a match requiring conversion, but was " + matchInfo, matchInfo.isMatchRequiringConversion());
|
||||
assertThat(matchInfo.isMatchRequiringConversion()).as("expected to be a match requiring conversion, but was " + matchInfo).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,32 +396,32 @@ public class ReflectionHelperTests extends AbstractExpressionTests {
|
||||
private void checkMatch2(Class<?>[] inputTypes, Class<?>[] expectedTypes, StandardTypeConverter typeConverter, ArgumentsMatchKind expectedMatchKind) {
|
||||
ReflectionHelper.ArgumentsMatchInfo matchInfo = ReflectionHelper.compareArgumentsVarargs(getTypeDescriptors(expectedTypes), getTypeDescriptors(inputTypes), typeConverter);
|
||||
if (expectedMatchKind == null) {
|
||||
assertNull("Did not expect them to match in any way: " + matchInfo, matchInfo);
|
||||
assertThat(matchInfo).as("Did not expect them to match in any way: " + matchInfo).isNull();
|
||||
}
|
||||
else {
|
||||
assertNotNull("Should not be a null match", matchInfo);
|
||||
assertThat(matchInfo).as("Should not be a null match").isNotNull();
|
||||
}
|
||||
|
||||
if (expectedMatchKind == ArgumentsMatchKind.EXACT) {
|
||||
assertTrue(matchInfo.isExactMatch());
|
||||
assertThat(matchInfo.isExactMatch()).isTrue();
|
||||
}
|
||||
else if (expectedMatchKind == ArgumentsMatchKind.CLOSE) {
|
||||
assertTrue(matchInfo.isCloseMatch());
|
||||
assertThat(matchInfo.isCloseMatch()).isTrue();
|
||||
}
|
||||
else if (expectedMatchKind == ArgumentsMatchKind.REQUIRES_CONVERSION) {
|
||||
assertTrue("expected to be a match requiring conversion, but was " + matchInfo, matchInfo.isMatchRequiringConversion());
|
||||
assertThat(matchInfo.isMatchRequiringConversion()).as("expected to be a match requiring conversion, but was " + matchInfo).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkArguments(Object[] args, Object... expected) {
|
||||
assertEquals(expected.length,args.length);
|
||||
assertThat(args.length).isEqualTo(expected.length);
|
||||
for (int i = 0; i < expected.length; i++) {
|
||||
checkArgument(expected[i],args[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkArgument(Object expected, Object actual) {
|
||||
assertEquals(expected,actual);
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
}
|
||||
|
||||
private List<TypeDescriptor> getTypeDescriptors(Class<?>... types) {
|
||||
|
||||
@@ -28,31 +28,29 @@ import org.springframework.expression.TypeComparator;
|
||||
import org.springframework.expression.TypeConverter;
|
||||
import org.springframework.expression.TypeLocator;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class StandardComponentsTests {
|
||||
|
||||
@Test
|
||||
public void testStandardEvaluationContext() {
|
||||
StandardEvaluationContext context = new StandardEvaluationContext();
|
||||
assertNotNull(context.getTypeComparator());
|
||||
assertThat(context.getTypeComparator()).isNotNull();
|
||||
|
||||
TypeComparator tc = new StandardTypeComparator();
|
||||
context.setTypeComparator(tc);
|
||||
assertEquals(tc, context.getTypeComparator());
|
||||
assertThat(context.getTypeComparator()).isEqualTo(tc);
|
||||
|
||||
TypeLocator tl = new StandardTypeLocator();
|
||||
context.setTypeLocator(tl);
|
||||
assertEquals(tl, context.getTypeLocator());
|
||||
assertThat(context.getTypeLocator()).isEqualTo(tl);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStandardOperatorOverloader() throws EvaluationException {
|
||||
OperatorOverloader oo = new StandardOperatorOverloader();
|
||||
assertFalse(oo.overridesOperation(Operation.ADD, null, null));
|
||||
assertThat(oo.overridesOperation(Operation.ADD, null, null)).isFalse();
|
||||
assertThatExceptionOfType(EvaluationException.class).isThrownBy(() ->
|
||||
oo.operate(Operation.ADD, 2, 3));
|
||||
}
|
||||
@@ -61,13 +59,13 @@ public class StandardComponentsTests {
|
||||
public void testStandardTypeLocator() {
|
||||
StandardTypeLocator tl = new StandardTypeLocator();
|
||||
List<String> prefixes = tl.getImportPrefixes();
|
||||
assertEquals(1, prefixes.size());
|
||||
assertThat(prefixes.size()).isEqualTo(1);
|
||||
tl.registerImport("java.util");
|
||||
prefixes = tl.getImportPrefixes();
|
||||
assertEquals(2, prefixes.size());
|
||||
assertThat(prefixes.size()).isEqualTo(2);
|
||||
tl.removeImport("java.util");
|
||||
prefixes = tl.getImportPrefixes();
|
||||
assertEquals(1, prefixes.size());
|
||||
assertThat(prefixes.size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user