1 8 package test.afterxxx; 9 10 import junit.framework.TestCase; 11 12 15 public class TestBinding extends TestCase { 16 17 private static String s_log; 18 19 public void testReturnInt() { 20 s_log = ""; 21 returnInt(1); 22 assertEquals("afterReturningInt 2", s_log); 23 } 24 25 public void testReturnString() { 26 s_log = ""; 27 returnString("hello"); 28 assertEquals("afterReturningString hellohello", s_log); 29 } 30 31 public void testThrowing() { 32 s_log = ""; 33 try { 34 throwChecked(); 35 } catch (Throwable t) { 36 assertEquals( 38 "afterThrowingExact java.lang.ClassNotFoundException afterThrowingParentClass java.lang.ClassNotFoundException", 39 s_log 40 ); 41 return; 42 } 43 fail("should have encounter an exception"); 44 } 45 46 public int returnInt(int i) { 48 return 2 * i; 49 } 50 51 public String returnString(String s) { 52 return s + s; 53 } 54 55 public void throwChecked() throws ClassNotFoundException { 56 throw new ClassNotFoundException ("checked exception"); 57 } 58 59 public static void log(String msg) { 61 s_log += msg; 62 } 63 64 public static void main(String [] args) { 65 junit.textui.TestRunner.run(suite()); 66 } 67 68 public static junit.framework.Test suite() { 69 return new junit.framework.TestSuite(TestBinding.class); 70 } 71 } 72 | Popular Tags |