How do I mock objects in a Java class that has no (non-default) constructor?
<p>I am working on setting up the first unit tests for a legacy Tomcat web service that was not written with testing in mind, and doesn't use Spring.  One of the classes I'm having trouble with is a servlet that extends HttpServlet.  Here is an abbreviated version of the class.</p>

<pre><code>public class ItemServlet extends HttpServlet {
    private ObjectMapper mapper;
    private IItemDAO dao;

    @Override
    public void init() {
        mapper = new ObjectMapper();
        dao = new GenericItemDao(...);
    }
}
</code></pre>

<p>Normally I would pass in the external dependencies to the constructor, but the servlets are created by Tomcat based on the <code>web.xml</code> config, which calls only the default constructor and the argument-less <code>init()</code> method.  As a result, there doesn't seem to be any way to do dependency injection to allow for my mocks in the unit tests.  The only way I can think of doing this is to create a test-only constructor that I can use to instantiate the class from my unit tests, and leave the init() method the way it is for the actual application to call.  I could also create a third method that could be called by both the constructor and <code>init()</code> like so:</p>

<pre><code>public class ItemServlet extends HttpServlet {
    private ObjectMapper mapper;
    private IItemDAO dao;

    public ItemServlet(ObjectMapper mapper, IItemDAO dao) {
        initDependencies(mapper, dao);
    }

    private void initDependencies(ObjectMapper mapper, IItemDAO dao) {
        this.mapper = mapper;
        this.dao = dao;
    }

    @Override
    public void init() {
        initDependencies(new ObjectMapper(), new GenericItemDAO(...));
    }
}
</code></pre>

<p>Is there a cleaner way to unit test these classes?</p>