Groovy动态语言 运行在JVM中的动态语言 可以方便的处理业务逻辑变化大的业务

源代码在线查看: trycatchtest.groovy

软件大小: 1644 K
上传用户: maple_78
关键词: Groovy JVM 动态语言 运行
下载地址: 免注册下载 普通下载 VIP

相关代码

				class TryCatchTest extends GroovyTestCase {
				
				    def exceptionCalled
				    def finallyCalled
					
				    void testTryCatch() {
				        try {
				            failingMethod()
				        }
				        catch (AssertionError e) {
				            onException(e)
				        }
				        finally {
				            onFinally()
				        }
				        afterTryCatch()
				        assert exceptionCalled , "should have invoked the catch clause"
				        assert finallyCalled , "should have invoked the finally clause"
				        println("After try/catch")
				     }
				
				
				     void testTryFinally() {
				         Boolean touched = false;
				         
				         try {
				         }
				         finally {
				             touched = true;
				         }
				
				         assert touched , "finally not called with empty try"
				     }
				
				
				
				     void testWorkingMethod() {
				         /** @todo causes inconsistent stack height
				          assert exceptionCalled == false , "should not invoked the catch clause"
				          */
				         
				         try {
					    	 workingMethod()
					     }
					     catch (AssertionError e) {
						     onException(e)
					     }
					     finally {
						     onFinally()
					     }
					     assert exceptionCalled == false , "should not invoked the catch clause"
					     assert finallyCalled , "should have invoked the finally clause"
					     println("After try/catch")
				    }
				    
				    void failingMethod() {
				        assert false , "Failing on purpose"
					}
					
				    void workingMethod() {
				        assert true , "Should never fail"
				    }
				    
				    void onException(e) {
					    assert e != null
					    exceptionCalled = true
					}
					
				    void onFinally() {
				        finallyCalled = true
					}
				
				    void afterTryCatch() {
				        assert exceptionCalled , "should have invoked the catch clause"        
				        assert finallyCalled , "should have invoked the finally clause"
				        println("After try/catch")
				    }
				    
				    protected void setUp() {
				        exceptionCalled = false
				        finallyCalled = false
				    }
				}
							

相关资源