KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > mockobjects > dynamic > DynamicUtilTest


1 /*
2  * Created on 16-Apr-2003
3  */

4 package test.mockobjects.dynamic;
5
6 import com.mockobjects.dynamic.DynamicUtil;
7 import com.mockobjects.dynamic.Mock;
8 import com.mockobjects.util.AssertMo;
9
10 import junit.framework.TestCase;
11
12 /**
13  * @author e2x
14  */

15 public class DynamicUtilTest extends TestCase {
16
17     public DynamicUtilTest(String JavaDoc name) {
18         super(name);
19     }
20     
21     public void testMethodToStringWithoutProxyArg() throws Exception JavaDoc {
22         String JavaDoc[] args = new String JavaDoc[] {"arg1", "arg2" };
23     
24         String JavaDoc result = DynamicUtil.methodToString("methodName", args);
25         
26         AssertMo.assertIncludes("Should contain method name", "methodName", result);
27         AssertMo.assertIncludes("Should contain firstArg", "arg1", result);
28         AssertMo.assertIncludes("Should contain second Arg", "arg2", result);
29     }
30     
31     public void testMethodToStringWithStringArray() throws Exception JavaDoc {
32             Object JavaDoc[] args = new Object JavaDoc[] { new String JavaDoc[] {"arg1","arg2"}};
33     
34             String JavaDoc result = DynamicUtil.methodToString("methodName", args);
35         
36             AssertMo.assertIncludes("Should contain method name", "methodName", result);
37             AssertMo.assertIncludes("Should contain args as an array", "[<arg1>, <arg2>]", result);
38         }
39         
40     public void testMethodToStringWithPrimitiveArray() throws Exception JavaDoc {
41             Object JavaDoc[] args = new Object JavaDoc[] { new long[] {1,2}};
42     
43             String JavaDoc result = DynamicUtil.methodToString("methodName", args);
44         
45             AssertMo.assertIncludes("Should contain method name", "methodName", result);
46             AssertMo.assertIncludes("Should contain args as an array", "[<1>, <2>]", result);
47         }
48     
49     public void testMethodToStringWithProxyArg() throws Exception JavaDoc {
50         Mock mockDummyInterface = new Mock(DummyInterface.class, "DummyMock");
51         Object JavaDoc[] args = new Object JavaDoc[] {"arg1", mockDummyInterface.proxy()};
52     
53         String JavaDoc result = DynamicUtil.methodToString("methodName", args);
54         
55         AssertMo.assertIncludes("Should contain method name", "methodName", result);
56         AssertMo.assertIncludes("Should contain firstArg", "arg1", result);
57         AssertMo.assertIncludes("Should contain second Arg", "DummyMock", result);
58     }
59
60 }
61
Popular Tags