KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > junit > JUnitMethodThread


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: JUnitMethodThread.java,v 1.5 2006/10/30 21:14:45 bostic Exp $
7  */

8
9 package com.sleepycat.je.junit;
10
11 import java.lang.reflect.Method JavaDoc;
12
13 import junit.framework.TestCase;
14     
15 /**
16  * A JUnitThread whose testBody calls a given TestCase method.
17  */

18 public class JUnitMethodThread extends JUnitThread {
19     
20     private TestCase testCase;
21     private Method JavaDoc method;
22     private Object JavaDoc param;
23
24     public JUnitMethodThread(String JavaDoc threadName, String JavaDoc methodName,
25                              TestCase testCase)
26         throws NoSuchMethodException JavaDoc {
27
28         this(threadName, methodName, testCase, null);
29     }
30
31     public JUnitMethodThread(String JavaDoc threadName, String JavaDoc methodName,
32                              TestCase testCase, Object JavaDoc param)
33         throws NoSuchMethodException JavaDoc {
34
35         super(threadName);
36         this.testCase = testCase;
37         this.param = param;
38         method = testCase.getClass().getMethod(methodName, new Class JavaDoc[0]);
39     }
40
41     public void testBody()
42         throws Exception JavaDoc {
43
44         if (param != null) {
45             method.invoke(testCase, new Object JavaDoc[] { param });
46         } else {
47             method.invoke(testCase, new Object JavaDoc[0]);
48         }
49     }
50 }
51
Popular Tags