@@ -11,6 +11,7 @@ public class KoanMethod {
1111 private final transient Method method ;
1212 private final String lesson ;
1313 private final boolean displayIncompleteException ;
14+ private final boolean requiresAssertion ;
1415 private static final KoanSuiteCompilationListener listener = new KoanSuiteCompilationListener ();
1516
1617 private KoanMethod (KoanElementAttributes koanAttributes ) throws SecurityException , NoSuchMethodException {
@@ -26,27 +27,33 @@ public static KoanMethod getInstance(KoanElementAttributes koanAttributes){
2627 }
2728
2829 public static KoanMethod getInstance (Method method ){
29- return new KoanMethod (null , method , true );
30+ return new KoanMethod (null , method , true , true );
31+ }
32+
33+ public static KoanMethod getInstance (Method method , boolean requiresAssertion ){
34+ return new KoanMethod (null , method , true , requiresAssertion );
3035 }
3136
3237 public static KoanMethod getInstance (String lesson , Method method ){
33- return new KoanMethod (lesson , method , true );
38+ return new KoanMethod (lesson , method , true , true );
3439 }
3540
36- private KoanMethod (String lesson , Method method , boolean displayIncompleteException ){
41+ private KoanMethod (String lesson , Method method , boolean displayIncompleteException , boolean requiresAssertion ){
3742 if (method == null ){
3843 throw new IllegalArgumentException ("method may not be null" );
3944 }
4045 this .method = method ;
4146 this .lesson = new RbVariableInjector (lesson , method ).injectLessonVariables ();
4247 this .displayIncompleteException = displayIncompleteException ;
48+ this .requiresAssertion = requiresAssertion ;
4349 }
4450
4551 public KoanMethod (String lesson , KoanElementAttributes koanAttributes ) throws SecurityException , NoSuchMethodException {
4652 this ( lesson ,
4753 KoanClassLoader .getInstance ().loadClass (koanAttributes .className , listener )
4854 .getMethod (koanAttributes .name ),
49- !"false" .equalsIgnoreCase (koanAttributes .displayIncompleteKoanException ));
55+ !"false" .equalsIgnoreCase (koanAttributes .displayIncompleteKoanException ),
56+ !"false" .equalsIgnoreCase (koanAttributes .requireAssertion ));
5057 }
5158
5259 public String getLesson () {
@@ -60,9 +67,13 @@ public Method getMethod() {
6067 public boolean displayIncompleteException () {
6168 return displayIncompleteException ;
6269 }
70+
71+ public boolean requiresAssertion () {
72+ return requiresAssertion ;
73+ }
6374
6475 public KoanMethod clone (Method method ){
65- return new KoanMethod (lesson , method , displayIncompleteException );
76+ return new KoanMethod (lesson , method , displayIncompleteException , requiresAssertion );
6677 }
6778
6879 @ Override public String toString (){
@@ -75,6 +86,7 @@ public int hashCode() {
7586 final int prime = 31 ;
7687 int result = 1 ;
7788 result = prime * result + (displayIncompleteException ? 1231 : 1237 );
89+ result = prime * result + (requiresAssertion ? 1231 : 1237 );
7890 result = prime * result + ((lesson == null ) ? 0 : lesson .hashCode ());
7991 return result ;
8092 }
@@ -90,6 +102,8 @@ public boolean equals(Object obj) {
90102 KoanMethod other = (KoanMethod ) obj ;
91103 if (displayIncompleteException != other .displayIncompleteException )
92104 return false ;
105+ if (requiresAssertion != other .requiresAssertion )
106+ return false ;
93107 if (lesson == null ) {
94108 if (other .lesson != null )
95109 return false ;
0 commit comments