1 8 package test.callAndExecution; 9 10 import junit.framework.TestCase; 11 12 15 public class CallExecutionTest extends TestCase implements Intf { 16 private static String s_logString = ""; 17 18 public CallExecutionTest() { 19 } 20 21 public CallExecutionTest(String name) { 22 super(name); 23 } 24 25 public void testPrivateMethod() { 26 s_logString = ""; 27 privateMethod(); 28 assertEquals("call1 execution1 invocation execution2 call2 ", s_logString); 29 } 30 31 public void testPublicMethod() { 32 s_logString = ""; 33 publicMethod(); 34 assertEquals("call1 execution1 invocation execution2 call2 ", s_logString); 35 } 36 37 public void testIntfMethod() { 38 s_logString = ""; 40 Intf me = new CallExecutionTest(); 41 me.called(); 42 me.called(1); 43 assertEquals("call1 execution1 invocation execution2 call2 ", s_logString); 44 45 s_logString = ""; 46 CallExecutionTest me2 = new CallExecutionTest(); 47 me2.called(); 48 me2.called(1); 49 assertEquals("call1 execution1 invocation execution2 call2 ", s_logString); 50 } 51 52 public void testAbstractMethod() { 53 s_logString = ""; 55 Abstract me = new Abstract.AbstractImpl(); 56 me.called(); 57 assertEquals("call1 execution1 invocation execution2 call2 ", s_logString); 58 59 s_logString = ""; 60 Abstract.AbstractImpl me2 = new Abstract.AbstractImpl(); 61 me2.called(); 62 assertEquals("call1 execution1 invocation execution2 call2 ", s_logString); 63 } 64 65 public static void main(String [] args) { 66 junit.textui.TestRunner.run(suite()); 67 } 68 69 public static junit.framework.Test suite() { 70 return new junit.framework.TestSuite(CallExecutionTest.class); 71 } 72 73 public static void log(final String wasHere) { 75 s_logString += wasHere; 76 } 77 78 private void privateMethod() { 79 log("invocation "); 80 } 81 82 public void publicMethod() { 83 log("invocation "); 84 } 85 86 public void called() { 87 log("invocation "); 89 } 90 91 public void called(int i) { 92 } 95 } | Popular Tags |