Skip to content

Instantly share code, notes, and snippets.

@adamw
Created January 7, 2020 07:07
Show Gist options
  • Save adamw/16f5d1ca87da0b85a0363dfaebacefdf to your computer and use it in GitHub Desktop.
Save adamw/16f5d1ca87da0b85a0363dfaebacefdf to your computer and use it in GitHub Desktop.
class Example3Test extends AnyFlatSpec with Matchers {
import Example3._
it should "add 1 point" in {
// given
val updatedPoints = new AtomicInteger(0)
val userId = UUID.randomUUID()
val stubDao = newStubDaoConstantPoints(15, updatedPoints)
// when
new Points(stubDao).increase(userId)
// then
updatedPoints.get() shouldBe 16
}
it should "add 3 points" in {
// given
val updatedPoints = new AtomicInteger(0)
val userId = UUID.randomUUID()
val stubDao = newStubDaoConstantPoints(16, updatedPoints)
// when
new Points(stubDao).increase(userId)
// then
updatedPoints.get() shouldBe 19
}
def newStubDaoConstantPoints(points: Int,
updatedPoints: AtomicInteger): Dao[Id] = new Dao[Id] {
override def currentPoints(userId: UUID): Id[Int] = points
override def updatePoints(userId: UUID, value: Int): Id[Unit] =
updatedPoints.set(value)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment