geirm 01/04/18 13:43:36
Modified: src/java/org/apache/velocity/test
MethodInvocationExceptionTest.java
Log:
Added test for throwing an exception in a #set()
Revision Changes Path
1.5 +33 -1
jakarta-velocity/src/java/org/apache/velocity/test/MethodInvocationExceptionTest.java
Index: MethodInvocationExceptionTest.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/test/MethodInvocationExceptionTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- MethodInvocationExceptionTest.java 2001/04/18 12:21:24 1.4
+++ MethodInvocationExceptionTest.java 2001/04/18 20:43:36 1.5
@@ -69,7 +69,7 @@
* Tests if we can hand Velocity an arbitrary class for logging.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
- * @version $Id: MethodInvocationExceptionTest.java,v 1.4 2001/04/18 12:21:24 geirm
Exp $
+ * @version $Id: MethodInvocationExceptionTest.java,v 1.5 2001/04/18 20:43:36 geirm
Exp $
*/
public class MethodInvocationExceptionTest extends TestCase
{
@@ -197,6 +197,32 @@
{
fail("Wrong exception thrown, third test");
}
+
+ template = "#set($woogie.foo = 'lala') boing!";
+
+ try
+ {
+ Velocity. evaluate( vc, w, "test", template );
+ fail("No exception thrown, set test.");
+ }
+ catch( MethodInvocationException mie )
+ {
+ System.out.println("Caught MIE (good!) :" );
+ System.out.println(" reference = " + mie.getReferenceName() );
+ System.out.println(" method = " + mie.getMethodName() );
+
+ Throwable t = mie.getWrappedThrowable();
+ System.out.println(" throwable = " + t );
+
+ if( t instanceof Exception)
+ {
+ System.out.println(" exception = " + ( (Exception) t).getMessage()
);
+ }
+ }
+ catch( Exception e)
+ {
+ fail("Wrong exception thrown, set test");
+ }
}
public void doException()
@@ -209,5 +235,11 @@
throws Exception
{
throw new Exception("Hello from getFoo()" );
+ }
+
+ public void setFoo( String foo )
+ throws Exception
+ {
+ throw new Exception("Hello from setFoo()");
}
}