Skip to content

Commit 1cc01c4

Browse files
authored
Merge pull request eugenp#1099 from mobiblunt/master
Fixed Unit Test for hibernate one to many
2 parents d87926b + cd921fe commit 1cc01c4

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

‎spring-hibernate4/src/test/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMainTest.java‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
import org.junit.BeforeClass;
1919
import org.junit.Test;
2020
import static org.junit.Assert.*;
21+
import org.junit.runner.RunWith;
22+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
2123

22-
24+
//@RunWith(SpringJUnit4ClassRunner.class)
2325
public class HibernateOneToManyAnnotationMainTest {
2426

2527
private static SessionFactory sessionFactory;
@@ -45,6 +47,15 @@ public void setUp() {
4547

4648
}
4749

50+
@Test
51+
public void givenSession_checkIfDatabaseIsEmpty(){
52+
Cart cart = (Cart) session.get(Cart.class, new Long(1));
53+
assertNull(cart);
54+
55+
}
56+
57+
58+
4859

4960

5061
@Test
@@ -63,7 +74,7 @@ public void testAddItemsToCart() {
6374
}
6475

6576
@Test
66-
public void testSaveCart(){
77+
public void givenSession_checkIfDatabaseIsPopulated_afterCommit(){
6778
Cart cart = new Cart();
6879
Set <Items> cartItems = new HashSet<>();
6980
cartItems = cart.getItems();
@@ -81,6 +92,8 @@ public void testSaveCart(){
8192
assertNotNull(cart);
8293
session.persist(cart);
8394
session.getTransaction().commit();
95+
cart = (Cart) session.get(Cart.class, new Long(1));
96+
assertNotNull(cart);
8497
session.close();
8598

8699
}

0 commit comments

Comments
 (0)