1 46 47 package org.codehaus.groovy.runtime; 48 49 import groovy.lang.Closure; 50 import groovy.lang.GroovyObject; 51 import groovy.lang.GroovyRuntimeException; 52 import groovy.util.GroovyTestCase; 53 54 60 public class MethodFailureTest extends GroovyTestCase { 61 62 public void testFailingMethod() { 63 MockGroovyObject object = new MockGroovyObject(); 64 try { 65 object.invokeMethod("nonExistentMethod", "hello"); 66 67 fail("Should have thrown an exception"); 68 } 69 catch (GroovyRuntimeException e) { 70 System.out.println(e); 71 } 72 } 73 74 public void testMethodWhichCallsTheFailingMethod() { 75 MockGroovyObject object = new MockGroovyObject(); 76 try { 77 object.invokeMethod("methodThatFails", null); 78 79 fail("Should have thrown an exception"); 80 } 81 catch (GroovyRuntimeException e) { 82 System.out.println(e); 83 } 85 } 86 87 public void testMethodWhichCallsTheFailingMethodInsideAClosure() { 88 MockGroovyObject object = new MockGroovyObject(); 89 try { 90 object.invokeMethod("callClosure", new Closure(this) { 91 protected Object doCall(GroovyObject object) { 92 return object.invokeMethod("nonExistentMethod", "hello"); 93 } 94 }); 95 96 fail("Should have thrown an exception"); 97 } 98 catch (GroovyRuntimeException e) { 99 System.out.println(e); 100 } 102 } 103 104 } 105 | Popular Tags |