Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have three options to set your mock dao:</p> <ol> <li><strong>Test the implementation</strong> - which gives a seam for your mock via the setDao method. (as JB's answer) </li> <li><strong>Add the setDao method</strong> to the interface - not desired since you don't want to add code just to support your tests.</li> <li><strong>Add a constructor</strong> to the impl class to accept the dao - not desired for same reason as #2.</li> </ol> <p>If you wanted to do #3, you'll need to add a constructor to the MobileService that accepts the MobileDao.</p> <pre><code> public MobileServiceImpl(MobileDao mobileDao) { this.mobileDao = mobileDao; } </code></pre> <hr> <p>Then your test will look like this:</p> <pre><code>import static org.mockito.Mockito.verify; import static org.mockito.Mockito.*; import java.util.Date; import org.junit.Before; import org.junit.Test; public class MobileServiceImplTest { private MobileService systemUnderTest; private MobileDao mobileDao; @Before public void setup() { mobileDao = mock(MobileDao.class); systemUnderTest = new MobileServiceImpl(mobileDao); } @Test public void testGetUser() { //if you need to, configure mock behavior here. //i.e. when(mobileDao.someMethod(someObject)).thenReturn(someResponse); systemUnderTest.getUser("accessCode", new Date()); verify(mobileDao).getUser("JeffAtwood"); } } </code></pre> <p>Please note that you have not provided us with the details of the MobileDao so I created a getUser method that accepts a String.</p> <p>To make the test pass, your MobileServiceImpl would just need this:</p> <pre><code>mobileDao.getUser("JeffAtwood"); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload