1 package org.jicengine.expression; 2 3 import org.jicengine.expression.Utils; 4 import org.jicengine.operation.SimpleContext; 5 import org.jicengine.operation.Context; 6 import org.jicengine.operation.Operation; 7 import junit.framework.TestCase; 8 import junit.framework.Test; 9 import junit.framework.TestSuite; 10 11 23 24 public class Tests { 25 26 public static class LJETest extends TestCase{ 27 protected void expressionEquals(String expression, Object expected) throws Exception 28 { 29 Context dummyContext = new SimpleContext("empty-context"); 30 Operation resultOp = LJEParser.getInstance().parse(expression); 31 Object result = resultOp.execute(dummyContext); 32 assertEquals(expected, result); 33 } 34 35 public void testNumbers() throws Exception 36 { 37 expressionEquals("123", new Integer (123)); 38 expressionEquals("-1", new Integer (-1)); 39 expressionEquals("0", new Integer (0)); 40 expressionEquals("1.23", new Double (1.23)); 41 expressionEquals("-1.01", new Double (-1.01)); 42 expressionEquals("0.0", new Double (0.0)); 43 expressionEquals("12345l", new Long (12345l)); 44 expressionEquals("-1L", new Long (-1L)); 45 expressionEquals("-11f", new Float (-11f)); 46 } 47 48 public void testStrings() throws Exception 49 { 50 expressionEquals("'hello' ", "hello"); 51 expressionEquals("'hello()'", "hello()"); 52 expressionEquals("'(hel,lo)'", "(hel,lo)"); 53 expressionEquals("'h,e,l,l,o'", "h,e,l,l,o"); 54 expressionEquals("'h e l l o'", "h e l l o"); 55 expressionEquals("'-123'", "-123"); 56 expressionEquals("''", ""); 57 } 58 59 public void testBoolean() throws Exception 60 { 61 expressionEquals("true ", new Boolean (true)); 62 expressionEquals("false ", new Boolean (false)); 63 } 64 65 } 66 67 public static class UtilsTest extends TestCase{ 68 83 84 107 } 108 109 public static Test createTests() 110 { 111 TestSuite suite = new TestSuite(); 112 113 Class [] testClasses = new Class []{ 116 LJETest.class, 117 UtilsTest.class 118 }; 119 120 for (int i = 0; i < testClasses.length; i++) { 121 suite.addTestSuite(testClasses[i]); 122 } 123 124 125 return suite; 126 } 127 128 public static void main(String [] args) { 129 junit.textui.TestRunner.run(createTests()); 131 } 132 } 133 | Popular Tags |