提交 eda193fc 编写于 作者: S Sam Brannen

Added assertPersonCount() functionality for increased robustness.

上级 66a79955
...@@ -52,6 +52,14 @@ public class HibernateSessionFlushingTests extends AbstractTransactionalJUnit4Sp ...@@ -52,6 +52,14 @@ public class HibernateSessionFlushingTests extends AbstractTransactionalJUnit4Sp
private SessionFactory sessionFactory; private SessionFactory sessionFactory;
protected int countRowsInPersonTable() {
return countRowsInTable("person");
}
protected void assertPersonCount(int expectedCount) {
assertEquals("Verifying number of rows in the 'person' table.", expectedCount, countRowsInPersonTable());
}
@Before @Before
public void setUp() { public void setUp() {
assertInTransaction(true); assertInTransaction(true);
...@@ -72,7 +80,9 @@ public class HibernateSessionFlushingTests extends AbstractTransactionalJUnit4Sp ...@@ -72,7 +80,9 @@ public class HibernateSessionFlushingTests extends AbstractTransactionalJUnit4Sp
public void saveJuergenWithDriversLicense() { public void saveJuergenWithDriversLicense() {
DriversLicense driversLicense = new DriversLicense(2L, 2222L); DriversLicense driversLicense = new DriversLicense(2L, 2222L);
Person juergen = new Person(JUERGEN, driversLicense); Person juergen = new Person(JUERGEN, driversLicense);
int numRows = countRowsInPersonTable();
personService.save(juergen); personService.save(juergen);
assertPersonCount(numRows + 1);
assertNotNull("Should be able to save and retrieve Juergen", personService.findByName(JUERGEN)); assertNotNull("Should be able to save and retrieve Juergen", personService.findByName(JUERGEN));
assertNotNull("Juergen's ID should have been set", juergen.getId()); assertNotNull("Juergen's ID should have been set", juergen.getId());
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册