org.sahagin.runlib.additionaltestdoc.AdditionalTestDocs Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sahagin Show documentation
Show all versions of sahagin Show documentation
Sahagin makes your Selenium script more readable and maintainable.
package org.sahagin.runlib.additionaltestdoc;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.sahagin.share.srctree.TestMethod;
public class AdditionalTestDocs {
private List classTestDocs
= new ArrayList(128);
private List methodTestDocs
= new ArrayList(256);
public List getClassTestDocs() {
return classTestDocs;
}
public void classAdd(AdditionalClassTestDoc classTestDoc) {
classTestDocs.add(classTestDoc);
}
public List getMethodTestDocs() {
return methodTestDocs;
}
public void methodAdd(AdditionalMethodTestDoc methodTestDoc) {
methodTestDocs.add(methodTestDoc);
}
// returns null if not found
public AdditionalClassTestDoc getClassTestDoc(String qualifiedClassName) {
if (qualifiedClassName == null) {
throw new NullPointerException();
}
// last set data is referred first
for (int i = classTestDocs.size() - 1; i >= 0; i--) {
AdditionalClassTestDoc classTestDoc = classTestDocs.get(i);
if (qualifiedClassName.equals(classTestDoc.getQualifiedName())) {
return classTestDoc;
}
}
return null;
}
// returns null if not found
// TODO delegation should work for not additional TestDoc
public AdditionalMethodTestDoc getMethodTestDoc(String classQualifiedName,
String methodSimpleName, List argClassQualifiedNames) {
if (classQualifiedName == null) {
throw new NullPointerException();
}
if (methodSimpleName == null) {
throw new NullPointerException();
}
if (argClassQualifiedNames == null) {
throw new NullPointerException();
}
for (int i = 0; i < methodTestDocs.size(); i++) {
AdditionalMethodTestDoc methodTestDoc = methodTestDocs.get(i);
if (matchesToMethodTestDoc(methodTestDoc,
classQualifiedName, methodSimpleName, argClassQualifiedNames)) {
return methodTestDoc;
}
}
return null;
}
private boolean matchesToMethodTestDoc(AdditionalMethodTestDoc methodTestDoc,
String classQualifiedName, String methodSimpleName, List argClassQualifiedNames) {
if (StringUtils.equals(methodTestDoc.getClassQualifiedName(), classQualifiedName)
&& StringUtils.equals(methodTestDoc.getSimpleName(), methodSimpleName)) {
if (!methodTestDoc.isOverloaded()) {
return true; // ignore method argument classes difference
}
String methodKey = TestMethod.generateMethodKey(
classQualifiedName, methodSimpleName, argClassQualifiedNames);
String testDocMethodKey = TestMethod.generateMethodKey(
methodTestDoc.getClassQualifiedName(),
methodTestDoc.getSimpleName(), methodTestDoc.getArgClassesStr());
if (methodKey.equals(testDocMethodKey)) {
return true;
}
}
return false;
}
public void clear() {
classTestDocs.clear();
methodTestDocs.clear();
}
}