Update of /cvsroot/webmacro/webmacro/test/unit/org/webmacro/template
In directory sc8-pr-cvs1:/tmp/cvs-serv19326
Modified Files:
TestFunction.java
Log Message:
added tests for functions that return null or void.
Index: TestFunction.java
===================================================================
RCS file: /cvsroot/webmacro/webmacro/test/unit/org/webmacro/template/TestFunction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** TestFunction.java 15 Jun 2002 05:50:35 -0000 1.1
--- TestFunction.java 27 Mar 2003 05:09:58 -0000 1.2
***************
*** 20,24 ****
--- 20,37 ----
}
+ public void voidFunc1(){
+ }
+
+ public void voidFunc2(String dummyArg){
+ if (dummyArg == null) throw new RuntimeException();
+ }
+
+ public Object nullFunc(){
+ return null;
+ }
+
public void stuffContext (Context context) throws Exception {
+ context.setEvaluationExceptionHandler(
+ new org.webmacro.engine.CrankyEvaluationExceptionHandler());
context.putFunction("toList", java.util.Arrays.class, "asList");
context.putGlobalFunction("escape", org.webmacro.util.HTMLEscaper.class, "escape");
***************
*** 26,29 ****
--- 39,45 ----
String abcs = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
context.putFunction("mySubstr", abcs, "substring");
+ context.putFunction("voidFunc1", this, "voidFunc1");
+ context.putFunction("voidFunc2", this, "voidFunc2");
+ context.putFunction("nullFunc", this, "nullFunc");
}
***************
*** 43,46 ****
--- 59,69 ----
assertStringTemplateEquals("$mySubstr(24)", "YZ");
assertStringTemplateEquals("$mySubstr(0,3)", "ABC");
+ }
+
+ public void testVoidFunction() throws Exception {
+ assertStringTemplateEquals("$voidFunc1()", "");
+ assertStringTemplateEquals("$voidFunc2('bogus arg')", "");
+ assertStringTemplateEquals("#if ($nullFunc()==null){true} #else {false}", "true");
+ assertStringTemplateThrows("$nullFunc()", org.webmacro.PropertyException.NullValueException.class);
}
}
|