Created
July 31, 2019 08:43
-
-
Save import-benjamin/de183941d4edd9108e6835a9965ade07 to your computer and use it in GitHub Desktop.
Case Class with abstract parent with parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package classes | |
abstract class Lunch() { | |
def eat(): String = { | |
"burp." | |
} | |
def sugarValue:Double | |
} | |
case class Soda(sugarValue:Double = 10.0) extends Lunch | |
object CaseClassWithAbstractParentWithParameters { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package classes | |
import org.scalatest.{FlatSpec, Matchers} | |
class TestCaseClassWithAbstractParentWithParameters extends FlatSpec with Matchers { | |
"Case class with abstract parent with parameters" should "use default value for parameters" in { | |
val boisson = Soda() | |
boisson.sugarValue shouldBe 10 | |
} | |
it should "update parameters if defined" in { | |
val boisson = Soda(20.0) | |
boisson.sugarValue shouldBe 20 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment