@ -16,6 +16,8 @@
@@ -16,6 +16,8 @@
package org.springframework.expression.spel ;
import static org.junit.Assert.assertEquals ;
import java.util.ArrayList ;
import java.util.HashMap ;
import java.util.LinkedHashMap ;
@ -49,7 +51,7 @@ import org.springframework.expression.spel.support.StandardTypeLocator;
@@ -49,7 +51,7 @@ import org.springframework.expression.spel.support.StandardTypeLocator;
* @author Andy Clement
* /
public class SpringEL300Tests extends ExpressionTestCase {
@Test
public void testNPE_SPR5661 ( ) {
evaluate ( "joinThreeStrings('a',null,'c')" , "anullc" , String . class ) ;
@ -766,6 +768,48 @@ public class SpringEL300Tests extends ExpressionTestCase {
@@ -766,6 +768,48 @@ public class SpringEL300Tests extends ExpressionTestCase {
ms . put ( "def" , "pqr" ) ;
}
}
static class D {
public String a ;
private D ( String s ) {
a = s ;
}
public String toString ( ) {
return "D(" + a + ")" ;
}
}
@Test
public void testGreaterThanWithNulls_SPR7840 ( ) throws Exception {
List < D > list = new ArrayList < D > ( ) ;
list . add ( new D ( "aaa" ) ) ;
list . add ( new D ( "bbb" ) ) ;
list . add ( new D ( null ) ) ;
list . add ( new D ( "ccc" ) ) ;
list . add ( new D ( null ) ) ;
list . add ( new D ( "zzz" ) ) ;
StandardEvaluationContext ctx = new StandardEvaluationContext ( list ) ;
SpelExpressionParser parser = new SpelExpressionParser ( ) ;
String el1 = "#root.?[a < 'hhh']" ;
SpelExpression exp = parser . parseRaw ( el1 ) ;
Object value = exp . getValue ( ctx ) ;
assertEquals ( "[D(aaa), D(bbb), D(null), D(ccc), D(null)]" , value . toString ( ) ) ;
String el2 = "#root.?[a > 'hhh']" ;
SpelExpression exp2 = parser . parseRaw ( el2 ) ;
Object value2 = exp2 . getValue ( ctx ) ;
assertEquals ( "[D(zzz)]" , value2 . toString ( ) ) ;
// trim out the nulls first
String el3 = "#root.?[a!=null].?[a < 'hhh']" ;
SpelExpression exp3 = parser . parseRaw ( el3 ) ;
Object value3 = exp3 . getValue ( ctx ) ;
assertEquals ( "[D(aaa), D(bbb), D(ccc)]" , value3 . toString ( ) ) ;
}
}