Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
snicoll committed Jan 5, 2024
1 parent 085af10 commit d7cfdc6
Show file tree
Hide file tree
Showing 37 changed files with 435 additions and 427 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void evaluate(String expression, Object expectedValue, Class<?> expectedR
}
assertThat(expectedValue).as("Expression returned null value, but expected '" + expectedValue + "'").isNull();
}
Class<? extends Object> resultType = value.getClass();
Class<?> resultType = value.getClass();
if (expectedValue instanceof String) {
assertThat(AbstractExpressionTests.stringValueOf(value)).as("Did not get expected value for expression '" + expression + "'.").isEqualTo(expectedValue);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,36 +28,36 @@
* @author Andy Clement
* @author Oliver Becker
*/
public class BooleanExpressionTests extends AbstractExpressionTests {
class BooleanExpressionTests extends AbstractExpressionTests {

@Test
public void testBooleanTrue() {
void testBooleanTrue() {
evaluate("true", Boolean.TRUE, Boolean.class);
}

@Test
public void testBooleanFalse() {
void testBooleanFalse() {
evaluate("false", Boolean.FALSE, Boolean.class);
}

@Test
public void testOr() {
void testOr() {
evaluate("false or false", Boolean.FALSE, Boolean.class);
evaluate("false or true", Boolean.TRUE, Boolean.class);
evaluate("true or false", Boolean.TRUE, Boolean.class);
evaluate("true or true", Boolean.TRUE, Boolean.class);
}

@Test
public void testAnd() {
void testAnd() {
evaluate("false and false", Boolean.FALSE, Boolean.class);
evaluate("false and true", Boolean.FALSE, Boolean.class);
evaluate("true and false", Boolean.FALSE, Boolean.class);
evaluate("true and true", Boolean.TRUE, Boolean.class);
}

@Test
public void testNot() {
void testNot() {
evaluate("!false", Boolean.TRUE, Boolean.class);
evaluate("!true", Boolean.FALSE, Boolean.class);

Expand All @@ -66,21 +66,21 @@ public void testNot() {
}

@Test
public void testCombinations01() {
void testCombinations01() {
evaluate("false and false or true", Boolean.TRUE, Boolean.class);
evaluate("true and false or true", Boolean.TRUE, Boolean.class);
evaluate("true and false or false", Boolean.FALSE, Boolean.class);
}

@Test
public void testWritability() {
void testWritability() {
evaluate("true and true", Boolean.TRUE, Boolean.class, false);
evaluate("true or true", Boolean.TRUE, Boolean.class, false);
evaluate("!false", Boolean.TRUE, Boolean.class, false);
}

@Test
public void testBooleanErrors01() {
void testBooleanErrors01() {
evaluateAndCheckError("1.0 or false", SpelMessage.TYPE_CONVERSION_ERROR, 0);
evaluateAndCheckError("false or 39.4", SpelMessage.TYPE_CONVERSION_ERROR, 9);
evaluateAndCheckError("true and 'hello'", SpelMessage.TYPE_CONVERSION_ERROR, 9);
Expand All @@ -90,7 +90,7 @@ public void testBooleanErrors01() {
}

@Test
public void testConvertAndHandleNull() { // SPR-9445
void testConvertAndHandleNull() { // SPR-9445
// without null conversion
evaluateAndCheckError("null or true", SpelMessage.TYPE_CONVERSION_ERROR, 0, "null", "boolean");
evaluateAndCheckError("null and true", SpelMessage.TYPE_CONVERSION_ERROR, 0, "null", "boolean");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,15 +31,15 @@
*
* @author Oliver Becker
*/
public class CachedMethodExecutorTests {
class CachedMethodExecutorTests {

private final ExpressionParser parser = new SpelExpressionParser();

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


@Test
public void testCachedExecutionForParameters() {
void testCachedExecutionForParameters() {
Expression expression = this.parser.parseExpression("echo(#var)");

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

@Test
public void testCachedExecutionForTarget() {
void testCachedExecutionForTarget() {
Expression expression = this.parser.parseExpression("#var.echo(42)");

assertMethodExecution(expression, new RootObject(), "int: 42");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,7 +37,7 @@
* @author Andy Clement
* @author Giovanni Dall'Oglio Risso
*/
public class ComparatorTests {
class ComparatorTests {

@Test
void testPrimitives() throws EvaluationException {
Expand Down Expand Up @@ -126,7 +126,7 @@ void testCanCompare() throws EvaluationException {
}

@Test
public void customComparatorWorksWithEquality() {
void customComparatorWorksWithEquality() {
final StandardEvaluationContext ctx = new StandardEvaluationContext();
ctx.setTypeComparator(customComparator);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,7 +23,6 @@
import org.junit.jupiter.api.Test;

import org.springframework.core.convert.TypeDescriptor;
import org.springframework.expression.AccessException;
import org.springframework.expression.ConstructorExecutor;
import org.springframework.expression.ConstructorResolver;
import org.springframework.expression.EvaluationContext;
Expand All @@ -40,15 +39,15 @@
*
* @author Andy Clement
*/
public class ConstructorInvocationTests extends AbstractExpressionTests {
class ConstructorInvocationTests extends AbstractExpressionTests {

@Test
public void testTypeConstructors() {
void testTypeConstructors() {
evaluate("new String('hello world')", "hello world", String.class);
}

@Test
public void testNonExistentType() {
void testNonExistentType() {
evaluateAndCheckError("new FooBar()", SpelMessage.CONSTRUCTOR_INVOCATION_PROBLEM);
}

Expand Down Expand Up @@ -89,7 +88,7 @@ public Tester(PlaceOfBirth pob) {


@Test
public void testConstructorThrowingException_SPR6760() {
void testConstructorThrowingException_SPR6760() {
// Test ctor on inventor:
// On 1 it will throw an IllegalArgumentException
// On 2 it will throw a RuntimeException
Expand Down Expand Up @@ -151,7 +150,7 @@ public void testConstructorThrowingException_SPR6760() {
}

@Test
public void testAddingConstructorResolvers() {
void testAddingConstructorResolvers() {
StandardEvaluationContext ctx = new StandardEvaluationContext();

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

@Override
public ConstructorExecutor resolve(EvaluationContext context, String typeName,
List<TypeDescriptor> argumentTypes) throws AccessException {
List<TypeDescriptor> argumentTypes) {
throw new UnsupportedOperationException("Auto-generated method stub");
}

}


@Test
public void testVarargsInvocation01() {
void testVarargsInvocation01() {
// Calling 'Fruit(String... strings)'
evaluate("new org.springframework.expression.spel.testresources.Fruit('a','b','c').stringscount()", 3,
Integer.class);
Expand All @@ -200,7 +199,7 @@ public void testVarargsInvocation01() {
}

@Test
public void testVarargsInvocation02() {
void testVarargsInvocation02() {
// Calling 'Fruit(int i, String... strings)' - returns int+length_of_strings
evaluate("new org.springframework.expression.spel.testresources.Fruit(5,'a','b','c').stringscount()", 8,
Integer.class);
Expand All @@ -220,7 +219,7 @@ public void testVarargsInvocation02() {
* the argument in order to satisfy a suitable constructor.
*/
@Test
public void testWidening01() {
void testWidening01() {
// widening of int 3 to double 3 is OK
evaluate("new Double(3)", 3.0d, Double.class);
// widening of int 3 to long 3 is OK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -336,7 +335,7 @@ void customMethodFilter() {
StandardEvaluationContext context = new StandardEvaluationContext();

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

// or simply...
// context.setMethodResolvers(new ArrayList<MethodResolver>());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,7 +24,6 @@

import org.junit.jupiter.api.Test;

import org.springframework.expression.AccessException;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.EvaluationException;
import org.springframework.expression.Expression;
Expand Down Expand Up @@ -60,13 +59,13 @@
*
* @author Andy Clement
*/
public class ExpressionLanguageScenarioTests extends AbstractExpressionTests {
class ExpressionLanguageScenarioTests extends AbstractExpressionTests {

/**
* Scenario: using the standard infrastructure and running simple expression evaluation.
*/
@Test
public void testScenario_UsingStandardInfrastructure() {
void testScenario_UsingStandardInfrastructure() {
try {
// Create a parser
SpelExpressionParser parser = new SpelExpressionParser();
Expand All @@ -89,7 +88,7 @@ public void testScenario_UsingStandardInfrastructure() {
* Scenario: using the standard context but adding your own variables
*/
@Test
public void testScenario_DefiningVariablesThatWillBeAccessibleInExpressions() throws Exception {
void testScenario_DefiningVariablesThatWillBeAccessibleInExpressions() {
// Create a parser
SpelExpressionParser parser = new SpelExpressionParser();
// Use the standard evaluation context
Expand Down Expand Up @@ -124,7 +123,7 @@ static class TestClass {
* Scenario: using your own root context object
*/
@Test
public void testScenario_UsingADifferentRootContextObject() throws Exception {
void testScenario_UsingADifferentRootContextObject() {
// Create a parser
SpelExpressionParser parser = new SpelExpressionParser();
// Use the standard evaluation context
Expand Down Expand Up @@ -170,7 +169,7 @@ public void testScenario_UsingADifferentRootContextObject() throws Exception {
* Scenario: using your own java methods and calling them from the expression
*/
@Test
public void testScenario_RegisteringJavaMethodsAsFunctionsAndCallingThem() throws SecurityException, NoSuchMethodException {
void testScenario_RegisteringJavaMethodsAsFunctionsAndCallingThem() throws SecurityException, NoSuchMethodException {
try {
// Create a parser
SpelExpressionParser parser = new SpelExpressionParser();
Expand All @@ -192,7 +191,7 @@ public void testScenario_RegisteringJavaMethodsAsFunctionsAndCallingThem() throw
* Scenario: looking up your own MethodHandles and calling them from the expression
*/
@Test
public void testScenario_RegisteringJavaMethodsAsMethodHandlesAndCallingThem() throws SecurityException, NoSuchMethodException {
void testScenario_RegisteringJavaMethodsAsMethodHandlesAndCallingThem() throws SecurityException {
try {
// Create a parser
SpelExpressionParser parser = new SpelExpressionParser();
Expand Down Expand Up @@ -231,7 +230,7 @@ public void testScenario_RegisteringJavaMethodsAsMethodHandlesAndCallingThem() t
* Scenario: add a property resolver that will get called in the resolver chain, this one only supports reading.
*/
@Test
public void testScenario_AddingYourOwnPropertyResolvers_1() throws Exception {
void testScenario_AddingYourOwnPropertyResolvers_1() {
// Create a parser
SpelExpressionParser parser = new SpelExpressionParser();
// Use the standard evaluation context
Expand All @@ -247,7 +246,7 @@ public void testScenario_AddingYourOwnPropertyResolvers_1() throws Exception {
}

@Test
public void testScenario_AddingYourOwnPropertyResolvers_2() throws Exception {
void testScenario_AddingYourOwnPropertyResolvers_2() {
// Create a parser
SpelExpressionParser parser = new SpelExpressionParser();
// Use the standard evaluation context
Expand Down Expand Up @@ -287,23 +286,22 @@ public Class<?>[] getSpecificTargetClasses() {
}

@Override
public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException {
public boolean canRead(EvaluationContext context, Object target, String name) {
return propertyMap.containsKey(name);
}

@Override
public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException {
public TypedValue read(EvaluationContext context, Object target, String name) {
return new TypedValue(propertyMap.get(name));
}

@Override
public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException {
public boolean canWrite(EvaluationContext context, Object target, String name) {
return false;
}

@Override
public void write(EvaluationContext context, Object target, String name, Object newValue)
throws AccessException {
public void write(EvaluationContext context, Object target, String name, Object newValue) {
}

}
Expand Down Expand Up @@ -331,22 +329,22 @@ public Class<?>[] getSpecificTargetClasses() {
}

@Override
public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException {
public boolean canRead(EvaluationContext context, Object target, String name) {
return propertyMap.containsKey(name);
}

@Override
public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException {
public TypedValue read(EvaluationContext context, Object target, String name) {
return new TypedValue(propertyMap.get(name));
}

@Override
public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException {
public boolean canWrite(EvaluationContext context, Object target, String name) {
return false;
}

@Override
public void write(EvaluationContext context, Object target, String name, Object newValue) throws AccessException {
public void write(EvaluationContext context, Object target, String name, Object newValue) {
}

}
Expand Down
Loading

0 comments on commit d7cfdc6

Please sign in to comment.