KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jicengine > expression > Tests


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 /**
12  *
13  *
14  * <p>
15  * Copyright (C) 2004 Timo Laitinen
16  * </p>
17  *
18  * @author Timo Laitinen
19  * @created 2004-09-20
20  * @since JICE-0.10
21  *
22  */

23
24 public class Tests {
25
26     public static class LJETest extends TestCase{
27         protected void expressionEquals(String JavaDoc expression, Object JavaDoc expected) throws Exception JavaDoc
28         {
29             Context dummyContext = new SimpleContext("empty-context");
30             Operation resultOp = LJEParser.getInstance().parse(expression);
31             Object JavaDoc result = resultOp.execute(dummyContext);
32             assertEquals(expected, result);
33         }
34
35         public void testNumbers() throws Exception JavaDoc
36         {
37             expressionEquals("123", new Integer JavaDoc(123));
38             expressionEquals("-1", new Integer JavaDoc(-1));
39             expressionEquals("0", new Integer JavaDoc(0));
40             expressionEquals("1.23", new Double JavaDoc(1.23));
41             expressionEquals("-1.01", new Double JavaDoc(-1.01));
42             expressionEquals("0.0", new Double JavaDoc(0.0));
43             expressionEquals("12345l", new Long JavaDoc(12345l));
44             expressionEquals("-1L", new Long JavaDoc(-1L));
45             expressionEquals("-11f", new Float JavaDoc(-11f));
46         }
47
48         public void testStrings() throws Exception JavaDoc
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 JavaDoc
60         {
61             expressionEquals("true ", new Boolean JavaDoc(true));
62             expressionEquals("false ", new Boolean JavaDoc(false));
63         }
64
65     }
66
67     public static class UtilsTest extends TestCase{
68         /*
69         public void doParseSignatureTest(String signature, String expectedType, String[] exprectedParams) throws Exception
70         {
71             Object[] result = Utils.parseSignature(signature);
72             assertEquals("Testing the type in signature '" + signature + "'.","type", result[0]);
73             Object[] params = (Object[]) result[1];
74             java.util.List paramsList = java.util.Arrays.asList(params);
75             java.util.List expectedParamsList = java.util.Arrays.asList(exprectedParams);
76             assertEquals("Expected " + expectedParamsList.size() + " params " + expectedParamsList + ", got " + paramsList.size() + " params " + paramsList,exprectedParams.length, params.length );
77
78             for (int i = 0; i < params.length; i++) {
79                 assertEquals("Testing param " + (i+1) + " in '" + signature + "'", exprectedParams[i], params[i]);
80             }
81         }
82         */

83
84         /*
85         public void testParseSignature() throws Exception
86         {
87             doParseSignatureTest(
88                 "type(param1,param2)",
89                 "type",
90                 new String[]{"param1","param2"}
91             );
92
93             doParseSignatureTest(
94                 "type('p()aram1',param2)",
95                 "type",
96                 new String[]{"'p()aram1'","param2"}
97             );
98
99             doParseSignatureTest(
100                 "type('a,b,c',param2)",
101                 "type",
102                 new String[]{"'a,b,c'","param2"}
103             );
104
105         }
106         */

107     }
108
109     public static Test createTests()
110     {
111         TestSuite suite = new TestSuite();
112
113         // add here all the TestCase-classes that are to
114
// be run.
115
Class JavaDoc[] testClasses = new Class JavaDoc[]{
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 JavaDoc[] args) {
129         //RunTests runTests1 = new RunTests();
130
junit.textui.TestRunner.run(createTests());
131     }
132 }
133
Popular Tags