Created
November 22, 2017 10:21
-
-
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/
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
// 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