Merge pull request #1099 from mobiblunt/master
Fixed Unit Test for hibernate one to many
This commit is contained in:
commit
1cc01c49a6
|
@ -18,8 +18,10 @@ import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
//@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
public class HibernateOneToManyAnnotationMainTest {
|
public class HibernateOneToManyAnnotationMainTest {
|
||||||
|
|
||||||
private static SessionFactory sessionFactory;
|
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
|
@Test
|
||||||
|
@ -63,7 +74,7 @@ public class HibernateOneToManyAnnotationMainTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSaveCart(){
|
public void givenSession_checkIfDatabaseIsPopulated_afterCommit(){
|
||||||
Cart cart = new Cart();
|
Cart cart = new Cart();
|
||||||
Set <Items> cartItems = new HashSet<>();
|
Set <Items> cartItems = new HashSet<>();
|
||||||
cartItems = cart.getItems();
|
cartItems = cart.getItems();
|
||||||
|
@ -81,6 +92,8 @@ public class HibernateOneToManyAnnotationMainTest {
|
||||||
assertNotNull(cart);
|
assertNotNull(cart);
|
||||||
session.persist(cart);
|
session.persist(cart);
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
|
cart = (Cart) session.get(Cart.class, new Long(1));
|
||||||
|
assertNotNull(cart);
|
||||||
session.close();
|
session.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue