Skip to content

Commit

Permalink
Merge pull request eugenp#1099 from mobiblunt/master
Browse files Browse the repository at this point in the history
Fixed Unit Test for hibernate one to many
  • Loading branch information
maibin authored Feb 3, 2017
2 parents d87926b + cd921fe commit 1cc01c4
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
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;
Expand All @@ -45,6 +47,15 @@ public void setUp() {

}

@Test
public void givenSession_checkIfDatabaseIsEmpty(){
Cart cart = (Cart) session.get(Cart.class, new Long(1));
assertNull(cart);

}





@Test
Expand All @@ -63,7 +74,7 @@ public void testAddItemsToCart() {
}

@Test
public void testSaveCart(){
public void givenSession_checkIfDatabaseIsPopulated_afterCommit(){
Cart cart = new Cart();
Set <Items> cartItems = new HashSet<>();
cartItems = cart.getItems();
Expand All @@ -81,6 +92,8 @@ public void testSaveCart(){
assertNotNull(cart);
session.persist(cart);
session.getTransaction().commit();
cart = (Cart) session.get(Cart.class, new Long(1));
assertNotNull(cart);
session.close();

}
Expand Down

0 comments on commit 1cc01c4

Please sign in to comment.