Implement RegistrationManagement dependencies

We will introduce the dependencies of RegistrationManagement briefly here. At this stage,  our focus is to get the RegistrationManagementTests pass. In the tests, we use mocks to define the behavior of the dependencies. So, we will only need to create a blank implementation of the dependencies, leaving the actual implementation for later sections in this chapter.

Here is the blank implementation of the PasswordEncryptor interface:

@Component
public class PasswordEncryptorDelegator implements PasswordEncryptor {
@Override
public String encrypt(String rawPassword) {
// TODO implement this
return rawPassword;
}
}

As you can see, we name it PasswordEncryptorDelegator, indicating that the actual password encryption logic is delegated to others, in our case, Spring Security's PasswordEncoder, which we will talk about later.

And here is the blank implementation of the MailManager interface:

@Component
public class DefaultMailManager implements MailManager {

@Override
public void send(String emailAddress, String subject, String template, MessageVariable... variables) {
// TODO implement this
}
}

This mail manager is responsible for creating mail messages from the template and the variables, and then calling the mail service API to send the message out.

Here is how the UserRepository interface looks:

...
public interface UserRepository {
User findByUsername(String username);
User findByEmailAddress(String emailAddress);
void save(User user);
}

As you can see, this interface is clean and easy to understand. We will talk about its implementation shortly.

Now, if you run RegistrationManagementTests from VS Code, you should see all of the tests pass.

By now, we have finished the implementation of registration inside the domain model. It's time to save the user in the database.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.96.94