Skip to content

Instantly share code, notes, and snippets.

@JavierCane
Created November 22, 2017 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JavierCane/0fdf9e056fa49646e2ca7a052e07cc68 to your computer and use it in GitHub Desktop.
Save JavierCane/0fdf9e056fa49646e2ca7a052e07cc68 to your computer and use it in GitHub Desktop.
Scala Case Class visibilities test example for the CodelyTV Pro Scala course πŸ‘‰ https://pro.codely.tv/
// Full repo: https://github.com/CodelyTV/scala-intro-examples/
package tv.codely.scala_intro_examples.lesson_09_oop
import org.scalatest.{Matchers, WordSpec}
final class CaseClassVisibilitiesSpec extends WordSpec with Matchers {
private val randomText = "some text"
private val caseClass = CaseClass(attributeInConstruct = randomText)
"Case Class" should {
"generate a public getter for the attributes defined in the constructor" in {
caseClass.attributeInConstruct shouldBe randomText
}
"not compile if we try to access private attributes defined in the constructor" in {
"caseClass.privateAttributeInConstruct" shouldNot compile
}
"set as public the attributes defined in the class body by default" in {
val bodyAttributeValue = "public body attribute value"
caseClass.attributeInBody shouldBe bodyAttributeValue
}
"not compile if we try to access private attributes defined in the body" in {
"caseClass.privateAttributeInBody" shouldNot compile
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment