@Override public ConstructorOrMethod getConstructorOrMethod() { return testNGMethod.getConstructorOrMethod(); }
private static Object computeInstance(Object instance, Object inst, ITestNGMethod tm) { if (instance == null || !tm.getConstructorOrMethod().getDeclaringClass().isAssignableFrom(instance.getClass())) { return inst; } return instance; }
public static ITestNGMethod[] createBeforeConfigurationMethods(ITestNGMethod[] methods, IAnnotationFinder annotationFinder, boolean isBefore, Object instance) { ITestNGMethod[] result = new ITestNGMethod[methods.length]; for(int i = 0; i < methods.length; i++) { result[i] = new ConfigurationMethod(methods[i].getConstructorOrMethod(), annotationFinder, false, false, false, false, false, false, false, false, isBefore ? methods[i].getBeforeGroups() : new String[0], new String[0], instance); } return result; }
public static ITestNGMethod[] createAfterConfigurationMethods(ITestNGMethod[] methods, IAnnotationFinder annotationFinder, boolean isBefore, Object instance) { ITestNGMethod[] result = new ITestNGMethod[methods.length]; for(int i = 0; i < methods.length; i++) { result[i] = new ConfigurationMethod(methods[i].getConstructorOrMethod(), annotationFinder, false, false, false, false, false, false, false, false, new String[0], isBefore ? new String[0] : methods[i].getAfterGroups(), instance); } return result; }
private Set<String> getPackages(ITestContext context) { Set<String> result = Sets.newHashSet(); for (ITestNGMethod m : context.getAllTestMethods()) { Package pkg = m.getConstructorOrMethod().getDeclaringClass().getPackage(); if (pkg != null) { result.add(pkg.getName()); } } return result; }
protected static String calculateMethodCanonicalName(ITestNGMethod m) { return calculateMethodCanonicalName(m.getConstructorOrMethod().getMethod()); }
private void generateExcludedMethodsReport(XmlSuite xmlSuite, ISuite suite) { Collection<ITestNGMethod> excluded = suite.getExcludedMethods(); StringBuilder sb2 = new StringBuilder("<h2>Methods that were not run</h2><table>\n"); for (ITestNGMethod method : excluded) { ConstructorOrMethod m = method.getConstructorOrMethod(); if (m != null) { sb2.append("<tr><td>") .append(m.getDeclaringClass().getName()).append(".").append(m.getName()); String description = method.getDescription(); if(isStringNotEmpty(description)) { sb2.append("<br/>").append(SP2).append("<i>").append(description).append("</i>"); } sb2.append("</td></tr>\n"); } } sb2.append("</table>"); Utils.writeFile(getOutputDirectory(xmlSuite), METHODS_NOT_RUN, sb2.toString()); }
/** * @param result * @param tm * @return true if a method by a similar name (and same hierarchy) already * exists */ private static boolean isMethodAlreadyPresent(List<ITestNGMethod> result, ITestNGMethod tm) { for (ITestNGMethod m : result) { ConstructorOrMethod jm1 = m.getConstructorOrMethod(); ConstructorOrMethod jm2 = tm.getConstructorOrMethod(); if (jm1.getName().equals(jm2.getName())) { // Same names, see if they are in the same hierarchy Class<?> c1 = jm1.getDeclaringClass(); Class<?> c2 = jm2.getDeclaringClass(); if (c1.isAssignableFrom(c2) || c2.isAssignableFrom(c1)) { return true; } } } return false; }
private static MatchResults matchMethod(ITestNGMethod[] methods, String regexp) { MatchResults results = new MatchResults(); boolean usePackage = regexp.indexOf('.') != -1; Pattern pattern = Pattern.compile(regexp); for (ITestNGMethod method : methods) { ConstructorOrMethod thisMethod = method.getConstructorOrMethod(); String thisMethodName = thisMethod.getName(); String methodName = usePackage ? calculateMethodCanonicalName(method) : thisMethodName; Pair<String, String> cacheKey = Pair.create(regexp, methodName); Boolean match = MATCH_CACHE.get(cacheKey); if (match == null) { match = pattern.matcher(methodName).matches(); MATCH_CACHE.put(cacheKey, match); } if (match) { results.matchedMethods.add(method); results.foundAtLeastAMethod = true; } } return results; }
private Set<String> getPackages(ITestContext context) { Set<String> result = Sets.newHashSet(); for (ITestNGMethod m : context.getAllTestMethods()) { Package pkg = m.getConstructorOrMethod().getDeclaringClass().getPackage(); if (pkg != null) { result.add(pkg.getName()); } } return result; }
/** * 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; } }
/** * 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)); }
private static String constructName(ITestNGMethod method) { return method.getConstructorOrMethod().getDeclaringClass().getSimpleName() + "." + method.getMethodName(); }
/** 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)); } }
private void logResult(String status, ITestResult tr, String stackTrace) { logResult(status, tr.getName(), tr.getMethod().getDescription(), stackTrace, tr.getParameters(), tr.getMethod().getConstructorOrMethod().getParameterTypes()); }
Method testMethod = testResult.getMethod().getConstructorOrMethod().getMethod(); boolean beforeCallbacksExecuted = false;
/** Returns the name of the executed test. */ private static String getTestName(IInvokedMethod method) { return StringUtils.substringAfterLast(method.getTestMethod().getTestClass().getName(), ".") + "#" + method.getTestMethod().getConstructorOrMethod().getName(); }