From cd921fe6d330ed3125efe995ad3c258ee96b3693 Mon Sep 17 00:00:00 2001 From: Chima Ejiofor Date: Fri, 3 Feb 2017 23:50:52 +0100 Subject: [PATCH] Fixed Unit Test for hibernate one to many --- .../HibernateOneToManyAnnotationMainTest.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/spring-hibernate4/src/test/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMainTest.java b/spring-hibernate4/src/test/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMainTest.java index 539298ae1e..742bb2b470 100644 --- a/spring-hibernate4/src/test/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMainTest.java +++ b/spring-hibernate4/src/test/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMainTest.java @@ -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 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(); }