SWF-905 fix

This commit is contained in:
Keith Donald
2008-10-08 14:42:24 +00:00
parent 5d178452b9
commit 63af957f7b
5 changed files with 82 additions and 37 deletions

View File

@@ -138,6 +138,39 @@ public class ELExpressionParserTests extends TestCase {
assertEquals(null, e.getValueType(target));
}
public void testGetExpressionString() {
String expressionString = "maximum";
Expression exp = parser.parseExpression(expressionString, null);
assertEquals("maximum", exp.getExpressionString());
}
public void testGetExpressionType() {
String expressionString = "maximum";
Expression exp = parser.parseExpression(expressionString, null);
TestBean context = new TestBean();
assertEquals(int.class, exp.getValueType(context));
}
public void testSetValue() {
String expressionString = "maximum";
Expression exp = parser.parseExpression(expressionString, null);
TestBean context = new TestBean();
exp.setValue(context, new Integer(5));
assertEquals(5, context.getMaximum());
}
public void testSetValueConversionError() {
String expressionString = "maximum";
Expression exp = parser.parseExpression(expressionString, null);
TestBean context = new TestBean();
try {
exp.setValue(context, "bogus");
fail("Should have failed with coersion");
} catch (EvaluationException e) {
}
}
public static class TestBean {
private String value = "foo";
@@ -171,12 +204,12 @@ public class ELExpressionParserTests extends TestCase {
return value;
}
public String encode(String data) {
return "!" + data;
public void setValue(String value) {
this.value = value;
}
public void setValue(String value) {
public String encode(String data) {
return "!" + data;
}
public int getMaximum() {

View File

@@ -156,6 +156,12 @@ public class OgnlExpressionParserTests extends TestCase {
assertEquals("false0", exp.getValue(bean));
}
public void testGetExpressionString() {
String expressionString = "maximum";
Expression exp = parser.parseExpression(expressionString, null);
assertEquals("maximum", exp.getExpressionString());
}
public void testGetValueType() {
String exp = "flag";
Expression e = parser.parseExpression(exp, null);

View File

@@ -1,6 +1,8 @@
package org.springframework.binding.mapping;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import junit.framework.TestCase;
@@ -43,6 +45,29 @@ public class DefaultMapperTests extends TestCase {
}).size());
}
public void testMappingConversion() {
DefaultMapping mapping1 = new DefaultMapping(parser.parseExpression("beep", null), parser.parseExpression(
"beep", null));
mapper.addMapping(mapping1);
Map bean1 = new HashMap();
bean1.put("beep", "en");
TestBean2 bean2 = new TestBean2();
MappingResults results = mapper.map(bean1, bean2);
assertFalse(results.hasErrorResults());
assertEquals(Locale.ENGLISH, bean2.beep);
}
public void testMappingConversionError() {
DefaultMapping mapping1 = new DefaultMapping(parser.parseExpression("boop", null), parser.parseExpression(
"boop", null));
mapper.addMapping(mapping1);
Map bean1 = new HashMap();
bean1.put("boop", "bogus");
TestBean2 bean2 = new TestBean2();
MappingResults results = mapper.map(bean1, bean2);
assertTrue(results.hasErrorResults());
}
public static class TestBean {
private String foo;

View File

@@ -1,25 +0,0 @@
/*
* Copyright 2004-2008 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.binding.mapping;
import junit.framework.TestCase;
public class MappingTests extends TestCase {
public void testMapping() {
}
}