Merge pull request #1099 from mobiblunt/master

Fixed Unit Test for hibernate one to many
This commit is contained in:
maibin 2017-02-04 00:11:03 +01:00 committed by GitHub
commit 1cc01c49a6
1 changed files with 15 additions and 2 deletions

View File

@ -18,8 +18,10 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.runner.RunWith;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
//@RunWith(SpringJUnit4ClassRunner.class)
public class HibernateOneToManyAnnotationMainTest {
private static SessionFactory sessionFactory;
@ -45,6 +47,15 @@ public class HibernateOneToManyAnnotationMainTest {
}
@Test
public void givenSession_checkIfDatabaseIsEmpty(){
Cart cart = (Cart) session.get(Cart.class, new Long(1));
assertNull(cart);
}
@Test
@ -63,7 +74,7 @@ public class HibernateOneToManyAnnotationMainTest {
}
@Test
public void testSaveCart(){
public void givenSession_checkIfDatabaseIsPopulated_afterCommit(){
Cart cart = new Cart();
Set <Items> cartItems = new HashSet<>();
cartItems = cart.getItems();
@ -81,6 +92,8 @@ public class HibernateOneToManyAnnotationMainTest {
assertNotNull(cart);
session.persist(cart);
session.getTransaction().commit();
cart = (Cart) session.get(Cart.class, new Long(1));
assertNotNull(cart);
session.close();
}