ARTICLE AD BOX
I have a fairly standard Builder that returns a Command...
Builder:
@Component @Scope("prototype") public class CommandBuilder { private final Repository repository; private String authoritativeSourceId; private String title; public CommandBuilder(Repository repository) { this.repository = repository; } public CommandBuilder setAuthoritativeSourceId(String authoritativeSourceId) { this.authoritativeSourceId = authoritativeSourceId; return this; } public CommandBuilder setTitle(String title) { this.title = title; return this; } public CommandBuilder build() { return new AddCommand(this.repository, this.authoritativeSourceId, this.title); } }The command class looks like the following:
public class AddCommand { private final Repository repository; private final String authoritativeSourceId; private final String title; public AddCommand(Repository repository, String authoritativeSourceId, String title) { this.repository = repository; this.authoritativeSourceId = authoritativeSourceId; this.title = title; } @Transactional public Source execute() { // Create Source, a fictitious example object... Source source = new Source(authoritativeSourceId); source.setTitle(); this.repository.save(source); return source; } }Please note that the AddCommand doesn't have any accessors.
So, how do I verify behavior of the CommandBuilder to verify that it is building the AddCommand object correctly?
Any friendly direction on best practices would be greatly appreciated.
