use of org.junit.runners.model.FrameworkMethod in project hazelcast by hazelcast.
the class AbstractHazelcastClassRunner method withBefores.
// Override withBefores to accommodate spawning the member bouncing thread after @Before's have been executed and before @Test
// when MemberBounceRule is in use
@Override
protected Statement withBefores(FrameworkMethod method, Object target, Statement statement) {
List<FrameworkMethod> befores = getTestClass().getAnnotatedMethods(Before.class);
List<TestRule> testRules = getTestRules(target);
Statement nextStatement = statement;
if (!testRules.isEmpty()) {
for (TestRule rule : testRules) {
if (rule instanceof BounceMemberRule) {
nextStatement = ((BounceMemberRule) rule).startBouncing(statement);
}
}
}
return befores.isEmpty() ? nextStatement : new RunBefores(nextStatement, befores, target);
}
use of org.junit.runners.model.FrameworkMethod in project hazelcast by hazelcast.
the class AbstractHazelcastClassRunner method withAfters.
@Override
protected Statement withAfters(FrameworkMethod method, Object target, Statement statement) {
List<FrameworkMethod> afters = getTestClass().getAnnotatedMethods(After.class);
Statement nextStatement = statement;
List<TestRule> testRules = getTestRules(target);
if (!testRules.isEmpty()) {
for (TestRule rule : testRules) {
if (rule instanceof BounceMemberRule) {
nextStatement = ((BounceMemberRule) rule).stopBouncing(statement);
}
}
}
if (THREAD_DUMP_ON_FAILURE) {
return new ThreadDumpAwareRunAfters(method, nextStatement, afters, target);
}
if (afters.isEmpty()) {
return nextStatement;
} else {
return new RunAfters(nextStatement, afters, target);
}
}
use of org.junit.runners.model.FrameworkMethod in project hibernate-orm by hibernate.
the class CustomParameterized method getParametersMethods.
private List<FrameworkMethod> getParametersMethods() throws Exception {
List<FrameworkMethod> methods = getTestClass().getAnnotatedMethods(Parameterized.Parameters.class);
SortedMap<Integer, FrameworkMethod> sortedMethods = new TreeMap<Integer, FrameworkMethod>();
for (FrameworkMethod each : methods) {
if (each.isPublic()) {
if (!each.isStatic()) {
if (getTestClass().getOnlyConstructor().getParameterCount() != 0) {
throw new Exception("Method " + each.getMethod() + " is annotated with @Parameters, it is not static and there is no parameter-less constructor!");
}
}
Order order = each.getAnnotation(Order.class);
int value = order == null ? 0 : order.value();
FrameworkMethod prev = sortedMethods.put(value, each);
if (prev != null) {
throw new Exception(String.format("There are more methods annotated with @Parameters and @Order(value=%d): %s (%s) and %s (%s)", value, prev.getMethod(), prev.getAnnotation(Order.class), each.getMethod(), order));
}
} else {
throw new Exception("Method " + each.getMethod() + " is annotated with @Parameters but it is not public!");
}
}
if (sortedMethods.isEmpty()) {
throw new Exception("No public static parameters method on class " + getTestClass().getName());
}
return new ArrayList<FrameworkMethod>(sortedMethods.values());
}
use of org.junit.runners.model.FrameworkMethod in project hibernate-orm by hibernate.
the class CustomParameterized method allParameters.
private Iterable<Object[]> allParameters(List<FrameworkMethod> parametersMethods) throws Throwable {
ArrayList<Iterable<Object[]>> returnedParameters = new ArrayList<Iterable<Object[]>>();
ArrayList<Object[]> allParameters = new ArrayList<Object[]>();
Object cachedInstance = null;
for (FrameworkMethod method : parametersMethods) {
Object parameters;
if (method.isStatic()) {
parameters = method.invokeExplosively(null);
} else {
if (cachedInstance == null) {
cachedInstance = getTestClass().getOnlyConstructor().newInstance();
}
parameters = method.invokeExplosively(cachedInstance);
}
if (parameters instanceof Iterable) {
returnedParameters.add((Iterable<Object[]>) parameters);
} else {
throw parametersMethodReturnedWrongType(method);
}
}
for (Iterable<Object[]> parameters : returnedParameters) {
if (allParameters.isEmpty()) {
for (Object[] array : parameters) {
allParameters.add(array);
}
} else {
ArrayList<Object[]> newAllParameters = new ArrayList<Object[]>();
for (Object[] prev : allParameters) {
for (Object[] array : parameters) {
Object[] next = Arrays.copyOf(prev, prev.length + array.length);
System.arraycopy(array, 0, next, prev.length, array.length);
newAllParameters.add(next);
}
}
allParameters = newAllParameters;
}
}
return allParameters;
}
use of org.junit.runners.model.FrameworkMethod in project spring-framework by spring-projects.
the class SpringJUnit4ClassRunnerTests method getSpringTimeoutViaMetaAnnotation.
@Test
public void getSpringTimeoutViaMetaAnnotation() throws Exception {
SpringJUnit4ClassRunner runner = new SpringJUnit4ClassRunner(getClass());
long timeout = runner.getSpringTimeout(new FrameworkMethod(getClass().getDeclaredMethod("springTimeoutWithMetaAnnotation")));
assertEquals(10, timeout);
}
Aggregations