@@ -48,13 +48,14 @@ KoanSuiteResult runKoans() {
4848 String level = null ;
4949 KoanMethodResult failure = null ;
5050 DynamicClassLoader loader = new DynamicClassLoader ();
51- for (Entry <String , Map <String , Map <String , KoanElementAttributes >>> packages : getPathToEnlightement ()) {
51+ Path pathToEnlightement = getPathToEnlightement ();
52+ for (Entry <String , Map <String , Map <String , KoanElementAttributes >>> packages : pathToEnlightement ) {
5253 for (Entry <String , Map <String , KoanElementAttributes >> e : packages .getValue ().entrySet ()) {
5354 String name = e .getKey ().substring (e .getKey ().lastIndexOf ('.' )+1 );
5455 if (failure == null ){
5556 Object suite = constructSuite (loader , e .getKey ());
5657 final List <KoanElementAttributes > attributes = new ArrayList <KoanElementAttributes >(e .getValue ().values ());
57- final List <KoanMethod > methods = mergeJavaFilesMethodsAndThoseInXml (suite , attributes );
58+ final List <KoanMethod > methods = mergeJavaFilesMethodsAndThoseInXml (suite , attributes , pathToEnlightement . getOnlyMethodNameToRun () );
5859 Collections .sort (methods , new KoanComparator ());
5960 for (final KoanMethod koan : methods ) {
6061 KoanMethodResult result = KoanMethodRunner .run (suite , koan );
@@ -69,38 +70,45 @@ KoanSuiteResult runKoans() {
6970 }
7071 if (failure == null ) {
7172 passingSuites .add (name );
72- } else {
73- level = packages .getKey ();
7473 }
74+ level = packages .getKey ();
7575 }else {
7676 failingSuites .add (name );
7777 }
7878 }
7979 }
8080 return new KoanResultBuilder () .level (level )
8181 .numberPassing ((int )successfull .getCount ())
82- .totalNumberOfKoanMethods (getPathToEnlightement () .getTotalNumberOfKoans ())
82+ .totalNumberOfKoanMethods (pathToEnlightement .getTotalNumberOfKoans ())
8383 .methodResult (failure )
8484 .passingCases (passingSuites ).remainingCases (failingSuites ).build ();
8585 }
8686
8787 private List <KoanMethod > mergeJavaFilesMethodsAndThoseInXml (Object suite ,
88- final List <KoanElementAttributes > attributes ) {
88+ final List <KoanElementAttributes > attributes , String onlyMethodNameToRun ) {
8989 final List <KoanMethod > methods = new ArrayList <KoanMethod >();
9090 final List <String > methodNames = new ArrayList <String >();
9191 for (KoanElementAttributes attributeSet : attributes ){
92- KoanMethod method = KoanMethod .getInstance (attributeSet );
93- methods .add (method );
94- methodNames .add (method .getMethod ().getName ());
92+ if (isMethodEligibleForRunning (onlyMethodNameToRun , attributeSet .name )){
93+ KoanMethod method = KoanMethod .getInstance (attributeSet );
94+ methods .add (method );
95+ methodNames .add (method .getMethod ().getName ());
96+ }
9597 }
9698 for (Method method : suite .getClass ().getMethods ()){
97- if (!methodNames .contains (method .getName ()) && method .getAnnotation (Koan .class ) != null ){
99+ if (!methodNames .contains (method .getName ()) &&
100+ isMethodEligibleForRunning (onlyMethodNameToRun , method .getName ()) &&
101+ method .getAnnotation (Koan .class ) != null ){
98102 methods .add (KoanMethod .getInstance (method ));
99103 }
100104 }
101105 return methods ;
102106 }
103107
108+ private boolean isMethodEligibleForRunning (String onlyMethodNameToRun , String name ) {
109+ return onlyMethodNameToRun == null || onlyMethodNameToRun .equals (name );
110+ }
111+
104112 private Object constructSuite (DynamicClassLoader loader , String className ) {
105113 Object suite ;
106114 try {
0 commit comments