I am trying to get some tests to work without relying on the app's DB. The app is using JPA w/Hibernate. I have tried annotating the class with @Transactional
on both the method and the class without success.
Here is the relationship in Employee.java
:
@OneToMany(mappedBy = "manager", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private List<Employee> directReports;
Here's the test, the last arg is the manager
:
Employee ceo;
Employee evp;
@Before
public void setup() {
ceo = new Employee("Name", "ceo", null);
evp = new Employee("Name", "evp", ceo);
}
@Test
public void testThatDirectReportsAreAssignedWithoutPersistence() {
assertNotNull(ceo.getDirectReports());
}