Last active
April 15, 2020 14:35
-
-
Save tk3/6364a2dcf9940a5cfd7e105b4a952384 to your computer and use it in GitHub Desktop.
ScalaTest sampless
This file contains hidden or 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
name := "SampleTest" | |
version := "0.1" | |
scalaVersion := "2.13.1" | |
libraryDependencies ++= Seq( | |
"org.scalatest" %% "scalatest" % "3.1.1" % "test" | |
) |
This file contains hidden or 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 SampleCase | |
trait SampleTrait { | |
def calc(price: Double): Double = { | |
price * 1.08 | |
} | |
private[SampleTrait] def calcWithStandardPlan(price: Double): Double = { | |
(price * 2) * 1.08 | |
} | |
} |
This file contains hidden or 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 SampleCase | |
import org.scalatest.wordspec.AnyWordSpec | |
import org.scalatest.matchers.should.Matchers | |
import org.scalatest.PrivateMethodTester._ | |
class SampleTraitTest extends AnyWordSpec with Matchers { | |
object SampleTrait extends SampleTrait | |
"SampleTrait" when { | |
"calc" must { | |
"OK" in { | |
val expected = 108.0 | |
val result = SampleTrait.calc(100) | |
result shouldEqual expected | |
} | |
} | |
"calcWithStandardPlan" must { | |
"OK" in { | |
val expected = 432.0 | |
val calcWithStandardPlan = PrivateMethod[Double](Symbol("calcWithStandardPlan")) | |
val result = SampleTrait invokePrivate calcWithStandardPlan(200.0) | |
result shouldEqual expected | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment