public BaseTestMethod(String methodName, ConstructorOrMethod com, IAnnotationFinder annotationFinder, Object instance) { m_methodClass = com.getDeclaringClass(); m_method = com; m_methodName = methodName; m_annotationFinder = annotationFinder; m_instance = instance; }
public BaseTestMethod( String methodName, ConstructorOrMethod com, IAnnotationFinder annotationFinder, Object instance) { m_methodClass = com.getDeclaringClass(); m_method = com; m_methodName = methodName; m_annotationFinder = annotationFinder; m_instance = instance; }
private static Object computeInstance(Object instance, Object inst, ITestNGMethod tm) { if (instance == null || !tm.getConstructorOrMethod().getDeclaringClass().isAssignableFrom(instance.getClass())) { return inst; } return instance; }
/** * {@inheritDoc} */ @Override public void setTestClass(ITestClass tc) { assert null != tc; if (! tc.getRealClass().equals(m_method.getDeclaringClass())) { assert m_method.getDeclaringClass().isAssignableFrom(tc.getRealClass()) : "\nMISMATCH : " + tc.getRealClass() + " " + m_method.getDeclaringClass(); } m_testClass = tc; }
private IConfigurable computeConfigurableInstance(ConstructorOrMethod method, Object targetInstance) { return IConfigurable.class.isAssignableFrom(method.getDeclaringClass()) ? (IConfigurable) targetInstance : m_configuration.getConfigurable(); }
public String getSimpleName() { return m_method.getDeclaringClass().getSimpleName() + "." + m_method.getName(); }
private String computeSignature() { String classLong = m_method.getDeclaringClass().getName(); String cls = classLong.substring(classLong.lastIndexOf(".") + 1); StringBuilder result = new StringBuilder(cls).append(".").append(m_method.getName()).append("("); int i = 0; for (Class<?> p : m_method.getParameterTypes()) { if (i++ > 0) { result.append(", "); } result.append(p.getName()); } result.append(")"); result.append("[pri:").append(getPriority()).append(", instance:").append(m_instance).append("]"); return result.toString(); }
private IConfigurable computeConfigurableInstance( ConstructorOrMethod method, Object targetInstance) { return IConfigurable.class.isAssignableFrom(method.getDeclaringClass()) ? (IConfigurable) targetInstance : m_configuration.getConfigurable(); }
private static Object computeInstance(Object instance, Object inst, ITestNGMethod tm) { if (instance == null || !tm.getConstructorOrMethod().getDeclaringClass().isAssignableFrom(instance.getClass())) { return inst; } return instance; }
@Override public String toString() { ConstructorOrMethod m = getConstructorOrMethod(); String cls = m.getDeclaringClass().getName(); StringBuilder result = new StringBuilder(cls).append(".").append( m.getName()).append("("); int i = 0; for (Class<?> p : m.getParameterTypes()) { if (i++ > 0) { result.append(", "); } result.append(p.getName()); } result.append(")"); return result.toString(); }
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; }
@Override public String toString() { ConstructorOrMethod m = getConstructorOrMethod(); String cls = m.getDeclaringClass().getName(); return BaseTestMethod.stringify(cls, m).toString(); }
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()); }
private String computeSignature() { String classLong = m_method.getDeclaringClass().getName(); String cls = classLong.substring(classLong.lastIndexOf(".") + 1); StringBuilder result = stringify(cls, m_method); result .append("[pri:") .append(getPriority()) .append(", instance:") .append(getInstance()) .append(instanceParameters()) .append("]"); return result.toString(); }
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; }
/** * 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()]); }
@DataProvider(name = "dp1") public static Object[][] createData1(ConstructorOrMethod cOrM) { Assert.assertEquals(cOrM.getDeclaringClass(), ConstructorOrMethodSample.class); Assert.assertNull(cOrM.getMethod()); Assert.assertNotNull(cOrM.getConstructor()); Constructor c = cOrM.getConstructor(); Assert.assertNotNull(c.getAnnotation(Factory.class)); Assert.assertEquals(c.getParameterTypes().length, 1); Assert.assertEquals(c.getParameterTypes()[0], String.class); return new Object[][] {{"0"}, {"1"}}; }
@DataProvider(name = "dp2") public Object[][] createData2(ConstructorOrMethod cOrM) { Assert.assertEquals(cOrM.getDeclaringClass(), ConstructorOrMethodSample.class); Assert.assertNotNull(cOrM.getMethod()); Assert.assertNull(cOrM.getConstructor()); Method m = cOrM.getMethod(); Assert.assertEquals(m.getName(), "test2"); return new Object[][] {{"Cedric" + s}, {"Alois" + s}}; }
private static String constructName(ITestNGMethod method) { return method.getConstructorOrMethod().getDeclaringClass().getSimpleName() + "." + method.getMethodName(); }
protected void initGroups(Class<? extends ITestOrConfiguration> annotationClass) { // // Init groups // { ITestOrConfiguration annotation = getAnnotationFinder().findAnnotation(getConstructorOrMethod(), annotationClass); ITestOrConfiguration classAnnotation = getAnnotationFinder().findAnnotation(getConstructorOrMethod().getDeclaringClass(), annotationClass); setGroups(getStringArray(null != annotation ? annotation.getGroups() : null, null != classAnnotation ? classAnnotation.getGroups() : null)); } // // Init groups depended upon // initRestOfGroupDependencies(annotationClass); }