We can unify the launchers by accepting a BooksEndpoint dependency. If we don't specify it, it will register the dependency with the real instance of BooksRepository. Otherwise, it will register the received one:
public class MyApplication extends ResourceConfig { public MyApplication() { this(new BooksEndpoint( new BooksRepository())); } public MyApplication (BooksEndpoint booksEndpoint) { register(booksEndpoint); register(RequestContextFilter.class); register(JacksonJaxbJsonProvider.class); register(CustomExceptionMapper.class); } }
In this case, we have opted for constructor chaining to avoid repetition in the constructors.
After doing this refactor, the BooksEndpointInteractionTest class is as follows in ...