KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > pojo > util > MethodCallTest


1 /*
2  * JBoss, Home of Professional Open Source
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 package org.jboss.cache.pojo.util;
9
10 import junit.framework.Test;
11 import junit.framework.TestCase;
12 import junit.framework.TestSuite;
13 import org.apache.commons.logging.Log;
14 import org.apache.commons.logging.LogFactory;
15
16 import java.lang.reflect.Method JavaDoc;
17
18 /**
19  * @author Ben Wang
20  */

21
22 public class MethodCallTest extends TestCase
23 {
24    Log log_ = LogFactory.getLog(MethodCallTest.class);
25
26    public MethodCallTest(String JavaDoc name)
27    {
28       super(name);
29    }
30
31    protected void setUp() throws Exception JavaDoc
32    {
33       super.setUp();
34       log_.info("setUp() ....");
35    }
36
37    protected void tearDown() throws Exception JavaDoc
38    {
39       super.tearDown();
40    }
41
42 // public void testDummy() {}
43

44    public void testBasic() throws Throwable JavaDoc
45    {
46       Integer JavaDoc i = 1;
47       Method JavaDoc method = Foo.class.getDeclaredMethod("setFoo",
48               new Class JavaDoc[]{Integer JavaDoc.class});
49
50       Object JavaDoc[] args = new Object JavaDoc[]{i};
51       Foo foo = new Foo();
52       MethodCall mc = new MethodCall(method, args, foo);
53
54       mc.invoke();
55    }
56
57    public static Test suite() throws Exception JavaDoc
58    {
59       return new TestSuite(MethodCallTest.class);
60    }
61
62
63    public static void main(String JavaDoc[] args) throws Exception JavaDoc
64    {
65       junit.textui.TestRunner.run(MethodCallTest.suite());
66    }
67
68    public static class Foo
69    {
70       Integer JavaDoc i;
71
72       public void setFoo(Integer JavaDoc i)
73       {
74          this.i = i;
75       }
76
77       public Integer JavaDoc getFoo()
78       {
79          return i;
80       }
81    }
82 }
83
Popular Tags