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]] ...

Get Building Applications with Scala now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.