⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trycatchtest.groovy

📁 大名鼎鼎的java动态脚本语言。已经通过了sun的认证
💻 GROOVY
字号:
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    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -