1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
/***************************************************************************
* Copyright (c) 2004 - 2007 Eike Stepper, Germany.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Eike Stepper - initial API and implementation
**************************************************************************/
package org.eclipse.emf.cdo.tests;
import org.eclipse.net4j.tests.AbstractOMTest;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
* @author Eike Stepper
*/
public class TDD
{
private static final AbstractOMTest test = new InvalidationTest();
private static final String METHOD_NAME = "testSeparateView";
public static void main(String[] args) throws Throwable
{
if (METHOD_NAME != null && METHOD_NAME.length() != 0)
{
runTest(test, METHOD_NAME);
}
else
{
Method[] methods = test.getClass().getMethods();
for (Method method : methods)
{
String methodName = method.getName();
if (methodName.startsWith("test"))
{
runTest(test, methodName);
}
}
}
System.out.println("******* COMPLETED *******");
}
private static void runTest(AbstractOMTest test, String methodName) throws Exception, Throwable
{
test.setName(methodName);
test.setUp();
callMethod(test, methodName);
test.tearDown();
}
private static void callMethod(Object object, String methodName) throws Throwable
{
try
{
Method method = object.getClass().getMethod(methodName, new Class[0]);
method.invoke(object, new Object[0]);
}
catch (InvocationTargetException ex)
{
throw filterException(ex.getTargetException(), object.getClass());
}
}
private static Throwable filterException(Throwable t, Class<? extends Object> entry)
{
StackTraceElement[] stackTrace = t.getStackTrace();
int len;
for (len = stackTrace.length - 1; len >= 0; len--)
{
if (stackTrace[len].getClassName().equals(entry.getName()))
{
StackTraceElement[] filtered = new StackTraceElement[++len];
System.arraycopy(stackTrace, 0, filtered, 0, len);
t.setStackTrace(filtered);
break;
}
}
return t;
}
}
|