Issue
I am trying to test the delete method of my repository class but I can't pass the test.
Here is my test code.
When persistAll() is called, members are added to the persistence context. And next, when flush(), 100 posts are added to the persistence context because of the Cascade.Persist option.
And I called count(), delete() and count() again to check whether the post tuple is removed from the database or not.
Here are the count() and delete() codes.
And I got this failure message from JUnit
Solution
I solved it by adding em.clear() after em.flush() in persistAll() method.
Answered By - Roger
Answer Checked By - Katrina (JavaFixing Volunteer)