Skip to content

Commit 3bed6cf

Browse files
committed
Activated through rename to *Tests, and added method call interaction tests
Issue: SPR-7831
1 parent 640d8cb commit 3bed6cf

File tree

1 file changed

+51
-32
lines changed

1 file changed

+51
-32
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,17 +16,14 @@
1616

1717
package org.springframework.expression.spel;
1818

19-
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertNotNull;
21-
import static org.junit.Assert.assertTrue;
22-
2319
import java.util.ArrayList;
2420
import java.util.Collection;
2521
import java.util.Collections;
2622
import java.util.List;
2723

2824
import org.junit.Before;
2925
import org.junit.Test;
26+
3027
import org.springframework.core.MethodParameter;
3128
import org.springframework.core.convert.ConversionService;
3229
import org.springframework.core.convert.TypeDescriptor;
@@ -36,14 +33,16 @@
3633
import org.springframework.expression.TypeConverter;
3734
import org.springframework.expression.spel.support.StandardEvaluationContext;
3835

36+
import static org.junit.Assert.*;
37+
3938
/**
4039
* Expression evaluation where the TypeConverter plugged in is the
4140
* {@link org.springframework.core.convert.support.GenericConversionService}.
4241
*
4342
* @author Andy Clement
4443
* @author Dave Syer
4544
*/
46-
public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCase {
45+
public class ExpressionWithConversionTests extends ExpressionTestCase {
4746

4847
private static List<String> listOfString = new ArrayList<String>();
4948
private static TypeDescriptor typeDescriptorForListOfString = null;
@@ -61,8 +60,8 @@ public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCas
6160

6261
@Before
6362
public void setUp() throws Exception {
64-
ExpressionTestsUsingCoreConversionService.typeDescriptorForListOfString = new TypeDescriptor(ExpressionTestsUsingCoreConversionService.class.getDeclaredField("listOfString"));
65-
ExpressionTestsUsingCoreConversionService.typeDescriptorForListOfInteger = new TypeDescriptor(ExpressionTestsUsingCoreConversionService.class.getDeclaredField("listOfInteger"));
63+
ExpressionWithConversionTests.typeDescriptorForListOfString = new TypeDescriptor(ExpressionWithConversionTests.class.getDeclaredField("listOfString"));
64+
ExpressionWithConversionTests.typeDescriptorForListOfInteger = new TypeDescriptor(ExpressionWithConversionTests.class.getDeclaredField("listOfInteger"));
6665
}
6766

6867

@@ -133,45 +132,37 @@ public int sum(Collection<Integer> numbers) {
133132

134133
}
135134

136-
public static class Foo {
137-
138-
private Collection<Foo> foos;
139-
140-
public final String value;
141-
142-
public Foo(String value) {
143-
this.value = value;
144-
}
145-
146-
public void setFoos(Collection<Foo> foos) {
147-
this.foos = foos;
148-
}
149-
150-
public Collection<Foo> getFoos() {
151-
return this.foos;
152-
}
153-
154-
}
155-
156135
@Test
157136
public void testConvert() {
158137
Foo root = new Foo("bar");
159-
StandardEvaluationContext context = new StandardEvaluationContext(root);
160-
161138
Collection<String> foos = Collections.singletonList("baz");
162139

163-
// property access, works
140+
StandardEvaluationContext context = new StandardEvaluationContext(root);
141+
142+
// property access
164143
Expression expression = parser.parseExpression("foos");
165144
expression.setValue(context, foos);
166145
Foo baz = root.getFoos().iterator().next();
167146
assertEquals("baz", baz.value);
168147

169-
// method call, fails (ClassCastException)
148+
// method call
170149
expression = parser.parseExpression("setFoos(#foos)");
171150
context.setVariable("foos", foos);
172151
expression.getValue(context);
173152
baz = root.getFoos().iterator().next();
174153
assertEquals("baz", baz.value);
154+
155+
// method call with result from method call
156+
expression = parser.parseExpression("setFoos(getFoosAsStrings())");
157+
expression.getValue(context);
158+
baz = root.getFoos().iterator().next();
159+
assertEquals("baz", baz.value);
160+
161+
// method call with result from method call
162+
expression = parser.parseExpression("setFoos(getFoosAsObjects())");
163+
expression.getValue(context);
164+
baz = root.getFoos().iterator().next();
165+
assertEquals("baz", baz.value);
175166
}
176167

177168

@@ -193,4 +184,32 @@ public Object convertValue(Object value, TypeDescriptor sourceType, TypeDescript
193184
}
194185
}
195186

187+
188+
public static class Foo {
189+
190+
public final String value;
191+
192+
private Collection<Foo> foos;
193+
194+
public Foo(String value) {
195+
this.value = value;
196+
}
197+
198+
public void setFoos(Collection<Foo> foos) {
199+
this.foos = foos;
200+
}
201+
202+
public Collection<Foo> getFoos() {
203+
return this.foos;
204+
}
205+
206+
public Collection<String> getFoosAsStrings() {
207+
return Collections.singletonList("baz");
208+
}
209+
210+
public Collection<?> getFoosAsObjects() {
211+
return Collections.singletonList("baz");
212+
}
213+
}
214+
196215
}

0 commit comments

Comments
 (0)