package beanface.el.functor.testing.tests; import java.util.Arrays; import java.util.List; import java.util.Vector; import javax.el.ELContext; import junit.framework.JUnit4TestAdapter; import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.JUnitCore; import beanface.el.functor.FunctorELResolver; import beanface.el.functor.testing.ELContextFactory; public class ListTests { static private ELContextFactory elcFactory; private ELContext elContext; private List items; @BeforeClass public static void setupOnce() { elcFactory = new ELContextFactory(); elcFactory.addELResolver(new FunctorELResolver()); } @Before public void setup() { elContext = elcFactory.getELContext(); items = new Vector(Arrays.asList(new String[] { "Apple", "Banana", "Orange", "Pear" })); } private Object testResolve(Object base, Object... properties) { Object result = base; for (Object prop : properties) { result = elContext.getELResolver().getValue(elContext, result, prop); Assert.assertNotNull("Expect result of applying property '" + prop + "' to base is not null", result); } return result; } @Test public void testListItem() { int index = 0; Object r = testResolve(items, index); Assert.assertNotNull("Resolve result", r); Assert.assertEquals("Expect a String to be returned", r.getClass(), String.class); Assert.assertEquals("Expected returned value", items.get(index), r); } @Test public void testListClass() { Object r = testResolve(items, "class"); Assert.assertNotNull("Resolve result", r); Assert.assertEquals("Expect a class to be returned", r.getClass(), Class.class); Class rClass = (Class) r; Assert.assertEquals("Expected returned class", items.getClass(), rClass); } @Test public void testListEmpty() { Object r = testResolve(items, "empty"); Assert.assertNotNull("Resolve result", r); Assert.assertEquals("Expect a bool to be returned", r.getClass(), Boolean.class); Boolean rBool = (Boolean) r; Assert.assertEquals("Expected returned value", items.isEmpty(), rBool.booleanValue()); } public static junit.framework.Test suite() { return new JUnit4TestAdapter(ListTests.class); } public static void main(String[] args) { JUnitCore.runClasses(ListTests.class); } }