Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save import-benjamin/de183941d4edd9108e6835a9965ade07 to your computer and use it in GitHub Desktop.
Save import-benjamin/de183941d4edd9108e6835a9965ade07 to your computer and use it in GitHub Desktop.
Case Class with abstract parent with parameters
package classes
abstract class Lunch() {
def eat(): String = {
"burp."
}
def sugarValue:Double
}
case class Soda(sugarValue:Double = 10.0) extends Lunch
object CaseClassWithAbstractParentWithParameters {
}
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