Commits

dmarsh  committed 8198076

added fill-in-the-blanks and changed return types of methods

  • Participants
  • Parent commits 76fe961

Comments (0)

Files changed (1)

File src/test/scala/org/functionalkoans/forscala/AboutTraits.scala

   koan("A class uses the extends keyword to mixin a trait if it is the only relationship the class inherits") {
     case class Event(name: String)
     trait EventListener {
-      def listen(event: Event): Unit
+      def listen(event: Event): String
     }
     class MyListener extends EventListener {
-      def listen(event: Event) {
+      def listen(event: Event): String = {
         event match {
-          case Event("Moose Stampede") => println("An unfortunate moose stampede occured")
-          case _ => println("Nothing of importance occured")
+          case Event("Moose Stampede") => "An unfortunate moose stampede occured"
+          case _ => "Nothing of importance occured"
         }
       }
     }
 
     val evt = Event("Moose Stampede")
     val myListener = new MyListener
-    myListener.listen(evt)
+    myListener.listen(evt) should be (__)
   }
 
   koan("A class can only \'extend\' from one class or trait, any subsequent extension should use the keyword \'with\'") {
     case class Event(name: String)
 
     trait EventListener {
-      def listen(event: Event): Unit
+      def listen(event: Event): String
     }
 
     class OurListener
 
     class MyListener extends OurListener with EventListener {
-      def listen(event: Event) {
+      def listen(event: Event) : String = {
         event match {
-          case Event("Woodchuck Stampede") => println("An unfortunate woodchuck stampede occured")
-          case _ => println("Nothing of importance occured")
+          case Event("Woodchuck Stampede") => "An unfortunate woodchuck stampede occured"
+          case _ => "Nothing of importance occured"
         }
       }
     }
 
     val evt = Event("Woodchuck Stampede")
     val myListener = new MyListener
-    myListener.listen(evt)
+    myListener.listen(evt) should be (__)
   }
 
   koan("Traits are polymorphic. Any type can be referred to by another type if related by extension") {
     case class Event(name: String)
     trait EventListener {
-      def listen(event: Event): Unit
+      def listen(event: Event): String
     }
     class MyListener extends EventListener {
-      def listen(event: Event) {
+      def listen(event: Event) : String = {
         event match {
-          case Event("Moose Stampede") => println("An unfortunate moose stampede occured")
-          case _ => println("Nothing of importance occured")
+          case Event("Moose Stampede") => "An unfortunate moose stampede occured"
+          case _ => "Nothing of importance occured"
         }
       }
     }