Skip to content

Instantly share code, notes, and snippets.

@JavierCane
Created November 22, 2017 10:03
Show Gist options
  • Save JavierCane/bd26d3a6bcabbbffff4d29978dea6911 to your computer and use it in GitHub Desktop.
Save JavierCane/bd26d3a6bcabbbffff4d29978dea6911 to your computer and use it in GitHub Desktop.
Scala standard class visibilities 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 StandardClassVisibilitiesSpec extends WordSpec with Matchers {
private val randomText = "some text"
private val standardClass = new StandardClass(attributeInConstruct = randomText)
"Standard Class" should {
"set as public the attributes defined in the constructor by default" in {
standardClass.attributeInConstruct shouldBe randomText
}
"not compile if we try to access private attributes defined in the constructor" in {
"standardClass.privateAttributeInConstruct" shouldNot compile
}
"set as public the attributes defined in the class body by default" in {
val bodyAttributeValue = "public body attribute value"
standardClass.attributeInBody shouldBe bodyAttributeValue
}
"not compile if we try to access private attributes defined in the body" in {
"standardClass.privateAttributeInBody" shouldNot compile
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment