Brought spring-binding code to formatting conventions
This commit is contained in:
@@ -28,19 +28,18 @@ import junit.framework.TestCase;
|
||||
* @author Erwin Vervaet
|
||||
*/
|
||||
public class CompositeIteratorTests extends TestCase {
|
||||
|
||||
|
||||
public void testNoIterators() {
|
||||
CompositeIterator it = new CompositeIterator();
|
||||
assertFalse(it.hasNext());
|
||||
try {
|
||||
it.next();
|
||||
fail();
|
||||
}
|
||||
catch (NoSuchElementException e) {
|
||||
} catch (NoSuchElementException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void testSingleIterator() {
|
||||
CompositeIterator it = new CompositeIterator();
|
||||
it.add(Arrays.asList(new String[] { "0", "1" }).iterator());
|
||||
@@ -52,12 +51,11 @@ public class CompositeIteratorTests extends TestCase {
|
||||
try {
|
||||
it.next();
|
||||
fail();
|
||||
}
|
||||
catch (NoSuchElementException e) {
|
||||
} catch (NoSuchElementException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void testMultipleIterators() {
|
||||
CompositeIterator it = new CompositeIterator();
|
||||
it.add(Arrays.asList(new String[] { "0", "1" }).iterator());
|
||||
@@ -71,12 +69,11 @@ public class CompositeIteratorTests extends TestCase {
|
||||
try {
|
||||
it.next();
|
||||
fail();
|
||||
}
|
||||
catch (NoSuchElementException e) {
|
||||
} catch (NoSuchElementException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void testInUse() {
|
||||
List list = Arrays.asList(new String[] { "0", "1" });
|
||||
CompositeIterator it = new CompositeIterator();
|
||||
@@ -85,8 +82,7 @@ public class CompositeIteratorTests extends TestCase {
|
||||
try {
|
||||
it.add(list.iterator());
|
||||
fail();
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
} catch (IllegalStateException e) {
|
||||
// expected
|
||||
}
|
||||
it = new CompositeIterator();
|
||||
@@ -95,12 +91,11 @@ public class CompositeIteratorTests extends TestCase {
|
||||
try {
|
||||
it.add(list.iterator());
|
||||
fail();
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
} catch (IllegalStateException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void testDuplicateIterators() {
|
||||
List list = Arrays.asList(new String[] { "0", "1" });
|
||||
Iterator iterator = list.iterator();
|
||||
@@ -110,8 +105,7 @@ public class CompositeIteratorTests extends TestCase {
|
||||
try {
|
||||
it.add(iterator);
|
||||
fail();
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,42 +25,41 @@ import org.springframework.binding.convert.support.AbstractConverter;
|
||||
* Test case for {@link ConversionExecutor}.
|
||||
*/
|
||||
public class ConversionExecutorTests extends TestCase {
|
||||
|
||||
|
||||
private ConversionExecutor conversionExecutor;
|
||||
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
conversionExecutor = new ConversionExecutor(String.class, Date.class, new TestTextToDate());
|
||||
}
|
||||
|
||||
|
||||
public void testTypeConversion() {
|
||||
assertTrue(conversionExecutor.execute("10-10-2008").getClass().equals(Date.class));
|
||||
}
|
||||
|
||||
|
||||
public void testAssignmentCompatibleTypeConversion() {
|
||||
java.sql.Date date = new java.sql.Date(123L);
|
||||
assertSame(date, conversionExecutor.execute(date));
|
||||
}
|
||||
|
||||
|
||||
public void testConvertNull() {
|
||||
assertNull(conversionExecutor.execute(null));
|
||||
}
|
||||
|
||||
|
||||
public void testIllegalType() {
|
||||
try {
|
||||
conversionExecutor.execute(new StringBuffer());
|
||||
fail();
|
||||
}
|
||||
catch (ConversionException e) {
|
||||
} catch (ConversionException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
private class TestTextToDate extends AbstractConverter {
|
||||
|
||||
|
||||
public Class[] getSourceClasses() {
|
||||
return new Class[] { String.class };
|
||||
}
|
||||
|
||||
|
||||
public Class[] getTargetClasses() {
|
||||
return new Class[] { Date.class };
|
||||
}
|
||||
|
||||
@@ -25,13 +25,13 @@ import org.springframework.binding.convert.ConversionService;
|
||||
|
||||
/**
|
||||
* Test case for the {@link CompositeConversionService}.
|
||||
*
|
||||
*
|
||||
* @author Erwin Vervaet
|
||||
*/
|
||||
public class CompositeConversionServiceTests extends TestCase {
|
||||
|
||||
|
||||
private CompositeConversionService service;
|
||||
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
GenericConversionService first = new GenericConversionService();
|
||||
first.addConverter(new TextToClass());
|
||||
@@ -52,24 +52,21 @@ public class CompositeConversionServiceTests extends TestCase {
|
||||
try {
|
||||
service.getConversionExecutor(String.class, Date.class);
|
||||
fail();
|
||||
}
|
||||
catch (ConversionException e) {
|
||||
} catch (ConversionException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void testGetConversionExecutorByTargetAlias() {
|
||||
assertNotNull(service.getConversionExecutorByTargetAlias(String.class, "boolean"));
|
||||
assertEquals(Boolean.TRUE, service.getConversionExecutorByTargetAlias(String.class, "boolean").execute("ja"));
|
||||
assertNotNull(service.getConversionExecutorByTargetAlias(String.class, "integer"));
|
||||
assertNull(service.getConversionExecutorByTargetAlias(String.class, "class"));
|
||||
}
|
||||
|
||||
|
||||
public void testGetConversionExecutorsForSource() {
|
||||
assertEquals(
|
||||
new TextToClass().getTargetClasses().length +
|
||||
new TextToBoolean().getTargetClasses().length +
|
||||
new TextToNumber().getTargetClasses().length,
|
||||
assertEquals(new TextToClass().getTargetClasses().length + new TextToBoolean().getTargetClasses().length
|
||||
+ new TextToNumber().getTargetClasses().length,
|
||||
service.getConversionExecutorsForSource(String.class).length);
|
||||
assertEquals(0, service.getConversionExecutorsForSource(Date.class).length);
|
||||
ConversionExecutor[] fromStringConversionExecutors = service.getConversionExecutorsForSource(String.class);
|
||||
@@ -81,7 +78,7 @@ public class CompositeConversionServiceTests extends TestCase {
|
||||
}
|
||||
assertEquals(Boolean.TRUE, booleanConversionExecutor.execute("ja"));
|
||||
}
|
||||
|
||||
|
||||
public void testGetClassByAlias() {
|
||||
assertEquals(Boolean.class, service.getClassByAlias("boolean"));
|
||||
assertEquals(Integer.class, service.getClassByAlias("integer"));
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.springframework.core.enums.ShortCodedLabeledEnum;
|
||||
* @author Keith Donald
|
||||
*/
|
||||
public class DefaultConversionServiceTests extends TestCase {
|
||||
|
||||
|
||||
public void testConvertCompatibleTypes() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addAlias("list", List.class);
|
||||
@@ -40,36 +40,34 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
List lst = new ArrayList();
|
||||
assertSame(lst, service.getConversionExecutor(ArrayList.class, List.class).execute(lst));
|
||||
assertSame(lst, service.getConversionExecutorByTargetAlias(ArrayList.class, "list").execute(lst));
|
||||
|
||||
|
||||
try {
|
||||
service.getConversionExecutor(List.class, ArrayList.class);
|
||||
fail();
|
||||
}
|
||||
catch (ConversionException e) {
|
||||
} catch (ConversionException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void testOverrideConverter() {
|
||||
Converter customConverter = new TextToBoolean("ja", "nee");
|
||||
|
||||
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
|
||||
|
||||
ConversionExecutor executor = service.getConversionExecutor(String.class, Boolean.class);
|
||||
assertNotSame(customConverter, executor.getConverter());
|
||||
try {
|
||||
executor.execute("ja");
|
||||
fail();
|
||||
}
|
||||
catch (ConversionException e) {
|
||||
} catch (ConversionException e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
|
||||
service.addConverter(customConverter);
|
||||
|
||||
|
||||
executor = service.getConversionExecutor(String.class, Boolean.class);
|
||||
assertSame(customConverter, executor.getConverter());
|
||||
assertTrue(((Boolean)executor.execute("ja")).booleanValue());
|
||||
assertTrue(((Boolean) executor.execute("ja")).booleanValue());
|
||||
}
|
||||
|
||||
public void testTargetClassNotSupported() {
|
||||
@@ -77,15 +75,14 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
try {
|
||||
service.getConversionExecutor(String.class, HashMap.class);
|
||||
fail("Should have thrown an exception");
|
||||
}
|
||||
catch (ConversionException e) {
|
||||
} catch (ConversionException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public void testValidConversion() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
ConversionExecutor executor = service.getConversionExecutor(String.class, Integer.class);
|
||||
Integer three = (Integer)executor.execute("3");
|
||||
Integer three = (Integer) executor.execute("3");
|
||||
assertEquals(3, three.intValue());
|
||||
}
|
||||
|
||||
@@ -95,15 +92,14 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
try {
|
||||
executor.execute("My Invalid Label");
|
||||
fail("Should have failed");
|
||||
}
|
||||
catch (ConversionException e) {
|
||||
} catch (ConversionException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public void testValidLabeledEnumConversion() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
ConversionExecutor executor = service.getConversionExecutor(String.class, MyEnum.class);
|
||||
MyEnum myEnum = (MyEnum)executor.execute("My Label 1");
|
||||
MyEnum myEnum = (MyEnum) executor.execute("My Label 1");
|
||||
assertEquals(MyEnum.ONE, myEnum);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,86 +17,86 @@ import org.springframework.binding.expression.support.TestMethods;
|
||||
*/
|
||||
public class ELExpressionParserTests extends TestCase {
|
||||
|
||||
ELExpressionParser parser = new ELExpressionParser(new ExpressionFactoryImpl());
|
||||
ELExpressionParser parser = new ELExpressionParser(new ExpressionFactoryImpl());
|
||||
|
||||
Map context;
|
||||
Map context;
|
||||
|
||||
Map container;
|
||||
Map container;
|
||||
|
||||
TestMethods target;
|
||||
TestMethods target;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
context = new HashMap();
|
||||
container = new HashMap();
|
||||
target = (TestMethods) EasyMock.createMock(TestMethods.class);
|
||||
context.put("container", container);
|
||||
container.put("myObject", target);
|
||||
}
|
||||
protected void setUp() throws Exception {
|
||||
context = new HashMap();
|
||||
container = new HashMap();
|
||||
target = (TestMethods) EasyMock.createMock(TestMethods.class);
|
||||
context.put("container", container);
|
||||
container.put("myObject", target);
|
||||
}
|
||||
|
||||
public void testWithIntParam() {
|
||||
String expression = "#{container.myObject.doSomethingWithInt(container.param1)}";
|
||||
int param = 5;
|
||||
container.put("param1", new Integer(param));
|
||||
target.doSomethingWithInt(param);
|
||||
EasyMock.replay(new Object[] { target });
|
||||
public void testWithIntParam() {
|
||||
String expression = "#{container.myObject.doSomethingWithInt(container.param1)}";
|
||||
int param = 5;
|
||||
container.put("param1", new Integer(param));
|
||||
target.doSomethingWithInt(param);
|
||||
EasyMock.replay(new Object[] { target });
|
||||
|
||||
parser.parseExpression(expression).evaluate(context, null);
|
||||
EasyMock.verify(new Object[] { target });
|
||||
parser.parseExpression(expression).evaluate(context, null);
|
||||
EasyMock.verify(new Object[] { target });
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void testReturnWithIntParam() {
|
||||
String expected = "sucess";
|
||||
String expression = "#{container.myObject.returnStringFromInt(container.param1)}";
|
||||
int param = 5;
|
||||
container.put("param1", new Integer(param));
|
||||
EasyMock.expect(target.returnStringFromInt(param)).andReturn(expected);
|
||||
EasyMock.replay(new Object[] { target });
|
||||
public void testReturnWithIntParam() {
|
||||
String expected = "sucess";
|
||||
String expression = "#{container.myObject.returnStringFromInt(container.param1)}";
|
||||
int param = 5;
|
||||
container.put("param1", new Integer(param));
|
||||
EasyMock.expect(target.returnStringFromInt(param)).andReturn(expected);
|
||||
EasyMock.replay(new Object[] { target });
|
||||
|
||||
String result = (String) parser.parseExpression(expression).evaluate(context, null);
|
||||
EasyMock.verify(new Object[] { target });
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
String result = (String) parser.parseExpression(expression).evaluate(context, null);
|
||||
EasyMock.verify(new Object[] { target });
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
public void testReturnWithIntAndObject() {
|
||||
String expected = "success";
|
||||
String expression = "#{container.myObject.returnStringFromIntAndObject(container.param1, container.param2)}";
|
||||
int param1 = 5;
|
||||
container.put("param1", new Integer(param1));
|
||||
TestBean param2 = new TestBean();
|
||||
container.put("param2", param2);
|
||||
EasyMock.expect(target.returnStringFromIntAndObject(param1, param2)).andReturn(expected);
|
||||
EasyMock.replay(new Object[] { target });
|
||||
public void testReturnWithIntAndObject() {
|
||||
String expected = "success";
|
||||
String expression = "#{container.myObject.returnStringFromIntAndObject(container.param1, container.param2)}";
|
||||
int param1 = 5;
|
||||
container.put("param1", new Integer(param1));
|
||||
TestBean param2 = new TestBean();
|
||||
container.put("param2", param2);
|
||||
EasyMock.expect(target.returnStringFromIntAndObject(param1, param2)).andReturn(expected);
|
||||
EasyMock.replay(new Object[] { target });
|
||||
|
||||
String result = (String) parser.parseExpression(expression).evaluate(context, null);
|
||||
EasyMock.verify(new Object[] { target });
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
String result = (String) parser.parseExpression(expression).evaluate(context, null);
|
||||
EasyMock.verify(new Object[] { target });
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
public void testEmptyMethod() {
|
||||
public void testEmptyMethod() {
|
||||
|
||||
String expStr1 = "#{foo.bar()}";
|
||||
Expression result1 = parser.parseExpression(expStr1);
|
||||
assertNotNull(result1);
|
||||
assertEquals(expStr1, result1.toString());
|
||||
String expStr1 = "#{foo.bar()}";
|
||||
Expression result1 = parser.parseExpression(expStr1);
|
||||
assertNotNull(result1);
|
||||
assertEquals(expStr1, result1.toString());
|
||||
|
||||
String expStr2 = "foo.bar()";
|
||||
Expression result2 = parser.parseExpression(expStr2);
|
||||
assertNotNull(result2);
|
||||
assertEquals(expStr1, result2.toString());
|
||||
}
|
||||
String expStr2 = "foo.bar()";
|
||||
Expression result2 = parser.parseExpression(expStr2);
|
||||
assertNotNull(result2);
|
||||
assertEquals(expStr1, result2.toString());
|
||||
}
|
||||
|
||||
public void testMethodWithParams() {
|
||||
public void testMethodWithParams() {
|
||||
|
||||
String expStr1 = "#{foo.bar(moe.curly, groucho.harpo)}";
|
||||
Expression result1 = parser.parseExpression(expStr1);
|
||||
assertNotNull(result1);
|
||||
assertEquals(expStr1, result1.toString());
|
||||
String expStr1 = "#{foo.bar(moe.curly, groucho.harpo)}";
|
||||
Expression result1 = parser.parseExpression(expStr1);
|
||||
assertNotNull(result1);
|
||||
assertEquals(expStr1, result1.toString());
|
||||
|
||||
String expStr2 = "foo.bar(moe.curly, groucho.harpo)";
|
||||
Expression result2 = parser.parseExpression(expStr2);
|
||||
assertNotNull(result2);
|
||||
assertEquals(expStr1, result2.toString());
|
||||
}
|
||||
String expStr2 = "foo.bar(moe.curly, groucho.harpo)";
|
||||
Expression result2 = parser.parseExpression(expStr2);
|
||||
assertNotNull(result2);
|
||||
assertEquals(expStr1, result2.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,29 +30,29 @@ public class OgnlExpressionParserTests extends TestCase {
|
||||
private OgnlExpressionParser parser = new OgnlExpressionParser();
|
||||
|
||||
private TestBean bean = new TestBean();
|
||||
|
||||
|
||||
public void testParseSimpleDelimited() {
|
||||
String exp = "${flag}";
|
||||
Expression e = parser.parseExpression(exp);
|
||||
assertNotNull(e);
|
||||
Boolean b = (Boolean)e.evaluate(bean, null);
|
||||
Boolean b = (Boolean) e.evaluate(bean, null);
|
||||
assertFalse(b.booleanValue());
|
||||
}
|
||||
|
||||
|
||||
public void testParseSimple() {
|
||||
String exp = "flag";
|
||||
Expression e = parser.parseExpression(exp);
|
||||
assertNotNull(e);
|
||||
Boolean b = (Boolean)e.evaluate(bean, null);
|
||||
Boolean b = (Boolean) e.evaluate(bean, null);
|
||||
assertFalse(b.booleanValue());
|
||||
}
|
||||
|
||||
|
||||
public void testParseNull() {
|
||||
Expression e = parser.parseExpression(null);
|
||||
assertNotNull(e);
|
||||
assertNull(e.evaluate(bean, null));
|
||||
}
|
||||
|
||||
|
||||
public void testParseEmpty() {
|
||||
Expression e = parser.parseExpression("");
|
||||
assertNotNull(e);
|
||||
@@ -63,7 +63,7 @@ public class OgnlExpressionParserTests extends TestCase {
|
||||
String exp = "hello ${flag} ${flag} ${flag}";
|
||||
Expression e = parser.parseExpression(exp);
|
||||
assertNotNull(e);
|
||||
String str = (String)e.evaluate(bean, null);
|
||||
String str = (String) e.evaluate(bean, null);
|
||||
assertEquals("hello false false false", str);
|
||||
}
|
||||
|
||||
@@ -72,8 +72,7 @@ public class OgnlExpressionParserTests extends TestCase {
|
||||
try {
|
||||
parser.parseExpression(exp);
|
||||
fail("Should've failed - not intended use");
|
||||
}
|
||||
catch (ParserException e) {
|
||||
} catch (ParserException e) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,58 +80,54 @@ public class OgnlExpressionParserTests extends TestCase {
|
||||
try {
|
||||
parser.parseExpression("${");
|
||||
fail();
|
||||
}
|
||||
catch (ParserException e) {
|
||||
} catch (ParserException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
String exp = "hello ${flag} ${abcd defg";
|
||||
parser.parseExpression(exp);
|
||||
fail("Should've failed - not intended use");
|
||||
}
|
||||
catch (ParserException e) {
|
||||
} catch (ParserException e) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void testSyntaxError2() {
|
||||
try {
|
||||
parser.parseExpression("${}");
|
||||
fail("Should've failed - not intended use");
|
||||
}
|
||||
catch (ParserException e) {
|
||||
} catch (ParserException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
String exp = "hello ${flag} ${}";
|
||||
parser.parseExpression(exp);
|
||||
fail("Should've failed - not intended use");
|
||||
}
|
||||
catch (ParserException e) {
|
||||
} catch (ParserException e) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void testIsDelimitedExpression() {
|
||||
assertTrue(parser.isDelimitedExpression("${foo}"));
|
||||
assertTrue(parser.isDelimitedExpression("${foo ${foo}}"));
|
||||
assertTrue(parser.isDelimitedExpression("foo ${bar}"));
|
||||
}
|
||||
|
||||
|
||||
public void testIsNotDelimitedExpression() {
|
||||
assertFalse(parser.isDelimitedExpression("foo"));
|
||||
assertFalse(parser.isDelimitedExpression("foo ${"));
|
||||
assertFalse(parser.isDelimitedExpression("$foo}"));
|
||||
assertFalse(parser.isDelimitedExpression("foo ${}"));
|
||||
}
|
||||
|
||||
|
||||
public void testCollectionContructionSyntax() {
|
||||
// lists
|
||||
parser.parseExpression("name in {null, \"Untitled\"}");
|
||||
parser.parseExpression("${name in {null, \"Untitled\"}}");
|
||||
|
||||
|
||||
// native arrays
|
||||
parser.parseExpression("new int[] {1, 2, 3}");
|
||||
parser.parseExpression("${new int[] {1, 2, 3}}");
|
||||
|
||||
|
||||
// maps
|
||||
parser.parseExpression("#{ 'foo' : 'foo value', 'bar' : 'bar value' }");
|
||||
parser.parseExpression("${#{ 'foo' : 'foo value', 'bar' : 'bar value' }}");
|
||||
|
||||
@@ -47,18 +47,17 @@ public class CollectionAddingExpressionTests extends TestCase {
|
||||
assertEquals("1", bean.getList().get(0));
|
||||
assertEquals("2", bean.getList().get(1));
|
||||
}
|
||||
|
||||
|
||||
public void testNotACollection() {
|
||||
Expression exp = parser.parseExpression("flag");
|
||||
Expression exp = parser.parseExpression("flag");
|
||||
CollectionAddingExpression colExp = new CollectionAddingExpression(exp);
|
||||
try {
|
||||
colExp.evaluateToSet(bean, "1", null);
|
||||
fail("not a collection");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void testNoAddOnNullValue() {
|
||||
CollectionAddingExpression colExp = new CollectionAddingExpression(exp);
|
||||
colExp.evaluateToSet(bean, null, null);
|
||||
|
||||
@@ -37,68 +37,68 @@ import junit.framework.TestSuite;
|
||||
*/
|
||||
public class SimpleExpressionTests extends TestCase {
|
||||
|
||||
private ExpressionParser expressionParser;
|
||||
private String expressionPrefix;
|
||||
private TestBean bean;
|
||||
private ExpressionParser expressionParser;
|
||||
private String expressionPrefix;
|
||||
private TestBean bean;
|
||||
|
||||
public static TestSuite suite() {
|
||||
TestSuite suite = new TestSuite();
|
||||
suite.addTest(new SimpleExpressionTests("testGetValue", new OgnlExpressionParser(), "$"));
|
||||
suite.addTest(new SimpleExpressionTests("testSetValue", new OgnlExpressionParser(), "$"));
|
||||
suite.addTest(new SimpleExpressionTests("testSyntaxError", new OgnlExpressionParser(), "$"));
|
||||
suite.addTest(new SimpleExpressionTests("testGetValue", new BeanWrapperExpressionParser(), "$"));
|
||||
suite.addTest(new SimpleExpressionTests("testSetValue", new BeanWrapperExpressionParser(), "$"));
|
||||
suite.addTest(new SimpleExpressionTests("testSyntaxError", new BeanWrapperExpressionParser(), "$"));
|
||||
suite.addTest(new SimpleExpressionTests("testGetValue", new ELExpressionParser(new ExpressionFactoryImpl()),
|
||||
"#"));
|
||||
suite.addTest(new SimpleExpressionTests("testSetValue", new ELExpressionParser(new ExpressionFactoryImpl()),
|
||||
"#"));
|
||||
suite.addTest(new SimpleExpressionTests("testSyntaxError", new ELExpressionParser(new ExpressionFactoryImpl()),
|
||||
"#"));
|
||||
return suite;
|
||||
}
|
||||
|
||||
public SimpleExpressionTests(String name, ExpressionParser expressionParser, String expressionPrefix) {
|
||||
super(name);
|
||||
this.expressionParser = expressionParser;
|
||||
this.expressionPrefix = expressionPrefix;
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
bean = new TestBean();
|
||||
bean.setFlag(true);
|
||||
List list = new ArrayList();
|
||||
list.add("foo");
|
||||
list.add("bar");
|
||||
bean.setList(list);
|
||||
}
|
||||
|
||||
public void testGetValue() {
|
||||
assertEquals(Boolean.TRUE, expressionParser.parseExpression(expressionPrefix + "{flag}").evaluate(bean, null));
|
||||
assertEquals(Boolean.TRUE, expressionParser.parseExpression("flag").evaluate(bean, null));
|
||||
assertSame(bean.getList(), expressionParser.parseExpression(expressionPrefix + "{list}").evaluate(bean, null));
|
||||
assertEquals("foo", expressionParser.parseExpression(expressionPrefix + "{list[0]}").evaluate(bean, null));
|
||||
}
|
||||
|
||||
public void testSetValue() {
|
||||
expressionParser.parseSettableExpression(expressionPrefix + "{flag}").evaluateToSet(bean, Boolean.FALSE, null);
|
||||
assertFalse(bean.isFlag());
|
||||
expressionParser.parseSettableExpression("flag").evaluateToSet(bean, Boolean.TRUE, null);
|
||||
assertTrue(bean.isFlag());
|
||||
List newList = new ArrayList();
|
||||
newList.add("boo");
|
||||
expressionParser.parseSettableExpression(expressionPrefix + "{list}").evaluateToSet(bean, newList, null);
|
||||
assertSame(newList, bean.getList());
|
||||
expressionParser.parseSettableExpression(expressionPrefix + "{list[0]}").evaluateToSet(bean, "baa", null);
|
||||
assertEquals("baa", bean.getList().get(0));
|
||||
}
|
||||
|
||||
public void testSyntaxError() {
|
||||
try {
|
||||
expressionParser.parseExpression("foo(").evaluate(bean, null);
|
||||
fail("should have failed");
|
||||
} catch (ParserException e) {
|
||||
} catch (EvaluationException e) {
|
||||
public static TestSuite suite() {
|
||||
TestSuite suite = new TestSuite();
|
||||
suite.addTest(new SimpleExpressionTests("testGetValue", new OgnlExpressionParser(), "$"));
|
||||
suite.addTest(new SimpleExpressionTests("testSetValue", new OgnlExpressionParser(), "$"));
|
||||
suite.addTest(new SimpleExpressionTests("testSyntaxError", new OgnlExpressionParser(), "$"));
|
||||
suite.addTest(new SimpleExpressionTests("testGetValue", new BeanWrapperExpressionParser(), "$"));
|
||||
suite.addTest(new SimpleExpressionTests("testSetValue", new BeanWrapperExpressionParser(), "$"));
|
||||
suite.addTest(new SimpleExpressionTests("testSyntaxError", new BeanWrapperExpressionParser(), "$"));
|
||||
suite.addTest(new SimpleExpressionTests("testGetValue", new ELExpressionParser(new ExpressionFactoryImpl()),
|
||||
"#"));
|
||||
suite.addTest(new SimpleExpressionTests("testSetValue", new ELExpressionParser(new ExpressionFactoryImpl()),
|
||||
"#"));
|
||||
suite.addTest(new SimpleExpressionTests("testSyntaxError", new ELExpressionParser(new ExpressionFactoryImpl()),
|
||||
"#"));
|
||||
return suite;
|
||||
}
|
||||
|
||||
public SimpleExpressionTests(String name, ExpressionParser expressionParser, String expressionPrefix) {
|
||||
super(name);
|
||||
this.expressionParser = expressionParser;
|
||||
this.expressionPrefix = expressionPrefix;
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
bean = new TestBean();
|
||||
bean.setFlag(true);
|
||||
List list = new ArrayList();
|
||||
list.add("foo");
|
||||
list.add("bar");
|
||||
bean.setList(list);
|
||||
}
|
||||
|
||||
public void testGetValue() {
|
||||
assertEquals(Boolean.TRUE, expressionParser.parseExpression(expressionPrefix + "{flag}").evaluate(bean, null));
|
||||
assertEquals(Boolean.TRUE, expressionParser.parseExpression("flag").evaluate(bean, null));
|
||||
assertSame(bean.getList(), expressionParser.parseExpression(expressionPrefix + "{list}").evaluate(bean, null));
|
||||
assertEquals("foo", expressionParser.parseExpression(expressionPrefix + "{list[0]}").evaluate(bean, null));
|
||||
}
|
||||
|
||||
public void testSetValue() {
|
||||
expressionParser.parseSettableExpression(expressionPrefix + "{flag}").evaluateToSet(bean, Boolean.FALSE, null);
|
||||
assertFalse(bean.isFlag());
|
||||
expressionParser.parseSettableExpression("flag").evaluateToSet(bean, Boolean.TRUE, null);
|
||||
assertTrue(bean.isFlag());
|
||||
List newList = new ArrayList();
|
||||
newList.add("boo");
|
||||
expressionParser.parseSettableExpression(expressionPrefix + "{list}").evaluateToSet(bean, newList, null);
|
||||
assertSame(newList, bean.getList());
|
||||
expressionParser.parseSettableExpression(expressionPrefix + "{list[0]}").evaluateToSet(bean, "baa", null);
|
||||
assertEquals("baa", bean.getList().get(0));
|
||||
}
|
||||
|
||||
public void testSyntaxError() {
|
||||
try {
|
||||
expressionParser.parseExpression("foo(").evaluate(bean, null);
|
||||
fail("should have failed");
|
||||
} catch (ParserException e) {
|
||||
} catch (EvaluationException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,11 +19,11 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TestBean {
|
||||
|
||||
|
||||
private boolean flag;
|
||||
|
||||
private List list = new ArrayList();
|
||||
|
||||
|
||||
public boolean isFlag() {
|
||||
return flag;
|
||||
}
|
||||
@@ -35,7 +35,7 @@ public class TestBean {
|
||||
public List getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
public void setList(List list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ package org.springframework.binding.expression.support;
|
||||
public interface TestMethods {
|
||||
|
||||
public void doSomethingWithInt(int arg);
|
||||
|
||||
|
||||
public String returnStringFromInt(int arg);
|
||||
|
||||
|
||||
public String returnStringFromIntAndObject(int arg, TestBean bean);
|
||||
}
|
||||
|
||||
@@ -29,18 +29,18 @@ import junit.framework.TestCase;
|
||||
* @author Erwin Vervaet
|
||||
*/
|
||||
public class NumberFormatterTests extends TestCase {
|
||||
|
||||
|
||||
private Locale systemDefaultLocale;
|
||||
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
systemDefaultLocale = Locale.getDefault();
|
||||
}
|
||||
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
// restore default
|
||||
Locale.setDefault(systemDefaultLocale);
|
||||
}
|
||||
|
||||
|
||||
public void testParseUsBigDecimalInUs() {
|
||||
Locale.setDefault(Locale.US);
|
||||
SimpleFormatterFactory formatterFactory = new SimpleFormatterFactory();
|
||||
@@ -56,7 +56,7 @@ public class NumberFormatterTests extends TestCase {
|
||||
Formatter formatter = formatterFactory.getNumberFormatter(BigDecimal.class);
|
||||
assertEquals(new BigDecimal("123.45"), formatter.parseValue("123.45", BigDecimal.class));
|
||||
}
|
||||
|
||||
|
||||
public void testParseGermanBigDecimalInGermany() {
|
||||
Locale.setDefault(Locale.GERMANY);
|
||||
SimpleFormatterFactory formatterFactory = new SimpleFormatterFactory();
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.springframework.binding.expression.ognl.OgnlExpressionParser;
|
||||
* Unit tests for the {@link org.springframework.binding.mapping.RequiredMapping}.
|
||||
*/
|
||||
public class RequiredMappingTests extends TestCase {
|
||||
|
||||
|
||||
public void testRequired() {
|
||||
MappingBuilder builder = new MappingBuilder(new OgnlExpressionParser());
|
||||
Mapping mapping = builder.source("foo").target("bar").required().value();
|
||||
@@ -35,7 +35,7 @@ public class RequiredMappingTests extends TestCase {
|
||||
mapping.map(source, target, null);
|
||||
assertEquals("baz", target.get("bar"));
|
||||
}
|
||||
|
||||
|
||||
public void testRequiredExceptionOnNull() {
|
||||
MappingBuilder builder = new MappingBuilder(new OgnlExpressionParser());
|
||||
Mapping mapping = builder.source("foo").target("bar").required().value();
|
||||
@@ -44,8 +44,7 @@ public class RequiredMappingTests extends TestCase {
|
||||
HashMap target = new HashMap();
|
||||
try {
|
||||
mapping.map(source, target, null);
|
||||
}
|
||||
catch (RequiredMappingException e) {
|
||||
} catch (RequiredMappingException e) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,8 +55,7 @@ public class RequiredMappingTests extends TestCase {
|
||||
HashMap target = new HashMap();
|
||||
try {
|
||||
mapping.map(source, target, null);
|
||||
}
|
||||
catch (RequiredMappingException e) {
|
||||
} catch (RequiredMappingException e) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ public class MethodInvocationExceptionTests extends TestCase {
|
||||
IllegalArgumentException iae = new IllegalArgumentException("test");
|
||||
MethodInvocationException ex = testException(iae);
|
||||
assertSame(iae, ex.getTargetException());
|
||||
|
||||
|
||||
// exception
|
||||
IOException ioe = new IOException("test");
|
||||
ex = testException(ioe);
|
||||
@@ -42,15 +42,15 @@ public class MethodInvocationExceptionTests extends TestCase {
|
||||
InvocationTargetException ite = new InvocationTargetException(ioe);
|
||||
ex = testException(ite);
|
||||
assertSame(ioe, ex.getTargetException());
|
||||
|
||||
|
||||
// deep nesting
|
||||
ite = new InvocationTargetException(new InvocationTargetException(ioe));
|
||||
ex = testException(ite);
|
||||
assertSame(ioe, ex.getTargetException());
|
||||
}
|
||||
|
||||
|
||||
// internal helpers
|
||||
|
||||
|
||||
private MethodInvocationException testException(Throwable cause) {
|
||||
return new MethodInvocationException(new MethodSignature("test"), null, cause);
|
||||
}
|
||||
|
||||
@@ -36,8 +36,7 @@ public class MethodInvokerTests extends TestCase {
|
||||
try {
|
||||
methodInvoker.invoke(new MethodSignature("test"), new TestObject(), null);
|
||||
fail();
|
||||
}
|
||||
catch (MethodInvocationException e) {
|
||||
} catch (MethodInvocationException e) {
|
||||
assertTrue(e.getTargetException() instanceof IllegalArgumentException);
|
||||
assertEquals("just testing", e.getTargetException().getMessage());
|
||||
}
|
||||
@@ -47,8 +46,7 @@ public class MethodInvokerTests extends TestCase {
|
||||
try {
|
||||
methodInvoker.invoke(new MethodSignature("bogus"), new TestObject(), null);
|
||||
fail();
|
||||
}
|
||||
catch (MethodInvocationException e) {
|
||||
} catch (MethodInvocationException e) {
|
||||
assertTrue(e.getTargetException() instanceof InvalidMethodKeyException);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public class MethodKeyTests extends TestCase {
|
||||
|
||||
private static final Method LIST_FILENAME_FILTER = safeGetMethod(File.class, "list",
|
||||
new Class[] { FilenameFilter.class });
|
||||
|
||||
|
||||
public void testGetMethodWithNoArgs() throws Exception {
|
||||
MethodKey key = new MethodKey(File.class, "list", new Class[0]);
|
||||
Method m = key.getMethod();
|
||||
@@ -62,8 +62,7 @@ public class MethodKeyTests extends TestCase {
|
||||
private static final Method safeGetMethod(Class type, String name, Class[] argTypes) {
|
||||
try {
|
||||
return type.getMethod(name, argTypes);
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new IllegalStateException("Unable to safely access a known method via reflection. " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,9 +28,9 @@ import org.springframework.binding.expression.ognl.OgnlExpressionParser;
|
||||
* @author Erwin Vervaet
|
||||
*/
|
||||
public class TextToMethodSignatureTests extends TestCase {
|
||||
|
||||
|
||||
private TextToMethodSignature converter;
|
||||
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
DefaultConversionService conversionService = new DefaultConversionService();
|
||||
conversionService.addConverter(new TextToExpression(new OgnlExpressionParser()));
|
||||
@@ -38,102 +38,101 @@ public class TextToMethodSignatureTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testParseNoArguments() {
|
||||
MethodSignature signature = (MethodSignature)converter.convert("foo");
|
||||
MethodSignature signature = (MethodSignature) converter.convert("foo");
|
||||
assertEquals("foo", signature.getMethodName());
|
||||
assertEquals(0, signature.getParameters().size());
|
||||
|
||||
signature = (MethodSignature)converter.convert("foo()");
|
||||
|
||||
signature = (MethodSignature) converter.convert("foo()");
|
||||
assertEquals("foo", signature.getMethodName());
|
||||
assertEquals(0, signature.getParameters().size());
|
||||
}
|
||||
|
||||
|
||||
public void testSingleArgument() {
|
||||
MethodSignature signature = (MethodSignature)converter.convert("foo(${flowScope.bar})");
|
||||
MethodSignature signature = (MethodSignature) converter.convert("foo(${flowScope.bar})");
|
||||
assertEquals("foo", signature.getMethodName());
|
||||
assertEquals(1, signature.getParameters().size());
|
||||
assertNull(signature.getParameters().getParameter(0).getType());
|
||||
assertEquals("flowScope.bar", signature.getParameters().getParameter(0).getName().toString());
|
||||
|
||||
signature = (MethodSignature)converter.convert("foo(${'Foo' + flowScope.bar})");
|
||||
|
||||
signature = (MethodSignature) converter.convert("foo(${'Foo' + flowScope.bar})");
|
||||
assertEquals("foo", signature.getMethodName());
|
||||
assertEquals(1, signature.getParameters().size());
|
||||
assertEquals("\"Foo\" + flowScope.bar", signature.getParameters().getParameter(0).getName().toString());
|
||||
}
|
||||
|
||||
|
||||
public void testSingleArgumentWithType() {
|
||||
MethodSignature signature = (MethodSignature)converter.convert("foo(java.lang.String ${flowScope.bar})");
|
||||
MethodSignature signature = (MethodSignature) converter.convert("foo(java.lang.String ${flowScope.bar})");
|
||||
assertEquals("foo", signature.getMethodName());
|
||||
assertEquals(1, signature.getParameters().size());
|
||||
assertEquals(String.class, signature.getParameters().getParameter(0).getType());
|
||||
assertEquals("flowScope.bar", signature.getParameters().getParameter(0).getName().toString());
|
||||
|
||||
signature = (MethodSignature)converter.convert("foo(long ${flowScope.bar})");
|
||||
|
||||
signature = (MethodSignature) converter.convert("foo(long ${flowScope.bar})");
|
||||
assertEquals("foo", signature.getMethodName());
|
||||
assertEquals(1, signature.getParameters().size());
|
||||
assertEquals(Long.class, signature.getParameters().getParameter(0).getType());
|
||||
assertEquals("flowScope.bar", signature.getParameters().getParameter(0).getName().toString());
|
||||
}
|
||||
|
||||
|
||||
public void testMultipleArguments() {
|
||||
MethodSignature signature = (MethodSignature)converter.convert(
|
||||
"foo(${flowScope.bar}, ${externalContext.requestParameterMap.test})");
|
||||
MethodSignature signature = (MethodSignature) converter
|
||||
.convert("foo(${flowScope.bar}, ${externalContext.requestParameterMap.test})");
|
||||
assertEquals("foo", signature.getMethodName());
|
||||
assertEquals(2, signature.getParameters().size());
|
||||
assertNull(signature.getParameters().getParameter(0).getType());
|
||||
assertEquals("flowScope.bar", signature.getParameters().getParameter(0).getName().toString());
|
||||
assertNull(signature.getParameters().getParameter(1).getType());
|
||||
assertEquals("externalContext.requestParameterMap.test", signature.getParameters().getParameter(1).getName().toString());
|
||||
assertEquals("externalContext.requestParameterMap.test", signature.getParameters().getParameter(1).getName()
|
||||
.toString());
|
||||
}
|
||||
|
||||
|
||||
public void testMultipleArgumentsWithType() {
|
||||
MethodSignature signature = (MethodSignature)converter.convert(
|
||||
"foo(long ${flowScope.bar}, java.lang.String ${externalContext.requestParameterMap.test})");
|
||||
MethodSignature signature = (MethodSignature) converter
|
||||
.convert("foo(long ${flowScope.bar}, java.lang.String ${externalContext.requestParameterMap.test})");
|
||||
assertEquals("foo", signature.getMethodName());
|
||||
assertEquals(2, signature.getParameters().size());
|
||||
assertEquals(Long.class, signature.getParameters().getParameter(0).getType());
|
||||
assertEquals("flowScope.bar", signature.getParameters().getParameter(0).getName().toString());
|
||||
assertEquals(String.class, signature.getParameters().getParameter(1).getType());
|
||||
assertEquals("externalContext.requestParameterMap.test", signature.getParameters().getParameter(1).getName().toString());
|
||||
assertEquals("externalContext.requestParameterMap.test", signature.getParameters().getParameter(1).getName()
|
||||
.toString());
|
||||
}
|
||||
|
||||
|
||||
public void testCollectionConstructionSyntax() {
|
||||
MethodSignature signature = (MethodSignature)converter.convert("foo({1, 2, 3})");
|
||||
MethodSignature signature = (MethodSignature) converter.convert("foo({1, 2, 3})");
|
||||
assertEquals("foo", signature.getMethodName());
|
||||
assertEquals(1, signature.getParameters().size());
|
||||
assertNull(signature.getParameters().getParameter(0).getType());
|
||||
assertEquals("{1, 2, 3}", signature.getParameters().getParameter(0).getName().toString());
|
||||
}
|
||||
|
||||
|
||||
public void testCollectionConstructionSyntaxWithType() {
|
||||
MethodSignature signature = (MethodSignature)converter.convert("foo(java.util.List {1, 2, 3})");
|
||||
MethodSignature signature = (MethodSignature) converter.convert("foo(java.util.List {1, 2, 3})");
|
||||
assertEquals("foo", signature.getMethodName());
|
||||
assertEquals(1, signature.getParameters().size());
|
||||
assertEquals(java.util.List.class, signature.getParameters().getParameter(0).getType());
|
||||
assertEquals("{1, 2, 3}", signature.getParameters().getParameter(0).getName().toString());
|
||||
|
||||
signature = (MethodSignature)converter.convert("foo(a${b,#{1:2},e}f${g,#{3:4},j}k)");
|
||||
|
||||
signature = (MethodSignature) converter.convert("foo(a${b,#{1:2},e}f${g,#{3:4},j}k)");
|
||||
}
|
||||
|
||||
|
||||
public void testSyntaxErrors() {
|
||||
try {
|
||||
converter.convert("foo(");
|
||||
fail();
|
||||
}
|
||||
catch (ConversionException e) {
|
||||
} catch (ConversionException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
converter.convert("foo(long 1, ${bar()}");
|
||||
fail();
|
||||
} catch (ConversionException e) {
|
||||
}
|
||||
catch (ConversionException e) {
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
converter.convert("foo(long 1, {1, 2)");
|
||||
fail();
|
||||
}
|
||||
catch (ConversionException e) {
|
||||
} catch (ConversionException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user