Skip to content

Commit 61a8fa0

Browse files
committed
change PlaceOfBirth toString() so round tripping from String > new PlaceOfBirth(String) > String works ok
1 parent 3faf28e commit 61a8fa0

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import junit.framework.Assert;
2323

24-
import org.junit.Ignore;
2524
import org.junit.Test;
2625
import org.springframework.expression.EvaluationException;
2726
import org.springframework.expression.Expression;
@@ -102,7 +101,6 @@ public void testSetListElementValue() {
102101
}
103102

104103
@Test
105-
@Ignore
106104
public void testSetGenericListElementValueTypeCoersion() {
107105
// TODO currently failing since setValue does a getValue and "Wien" string != PlaceOfBirth - check with andy
108106
setValue("placesLivedList[0]", "Wien");
@@ -221,7 +219,7 @@ protected void setValue(String expression, Object value) {
221219
StandardEvaluationContext lContext = TestScenarioCreator.getTestEvaluationContext();
222220
Assert.assertTrue("Expression is not writeable but should be", e.isWritable(lContext));
223221
e.setValue(lContext, value);
224-
Assert.assertEquals("Retrieved value was not equal to set value", value, e.getValue(lContext));
222+
Assert.assertEquals("Retrieved value was not equal to set value", value, e.getValue(lContext,value.getClass()));
225223
} catch (EvaluationException ee) {
226224
ee.printStackTrace();
227225
Assert.fail("Unexpected Exception: " + ee.getMessage());

org.springframework.expression/src/test/java/org/springframework/expression/spel/testresources/PlaceOfBirth.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ public class PlaceOfBirth {
66

77
public String Country;
88

9+
/**
10+
* Keith now has a converter that supports String to X, if X has a ctor that takes a String.
11+
* In order for round tripping to work we need toString() for X to return what it was
12+
* constructed with. This is a bit of a hack because a PlaceOfBirth also encapsulates a
13+
* country - but as it is just a test object, it is ok.
14+
*/
915
@Override
10-
public String toString() {return "PlaceOfBirth("+city+")";}
16+
public String toString() {return city;}
1117

1218
public String getCity() {
1319
return city;

0 commit comments

Comments
 (0)