use of cn.taketoday.expression.ExpressionContext in project today-framework by TAKETODAY.
the class ELProcessorTests method testMethExpr.
@Test
void testMethExpr() {
MethodExpression meth = null;
ExpressionContext ctxt = elm.getContext();
try {
meth = factory.createMethodExpression(ctxt, "#{str.length}", Object.class, null);
} catch (NullPointerException ex) {
// Do nothing
}
assertTrue(meth == null);
meth = factory.createMethodExpression(ctxt, "#{'abc'.length()}", Object.class, null);
Object result = meth.invoke(ctxt, new Object[] { "abcde" });
System.out.println("'abc'.length() called, equals " + result);
assertEquals(result, 3);
}
use of cn.taketoday.expression.ExpressionContext in project today-framework by TAKETODAY.
the class ConvertTest method testCustom.
@Test
public void testCustom() {
elp.getManager().addResolver(new TypeConverter() {
@Override
public Object convertToType(ExpressionContext context, Object obj, Class<?> type) {
if (obj instanceof String && type == MyBean.class) {
context.setPropertyResolved(true);
return new MyBean((String) obj);
}
return null;
}
});
Object val = elp.getValue("'John Doe'", MyBean.class);
assertTrue(val instanceof MyBean);
assertEquals(((MyBean) val).getName(), "John Doe");
}
Aggregations