Skip to content

Instantly share code, notes, and snippets.

Created December 17, 2012 14:39
Show Gist options
  • Save anonymous/4318746 to your computer and use it in GitHub Desktop.
Save anonymous/4318746 to your computer and use it in GitHub Desktop.
Sample Mock with Mockito API
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