use of org.testng.internal.MethodInstance in project infinispan by infinispan.
the class FakeTestClass method newFailureMethodInstance.
public static MethodInstance newFailureMethodInstance(Exception e, XmlTest xmlTest, ITestContext context, Object instance) {
Method failMethod;
try {
failMethod = TestFrameworkFailure.class.getMethod("fail");
} catch (NoSuchMethodException e1) {
e1.addSuppressed(e);
e1.printStackTrace(System.err);
throw new TestNGException(e1);
}
Class<?> testClass = instance.getClass();
TestFrameworkFailure<?> fakeInstance = new TestFrameworkFailure<>(testClass, e);
TestNGMethod testNGMethod = new TestNGMethod(failMethod, context.getSuite().getAnnotationFinder(), xmlTest, fakeInstance);
ITestClass fakeTestClass = new FakeTestClass(testNGMethod, fakeInstance, xmlTest);
testNGMethod.setTestClass(fakeTestClass);
return new MethodInstance(testNGMethod);
}
use of org.testng.internal.MethodInstance in project infinispan by infinispan.
the class ChainMethodInterceptor method intercept.
@Override
public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context) {
try {
Set<Class<? extends IMethodInterceptor>> interceptorSet = new HashSet<>();
List<Class<? extends IMethodInterceptor>> interceptorList = new ArrayList<>();
Set<Class<? extends Predicate<IMethodInstance>>> filters = new HashSet<>();
for (IMethodInstance method : methods) {
findInterceptors(method.getInstance().getClass(), interceptorSet, interceptorList, filters);
}
if (!filters.isEmpty()) {
List<? extends Predicate<IMethodInstance>> filterInstances = filters.stream().map(clazz -> {
try {
return clazz.getConstructor().newInstance();
} catch (Exception e) {
throw new IllegalStateException("Cannot construct filter", e);
}
}).collect(Collectors.toList());
ArrayList<IMethodInstance> filteredMethods = new ArrayList<>(methods.size());
METHODS: for (IMethodInstance m : methods) {
for (Predicate<IMethodInstance> filter : filterInstances) {
if (hasFilter(m.getInstance().getClass(), filter.getClass()) && !filter.test(m))
continue METHODS;
}
filteredMethods.add(m);
}
methods = filteredMethods;
}
for (Class<? extends IMethodInterceptor> interceptor : interceptorList) {
methods = interceptor.getConstructor().newInstance().intercept(methods, context);
}
return methods;
} catch (Throwable t) {
MethodInstance methodInstance = FakeTestClass.newFailureMethodInstance(new TestNGException(t), context.getCurrentXmlTest(), context, methods.get(0).getInstance());
return Collections.singletonList(methodInstance);
}
}
Aggregations