@@ -72,30 +72,34 @@ static Map<Object, List<KoanMethod>> createSuitesAndKoans(String pkg, NodeList c
7272 }
7373
7474 static List <KoanMethod > createKoanMethods (Class <?> koanSuiteClass , NodeList nodes ) {
75- Map <String , String > rawKoanLessonByMethodName = extractKoansAndRawLessons (koanSuiteClass .getName (), nodes );
75+ Map <String , KoanElementAttributes > rawKoanLessonByMethodName = extractKoansAndRawLessons (koanSuiteClass .getName (), nodes );
7676 List <KoanMethod > koanMethods = getKoanMethods (koanSuiteClass , rawKoanLessonByMethodName );
7777 KoanComparator koanComparator = new KoanComparator (rawKoanLessonByMethodName .keySet ());
7878 Collections .sort (koanMethods , koanComparator );
7979 assertXmlAndCodeAreInSynch (nodes , koanMethods , koanComparator );
8080 return koanMethods ;
8181 }
8282
83- static Map <String , String > extractKoansAndRawLessons (
83+ static Map <String , KoanElementAttributes > extractKoansAndRawLessons (
8484 String className , NodeList nodes ) {
85- Map <String , String > rawKoanLessonByMethodName = new LinkedHashMap <String , String >();
85+ Map <String , KoanElementAttributes > rawKoanAttributesByMethodName = new LinkedHashMap <String , KoanElementAttributes >();
8686 for (int i = 0 ; i < nodes .getLength (); i ++){
8787 Node node = nodes .item (i );
8888 if ("Koan" .equalsIgnoreCase (node .getNodeName ())){
8989 NamedNodeMap attributes = node .getAttributes ();
9090 String name = attributes .getNamedItem ("name" ).getNodeValue ();
9191 String rawLesson = attributes .getNamedItem ("lesson" ).getNodeValue ();
92- if (rawKoanLessonByMethodName .containsKey (name )){
92+ Node displayKoanIncompleteExceptionNode = attributes .getNamedItem ("displayIncompleteKoanException" );
93+ String displayIncompleteKoanException = displayKoanIncompleteExceptionNode == null ?
94+ null : displayKoanIncompleteExceptionNode .getNodeValue ();
95+ if (rawKoanAttributesByMethodName .containsKey (name )){
9396 throw new DuplicateKoanException (className , name );
9497 }
95- rawKoanLessonByMethodName .put (name , rawLesson );
98+ rawKoanAttributesByMethodName .put (name , new KoanElementAttributes (
99+ rawLesson , name , displayIncompleteKoanException ));
96100 }
97101 }
98- return rawKoanLessonByMethodName ;
102+ return rawKoanAttributesByMethodName ;
99103 }
100104
101105 static class DuplicateKoanException extends RuntimeException {
@@ -117,15 +121,28 @@ static void assertXmlAndCodeAreInSynch(NodeList csvOrder,
117121 }
118122 }
119123
120- static List <KoanMethod > getKoanMethods (Class <?> koanSuiteClass , Map <String , String > lessonByKoanName ) {
124+ static List <KoanMethod > getKoanMethods (Class <?> koanSuiteClass , Map <String , KoanElementAttributes > attributesByKoanName ) {
121125 List <KoanMethod > koanMethods = new ArrayList <KoanMethod >();
122126 for (final Method koan : koanSuiteClass .getMethods ()){
123127 final Koan annotation = koan .getAnnotation (Koan .class );
124128 if (annotation != null ){
125- koanMethods .add (new KoanMethod (lessonByKoanName .get (koan .getName ()), koan ));
129+ KoanElementAttributes koanMethodAttributes = attributesByKoanName .get (koan .getName ());
130+ String incompleteKoanException = koanMethodAttributes .displayIncompleteKoanException ;
131+ boolean displayIncompleteKoanException = incompleteKoanException == null ||
132+ "true" .equalsIgnoreCase (incompleteKoanException .trim ());
133+ koanMethods .add (new KoanMethod (koanMethodAttributes .lesson , koan , displayIncompleteKoanException ));
126134 }
127135 }
128136 return koanMethods ;
129137 }
138+
139+ static class KoanElementAttributes {
140+ String lesson , name , displayIncompleteKoanException ;
141+ public KoanElementAttributes (String lesson , String name , String displayIncompleteKoanException ){
142+ this .lesson = lesson ;
143+ this .name = name ;
144+ this .displayIncompleteKoanException = displayIncompleteKoanException ;
145+ }
146+ }
130147}
131148
0 commit comments