List<String> passingSuites = new ArrayList<String>();
List<String> failingSuites = new ArrayList<String>();
String level = null;
KoanMethodResult failure = null;
DynamicClassLoader loader = KoanClassLoader.getInstance();
Path pathToEnlightenment = getPathToEnlightenment();
KoanSuiteCompilationListener compilationListener = new KoanSuiteCompilationListener();
int successfull = 0;
for (Entry<String, Map<String, Map<String, KoanElementAttributes>>> packages : pathToEnlightenment) {
for (Entry<String, Map<String, KoanElementAttributes>> e : packages.getValue().entrySet()) {
String name = e.getKey().substring(e.getKey().lastIndexOf('.')+1);
if(failure == null){
Object suite = safelyConstructSuite(loader, compilationListener, e);
final List<KoanElementAttributes> attributes = new ArrayList<KoanElementAttributes>(e.getValue().values());
final List<KoanMethod> methods = mergeJavaFilesMethodsAndThoseInXml(suite, attributes, pathToEnlightenment.getOnlyMethodNameToRun());
Collections.sort(methods, new KoanComparator());
for (final KoanMethod koan : methods) {
KoanMethodResult result = KoanMethodRunner.run(suite, koan);
if(KoanMethodResult.PASSED != result){
// Test failed!
failure = result;
failingSuites.add(name);
break;
}else{
successfull++;
}
}
if (failure == null) {
passingSuites.add(name);
}
level = packages.getKey();
}else{
failingSuites.add(name);
}
}
}
return new KoanResultBuilder()
.level(level)
.numberPassing(successfull)
.totalNumberOfKoanMethods(pathToEnlightenment.getTotalNumberOfKoans())
.methodResult(failure).passingCases(passingSuites)
.remainingCases(failingSuites).build();
}