Book Image

Mastering Unit Testing Using Mockito and JUnit

By : Sujoy Acharya
Book Image

Mastering Unit Testing Using Mockito and JUnit

By: Sujoy Acharya

Overview of this book

Table of Contents (17 chapters)
Mastering Unit Testing Using Mockito and JUnit
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Simplifying persistence with Spring


Look at the PhoneBookDerbyDao class. It has 398 lines to support create, read, update, and delete (CRUD) operations. Every method performs almost similar tasks. The following tasks are invoked from the CRUD methods:

  • Passing connection parameters

  • Opening a connection

  • Creating a statement

  • Preparing the statement

  • Executing the statement

  • Iterating through the results (only in the read method)

  • Populating the model objects (only in the read method)

  • Processing any exception

  • Handling transactions

  • Closing the ResultSet (only in the read method)

  • Closing the statement

  • Closing the connection

The Spring framework provides APIs to reduce JDBC code duplication. Spring JDBC hides the low-level details and allows us to concentrate on business logic. We'll implement PhoneBookDao using Spring JDBC.

Download the latest version of JDBC JAR and its dependencies from http://maven.springframework.org/release/org/springframework/spring/.

Follow the ensuing steps to implement Spring JDBC and...