O'Reilly logo

Building Applications with Scala by Diego Pacheco

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Generic mocks

Now we have all that we need to create a generic mock implementation and mock all the dao packages. Under the location ReactiveWebStore/test/, we will create a package called mocks, and create a call, GenericMockedDao.

Your GenericMockedDao.scala file should look like this:

package mocks import models.BaseModel class GenericMockedDao[T <: BaseModel] { import java.util.concurrent.atomic.AtomicLong import scala.collection.mutable.HashMap import scala.concurrent._ import play.api.libs.concurrent.Execution. Implicits.defaultContext var inMemoryDB = new HashMap[Long,T] var idCounter = new AtomicLong(0) def findAll(): Future[Seq[T]] = { Future { if (inMemoryDB.isEmpty) Seq() inMemoryDB.values.toSeq } } def findById(id:Long): Future[Option[T]] ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required