JUnit create dao fake object JAVA
<p>I am trying to test a class which is using dao. In my test class I have mocked the DAO and inject the mock into an instance of the class that I test. I am trying to make a fake object of the DAO class.</p>

<pre><code>@RunWith(MockitoJUnitRunner.class)
public class UserManagerTest {

    @Mock
    private UserManagerDao umDao;

    @InjectMocks
    private UserManager um = new UserManager();

    @Before
    public void initializeMockito() {
        MockitoAnnotations.initMocks(this);
    }

    public void testGetUserId() {       

    }
</code></pre>

<p>This here are the methods from UserManager.class and Dao class</p>

<p><strong>userManager.class</strong></p>

<pre><code>public long getUserId(String email) throws Exception {
    String[] partsOfMail = email.split("@");        
    return umDao.getUserId(partsOfMail[0], partsOfMail[1]);
}
</code></pre>

<p><strong>Dao class</strong></p>

<pre><code>public long getUserId(String userName, String domain) throws Exception {
    String sql = msa.getMessage("sql.select.user_id");
    Object[] params = new Object[] { userName, domain };

    List&lt;Long&gt; result = getJdbcTemplate().queryForList(sql, params, Long.class);

    if (result.size() &gt; 0) {
        return result.get(0);
    }

    return 0;
}
</code></pre>