From 7ee0ac104de0afdd308151f619428ea80891d6e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9F=D0=B5=D1=82?= =?UTF-8?q?=D1=83=D0=BD=D0=B8=D0=BD?= Date: Sun, 29 Oct 2017 14:06:46 +0100 Subject: [PATCH] BAEL-1280: Fixed sample code issues --- hibernate5/pom.xml | 6 ++++ ...ava => DynamicMappingIntegrationTest.java} | 34 +++++++++---------- 2 files changed, 23 insertions(+), 17 deletions(-) rename hibernate5/src/test/java/com/baeldung/hibernate/{DynamicMappingTest.java => DynamicMappingIntegrationTest.java} (81%) diff --git a/hibernate5/pom.xml b/hibernate5/pom.xml index a9e3742e1c..8543d1dae3 100644 --- a/hibernate5/pom.xml +++ b/hibernate5/pom.xml @@ -29,6 +29,12 @@ junit 4.12 + + org.assertj + assertj-core + 3.8.0 + test + com.h2database h2 diff --git a/hibernate5/src/test/java/com/baeldung/hibernate/DynamicMappingTest.java b/hibernate5/src/test/java/com/baeldung/hibernate/DynamicMappingIntegrationTest.java similarity index 81% rename from hibernate5/src/test/java/com/baeldung/hibernate/DynamicMappingTest.java rename to hibernate5/src/test/java/com/baeldung/hibernate/DynamicMappingIntegrationTest.java index 456985eeae..b207d6630a 100644 --- a/hibernate5/src/test/java/com/baeldung/hibernate/DynamicMappingTest.java +++ b/hibernate5/src/test/java/com/baeldung/hibernate/DynamicMappingIntegrationTest.java @@ -12,9 +12,9 @@ import org.junit.Test; import java.io.IOException; import java.util.List; -import static org.junit.Assert.*; +import static org.assertj.core.api.Assertions.assertThat; -public class DynamicMappingTest { +public class DynamicMappingIntegrationTest { private Session session; @@ -34,21 +34,21 @@ public class DynamicMappingTest { @After public void tearDown() { - transaction.commit(); + transaction.rollback(); session.close(); } @Test public void givenEntity_whenFieldMappedWithFormula_thenFieldIsCalculated() { Employee employee = new Employee(10_000L, 25); - assertEquals(2_500L, employee.getTaxJavaWay()); + assertThat(employee.getTaxJavaWay()).isEqualTo(2_500L); session.save(employee); session.flush(); session.clear(); employee = session.get(Employee.class, employee.getId()); - assertEquals(2_500L, employee.getTax()); + assertThat(employee.getTax()).isEqualTo(2_500L); } @Test @@ -59,18 +59,18 @@ public class DynamicMappingTest { session.clear(); employee = session.find(Employee.class, employee.getId()); - assertNotNull(employee); + assertThat(employee).isNotNull(); employee.setDeleted(true); session.flush(); employee = session.find(Employee.class, employee.getId()); - assertNotNull(employee); + assertThat(employee).isNotNull(); session.clear(); employee = session.find(Employee.class, employee.getId()); - assertNull(employee); + assertThat(employee).isNull(); } @@ -89,17 +89,17 @@ public class DynamicMappingTest { session.clear(); employee = session.find(Employee.class, employee.getId()); - assertEquals(employee.getPhones().size(), 2); + assertThat(employee.getPhones()).hasSize(2); employee.getPhones().iterator().next().setDeleted(true); session.flush(); session.clear(); employee = session.find(Employee.class, employee.getId()); - assertEquals(employee.getPhones().size(), 1); + assertThat(employee.getPhones()).hasSize(1); List fullPhoneList = session.createQuery("from Phone").getResultList(); - assertEquals(2, fullPhoneList.size()); + assertThat(fullPhoneList).hasSize(2); } @@ -117,10 +117,10 @@ public class DynamicMappingTest { List employees = session.createQuery("from Employee").getResultList(); - assertEquals(2, employees.size()); + assertThat(employees).hasSize(2); Employee employee = session.get(Employee.class, 1); - assertEquals(10_000, employee.getGrossIncome()); + assertThat(employee.getGrossIncome()).isEqualTo(10_000); session.close(); @@ -129,7 +129,7 @@ public class DynamicMappingTest { employees = session.createQuery("from Employee").getResultList(); - assertEquals(3, employees.size()); + assertThat(employees).hasSize(3); } @@ -156,9 +156,9 @@ public class DynamicMappingTest { List descriptions = session.createQuery("from EntityDescription").getResultList(); - assertTrue(Employee.class.isAssignableFrom(descriptions.get(0).getEntity().getClass())); - assertTrue(Phone.class.isAssignableFrom(descriptions.get(1).getEntity().getClass())); - assertTrue(Phone.class.isAssignableFrom(descriptions.get(2).getEntity().getClass())); + assertThat(Employee.class.isAssignableFrom(descriptions.get(0).getEntity().getClass())).isTrue(); + assertThat(Phone.class.isAssignableFrom(descriptions.get(1).getEntity().getClass())).isTrue(); + assertThat(Phone.class.isAssignableFrom(descriptions.get(2).getEntity().getClass())).isTrue(); } }