Skip to content

Instantly share code, notes, and snippets.

@swegner
Created May 10, 2016 16:13
Show Gist options
  • Save swegner/d6425e703d10d82600d0e98319257c82 to your computer and use it in GitHub Desktop.
Save swegner/d6425e703d10d82600d0e98319257c82 to your computer and use it in GitHub Desktop.
@Test
public void testPrefix() throws IOException {
ClassPath cp = ClassPath.from(ClassLoader.getSystemClassLoader());
Set<ClassPath.ClassInfo> classes = cp.getAllClasses();
int prefixed = 0;
int unPrefixed = 0;
for (ClassPath.ClassInfo classInfo : classes) {
Class<?> clazz;
if (!classInfo.getPackageName().startsWith("org.apache.beam")) {
continue;
}
try {
clazz = classInfo.load();
} catch (NoClassDefFoundError e) {
System.err.println(String.format("Failed to load class %s: %s", classInfo.getName(), e));
continue;
}
for (Method method : clazz.getDeclaredMethods()) {
if (method.isAnnotationPresent(Test.class)) {
if (method.getName().startsWith("test")) {
prefixed++;
} else
unPrefixed++;
}
}
}
System.out.println(String.format("Prefixed: %d, Unprefixed: %d", prefixed, unPrefixed));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment