The problem seems really simple in an MVC style where every layer is supposed to be separated. However, when you apply the recommended Play 2 coding style (according to "Play for Scala") then it becomes difficult to Unit test controllers by isolating them.
Here is the code proposed by the authors of "Play for Scala" for a simple controller :
Object product extends Controller {
def list = Action { implicit request =>
val products = Product.findAll
Ok(views.html.products.list(products))
}
}
How is it possible to mock the DAO "Product" in order to isolate it from the database, with this way of calling for data ?
val products = Product.findAll
Product is not injected it seems nor a simple variable of this object that you could mock.
Did I miss or misunderstood something ? Is there any possibility to Unit test this ? Mocking or any other solution isolating the controller's method ?