01: /*-
02: * See the file LICENSE for redistribution information.
03: *
04: * Copyright (c) 2002,2008 Oracle. All rights reserved.
05: *
06: * $Id: JUnitMethodThread.java,v 1.5.2.3 2008/01/07 15:14:28 cwl Exp $
07: */
08:
09: package com.sleepycat.je.junit;
10:
11: import java.lang.reflect.Method;
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 method;
22: private Object param;
23:
24: public JUnitMethodThread(String threadName, String methodName,
25: TestCase testCase) throws NoSuchMethodException {
26:
27: this (threadName, methodName, testCase, null);
28: }
29:
30: public JUnitMethodThread(String threadName, String methodName,
31: TestCase testCase, Object param)
32: throws NoSuchMethodException {
33:
34: super (threadName);
35: this .testCase = testCase;
36: this .param = param;
37: method = testCase.getClass()
38: .getMethod(methodName, new Class[0]);
39: }
40:
41: public void testBody() throws Exception {
42:
43: if (param != null) {
44: method.invoke(testCase, new Object[] { param });
45: } else {
46: method.invoke(testCase, new Object[0]);
47: }
48: }
49: }
|