Example #1
0
 @BeforeClass
 public static void initClass() {
   dao = new PersonDaoImpl();
   factory = mock(SessionFactory.class);
   session = mock(Session.class);
   dao.setSessionFactory(factory);
 }
Example #2
0
 @Test(expected = HibernateException.class)
 public void testDeleteDataKO() {
   // Setup
   Person input = new Person();
   doThrow(new HibernateException("")).when(session).delete(input);
   // Action
   dao.deletePerson(input);
 }
Example #3
0
 @Test(expected = HibernateException.class)
 public void testRetrieveDataKO() {
   // /Setup
   Criteria criteria = mock(Criteria.class);
   when(session.createCriteria(Person.class)).thenReturn(criteria);
   when(criteria.list()).thenThrow(new HibernateException(""));
   dao.getAllPersons();
 }
Example #4
0
 @Test(expected = HibernateException.class)
 public void testCreateDataKO() {
   // Setup
   Person user = new Person();
   when(session.merge(user)).thenThrow(new HibernateException("fail"));
   // Action
   dao.savePerson(user);
 }
Example #5
0
 @Test
 public void testDeleteDataOK() {
   // Setup
   Person input = new Person();
   // Action
   dao.deletePerson(input);
   // Test
   verify(factory, times(1)).getCurrentSession();
   verify(session, times(1)).delete(input);
 }
Example #6
0
 @Test
 public void testCreateDataOK() {
   // Setup
   Person input = new Person();
   // Action
   dao.savePerson(input);
   // test
   verify(factory, times(1)).getCurrentSession();
   verify(session, times(1)).merge(input);
 }
Example #7
0
 @Test
 public void testRetrieveDataOK() {
   // /Setup
   Criteria criteria = mock(Criteria.class);
   when(session.createCriteria(Person.class)).thenReturn(criteria);
   List<Person> persons = mock(List.class);
   when(criteria.list()).thenReturn(persons);
   // Action
   dao.getAllPersons();
   // Test
   verify(session, times(1)).createCriteria(Person.class);
   verify(criteria, times(1)).list();
 }