Skip to content

Commit ac9fd00

Browse files
committed
more projection tests - verifying the typedescriptor changes made by Keith
1 parent b5c167b commit ac9fd00

File tree

1 file changed

+59
-1
lines changed

1 file changed

+59
-1
lines changed

org.springframework.expression/src/test/java/org/springframework/expression/spel/SpringEL300Tests.java

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,18 @@
1616

1717
package org.springframework.expression.spel;
1818

19+
import java.util.ArrayList;
1920
import java.util.HashMap;
2021
import java.util.LinkedHashMap;
22+
import java.util.List;
2123
import java.util.Map;
2224
import java.util.Properties;
2325

2426
import junit.framework.Assert;
27+
2528
import org.junit.Ignore;
2629
import org.junit.Test;
27-
30+
import org.springframework.core.convert.TypeDescriptor;
2831
import org.springframework.expression.AccessException;
2932
import org.springframework.expression.BeanResolver;
3033
import org.springframework.expression.EvaluationContext;
@@ -34,6 +37,7 @@
3437
import org.springframework.expression.ParserContext;
3538
import org.springframework.expression.PropertyAccessor;
3639
import org.springframework.expression.TypedValue;
40+
import org.springframework.expression.spel.standard.SpelExpression;
3741
import org.springframework.expression.spel.standard.SpelExpressionParser;
3842
import org.springframework.expression.spel.support.ReflectivePropertyAccessor;
3943
import org.springframework.expression.spel.support.StandardEvaluationContext;
@@ -708,6 +712,60 @@ public void testMapOfMap_SPR7244() throws Exception {
708712
evaluated = exp.getValue(ctx);
709713
Assert.assertEquals("Arthur",evaluated);
710714
}
715+
716+
@Test
717+
public void testProjectionTypeDescriptors_1() throws Exception {
718+
StandardEvaluationContext ctx = new StandardEvaluationContext(new C());
719+
SpelExpressionParser parser = new SpelExpressionParser();
720+
String el1 = "ls.![#this.equals('abc')]";
721+
SpelExpression exp = parser.parseRaw(el1);
722+
List value = (List)exp.getValue(ctx);
723+
// value is list containing [true,false]
724+
Assert.assertEquals(Boolean.class,value.get(0).getClass());
725+
TypeDescriptor evaluated = exp.getValueTypeDescriptor(ctx);
726+
Assert.assertEquals(Boolean.class,evaluated.getElementType());
727+
}
728+
729+
@Test
730+
public void testProjectionTypeDescriptors_2() throws Exception {
731+
StandardEvaluationContext ctx = new StandardEvaluationContext(new C());
732+
SpelExpressionParser parser = new SpelExpressionParser();
733+
String el1 = "as.![#this.equals('abc')]";
734+
SpelExpression exp = parser.parseRaw(el1);
735+
Object[] value = (Object[])exp.getValue(ctx);
736+
// value is array containing [true,false]
737+
Assert.assertEquals(Boolean.class,value[0].getClass());
738+
TypeDescriptor evaluated = exp.getValueTypeDescriptor(ctx);
739+
Assert.assertEquals(Boolean.class,evaluated.getElementType());
740+
}
741+
742+
@Test
743+
public void testProjectionTypeDescriptors_3() throws Exception {
744+
StandardEvaluationContext ctx = new StandardEvaluationContext(new C());
745+
SpelExpressionParser parser = new SpelExpressionParser();
746+
String el1 = "ms.![key.equals('abc')]";
747+
SpelExpression exp = parser.parseRaw(el1);
748+
List value = (List)exp.getValue(ctx);
749+
// value is list containing [true,false]
750+
Assert.assertEquals(Boolean.class,value.get(0).getClass());
751+
TypeDescriptor evaluated = exp.getValueTypeDescriptor(ctx);
752+
Assert.assertEquals(Boolean.class,evaluated.getElementType());
753+
}
754+
755+
static class C {
756+
public List<String> ls;
757+
public String[] as;
758+
public Map<String,String> ms;
759+
C() {
760+
ls = new ArrayList<String>();
761+
ls.add("abc");
762+
ls.add("def");
763+
as = new String[]{"abc","def"};
764+
ms = new HashMap<String,String>();
765+
ms.put("abc","xyz");
766+
ms.put("def","pqr");
767+
}
768+
}
711769

712770

713771
}

0 commit comments

Comments
 (0)