/** * {@inheritDoc} */ @Override public Method getMethod() { return m_method.getMethod(); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; ConstructorOrMethod other = (ConstructorOrMethod) obj; if (getConstructor() == null) { if (other.getConstructor() != null) return false; } else if (!getConstructor().equals(other.getConstructor())) return false; if (getMethod() == null) { if (other.getMethod() != null) return false; } else if (!getMethod().equals(other.getMethod())) return false; return true; }
@Override public <A extends IAnnotation> A findAnnotation(ConstructorOrMethod com, Class<A> annotationClass) { if (com.getConstructor() != null) { return findAnnotation(com.getConstructor(), annotationClass); } if (com.getMethod() != null) { return findAnnotation(com.getMethod(), annotationClass); } return null; }
protected static String calculateMethodCanonicalName(ITestNGMethod m) { return calculateMethodCanonicalName(m.getConstructorOrMethod().getMethod()); }
private void runOne() { try { RuntimeException t = null; try { ConstructorOrMethod m = m_method.getConstructorOrMethod(); if (m_hookable == null) { MethodInvocationHelper.invokeMethod(m.getMethod(), m_instance, m_parameters); } else { MethodInvocationHelper.invokeHookable(m_instance, m_parameters, m_hookable, m.getMethod(), m_testResult); } } catch(Throwable e) { t = new TestNGRuntimeException(e.getCause()); } if(null != t) { Thread.currentThread().interrupt(); throw t; } } finally { m_method.incrementCurrentInvocationCount(); } }
private String findDescription(ITestAnnotation testAnnotation, XmlTest xmlTest) { String result = testAnnotation.getDescription(); if (result == null) { List<XmlClass> classes = xmlTest.getXmlClasses(); for (XmlClass c : classes) { if (c.getName().equals(m_method.getMethod().getDeclaringClass().getName())) { for (XmlInclude include : c.getIncludedMethods()) { if (include.getName().equals(m_method.getName())) { result = include.getDescription(); if (result != null) { break; } } } } } } return result; }
/** * Create the test methods that belong to this class (rejects * all those that belong to a different class). */ private ITestNGMethod[] createTestMethods(ITestNGMethod[] methods) { List<ITestNGMethod> vResult = Lists.newArrayList(); for (ITestNGMethod tm : methods) { ConstructorOrMethod m = tm.getConstructorOrMethod(); if (m.getDeclaringClass().isAssignableFrom(m_testClass)) { for (Object o : iClass.getInstances(false)) { log(4, "Adding method " + tm + " on TestClass " + m_testClass); vResult.add(new TestNGMethod(/* tm.getRealClass(), */ m.getMethod(), annotationFinder, xmlTest, o)); } } else { log(4, "Rejecting method " + tm + " for TestClass " + m_testClass); } } return vResult.toArray(new ITestNGMethod[vResult.size()]); }
public static MethodParameters newInstance(Map<String, String> params, ITestNGMethod testNGMethod, ITestContext context) { Map<String, String> methodParams = testNGMethod.findMethodParameters(context.getCurrentXmlTest()); Object[] pv = null; ITestResult tr = null; Method method = testNGMethod.getConstructorOrMethod().getMethod(); return new MethodParameters(params, methodParams, pv, method, context, tr); }
/** Checks the writer if {@link CheckNoWriter} is found. */ private static void checkWriter(ITestResult testResult, CacheContext context) { Method testMethod = testResult.getMethod().getConstructorOrMethod().getMethod(); CheckNoWriter checkWriter = testMethod.getAnnotation(CheckNoWriter.class); if (checkWriter == null) { return; } assertThat("Test requires CacheContext param for validation", context, is(not(nullValue()))); verifyWriter(context, (verifier, writer) -> verifier.zeroInteractions()); }
/** Checks the statistics if {@link CheckNoStats} is found. */ private static void checkNoStats(ITestResult testResult, CacheContext context) { Method testMethod = testResult.getMethod().getConstructorOrMethod().getMethod(); boolean checkNoStats = testMethod.isAnnotationPresent(CheckNoStats.class); if (!checkNoStats) { return; } assertThat("Test requires CacheContext param for validation", context, is(not(nullValue()))); assertThat(context, hasHitCount(0)); assertThat(context, hasMissCount(0)); assertThat(context, hasLoadSuccessCount(0)); assertThat(context, hasLoadFailureCount(0)); }
public static MethodParameters newInstance( Map<String, String> params, ITestNGMethod testNGMethod, ITestContext context) { Map<String, String> methodParams = testNGMethod.findMethodParameters(context.getCurrentXmlTest()); Method method = testNGMethod.getConstructorOrMethod().getMethod(); return new MethodParameters(params, methodParams, null, method, context, null); }
protected static void invokeMethodConsideringTimeout(ITestNGMethod tm, ConstructorOrMethod method, Object targetInstance, Object[] params, ITestResult testResult) throws Throwable { if (MethodHelper.calculateTimeOut(tm) <= 0) { MethodInvocationHelper.invokeMethod(method.getMethod(), targetInstance, params); } else { MethodInvocationHelper.invokeWithTimeout(tm, targetInstance, params, testResult); if (!testResult.isSuccess()) { // A time out happened Throwable ex = testResult.getThrowable(); testResult.setStatus(ITestResult.FAILURE); testResult.setThrowable(ex.getCause() == null ? ex : ex.getCause()); throw testResult.getThrowable(); } } }
/** * Store the result of parameterTypes and optionalValues after filter out injected types */ final static class FilterOutInJectedTypesResult { private Class<?>[] parameterTypes; private String[] optionalValues; private FilterOutInJectedTypesResult(Class<?>[] parameterTypes, String[] optionalValues) { this.parameterTypes = parameterTypes; this.optionalValues = optionalValues; } Class<?>[] getParameterTypes() { return parameterTypes; } String[] getOptionalValues() { return optionalValues; } }
/** Checks whether the {@link TrackingExecutor} had unexpected failures. */ private static void checkExecutor(ITestResult testResult, CacheContext context) { Method testMethod = testResult.getMethod().getConstructorOrMethod().getMethod(); CacheSpec cacheSpec = testMethod.getAnnotation(CacheSpec.class); if (cacheSpec == null) { return; } assertThat("CacheContext required", context, is(not(nullValue()))); if (!(context.executor() instanceof TrackingExecutor)) { return; } TrackingExecutor executor = (TrackingExecutor) context.executor(); if (cacheSpec.executorFailure() == ExecutorFailure.EXPECTED) { assertThat(executor.failureCount(), is(greaterThan(0))); } else if (cacheSpec.executorFailure() == ExecutorFailure.DISALLOWED) { assertThat(executor.failureCount(), is(0)); } }
Method testMethod = testResult.getMethod().getConstructorOrMethod().getMethod(); boolean beforeCallbacksExecuted = false;