Book Image

Mockito for Spring

By : Sujoy Acharya
Book Image

Mockito for Spring

By: Sujoy Acharya

Overview of this book

Table of Contents (12 chapters)
Mockito for Spring
About the Author
About the Reviewers

Unit testing the service layer

RegistrationService validates the following rules:

  • The user ID, password, first name, or last name cannot be empty

  • The first and last names cannot contain numbers

  • The first and last names cannot contain special characters

  • The password should contain at least one special character

  • There cannot be a duplicate user ID

RegistrationService should call the database to determine whether a user ID exists or not. We'll create a data access interface for persisting user and to check whether a duplicate user ID is present. Perform the following steps to build the service, create a data access object API, and unit test the service:

  1. Create a RegistrationDao interface in the com.packt.dao package, and add the following methods to check for duplicate users and to create a new user:

    public interface RegistrationDao {
      boolean isExistingUserId(String userId);
      void create(String userId, String password, String 
            firstName, String lastName);
  2. Modify the RegistrationService...