Book Image

Building Applications with Scala

By : Diego Pacheco
Book Image

Building Applications with Scala

By: Diego Pacheco

Overview of this book

<p>Scala is known for incorporating both object-oriented and functional programming into a concise and extremely powerful package. However, creating an app in Scala can get a little tricky because of the complexity the language has. This book will help you dive straight into app development by creating a real, reactive, and functional application. We will provide you with practical examples and instructions using a hands-on approach that will give you a firm grounding in reactive functional principles.</p> <p>The book will take you through all the fundamentals of app development within Scala as you build an application piece by piece. We’ve made sure to incorporate everything you need from setting up to building reports and scaling architecture. This book also covers the most useful tools available in the Scala ecosystem, such as Slick, Play, and Akka, and a whole lot more. It will help you unlock the secrets of building your own up-to-date Scala application while maximizing performance and scalability.</p>
Table of Contents (17 chapters)
Building Applications with Scala
Credits
About the Author
Acknowledgments
About the Reviewer
www.PacktPub.com
Preface

Refactoring tests


As you might expect, most tests are no longer working. We will need to perform some refactoring here as well. We will refactor our former dao to make it generic, and it will be used in integration tests (end-to-end tests).

Since we will create a generic dao system in memory for end-to-end testing purposes, we need to change our models a little bit. First, we need to create a base trait for all the models. This is needed so we can treat our models as equals.

Let's have a look at models.BaseModel.scala:

    package models 
    trait BaseModel { 
      def getId:Option[Long] 
      def setId(id:Option[Long]):Unit 
    } 

We also need to make all our models implement this new trait. So we will need to change the Scala code for the product, image, and review. This is very trivial: we just add a getter and a setter for the id field. You can also use scala.bean.BeanProperty instead of writing one by yourself.

Your models.Product.scala file should look something like this:

    package...