nl.hsac.fitnesse.slim.interaction.ReflectionHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hsac-fitnesse-fixtures Show documentation
Show all versions of hsac-fitnesse-fixtures Show documentation
Fixtures to assist in testing via FitNesse
package nl.hsac.fitnesse.slim.interaction;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class ReflectionHelper {
private ReflectionHelper() {}
public static Set validateMethodNames(Class> clazz, String... names) {
HashSet result = new HashSet(Arrays.asList(names));
Method[] allMethods = clazz.getMethods();
List methodsNotMentioned = new ArrayList(allMethods.length);
for (Method method : allMethods) {
methodsNotMentioned.add(method.getName());
}
List notFound = new ArrayList(0);
for (String methodName : result) {
if (!methodsNotMentioned.contains(methodName)) {
notFound.add(methodName);
} else {
methodsNotMentioned.remove(methodName);
}
}
if (!notFound.isEmpty()) {
throw new RuntimeException("Unable to locate methods: " + notFound);
}
return result;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy