Created
December 17, 2012 14:39
-
-
Save anonymous/4318746 to your computer and use it in GitHub Desktop.
Sample Mock with Mockito API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package th.co.osdev.alfresco.filemigration.dao; | |
import static org.mockito.Mockito.*; | |
import java.io.Serializable; | |
import java.util.List; | |
import org.hibernate.Session; | |
import org.hibernate.SessionFactory; | |
import org.junit.After; | |
import org.junit.Before; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.mockito.Mock; | |
import org.mockito.runners.MockitoJUnitRunner; | |
import th.co.osdev.alfresco.filemigration.domain.FileConversion; | |
@RunWith(MockitoJUnitRunner.class) | |
public class MyDAOTest { | |
@Mock | |
private SessionFactory sessionFactory; | |
@Mock | |
private Session session; | |
@Mock | |
private Serializable serializable; | |
@Before | |
public void setUp() throws Exception { | |
when(sessionFactory.openSession()).thenReturn(session); | |
when(session.save(anyObject())).thenReturn(serializable); | |
when(session.load(FileConversion.class, serializable)).thenReturn(anyObject()); | |
} | |
@After | |
public void tearDown() throws Exception { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment