In HibernateUserRepositoryTests, we will create the following test methods to cover different scenarios:
- save_nullUsernameUser_shouldFail()
- save_nullEmailAddressUser_shouldFail()
- save_nullPasswordUser_shouldFail()
- save_validUser_shouldSuccess()
- save_usernameAlreadyExist_shouldFail()
- save_emailAddressAlreadyExist_shouldFail()
- findByEmailAddress_notExist_shouldReturnEmptyResult()
- findByEmailAddress_exist_shouldReturnResult()
- findByUsername_notExist_shouldReturnEmptyResult()
- findByUsername_exist_shouldReturnResult()
First of all, let's add a H2 dependency into Maven's pom.xml as follows, so that when Spring Boot starts the tests, it knows that we need H2 instead of MySQL:
<dependency> <groupId>com.h2database</groupId> ...