@Test
public void testNoStackOverflowOnObjectCycle() {
PersonImpl cycle1 = new PersonImpl("cycle1", 30, null);
Person cycle2 = new PersonImpl("cycle2", 5, cycle1);
cycle1.setMother(cycle2);
try {
Statement snapshotStmt = SnapshotMaker.makeSnapshotAsSubclass(cycle2, Person.class, Person.class, null, Person.class);
snapshotStmt.generate(Context.create());
Assert.fail("Instance cycle was not detected");
}
catch (CyclicalObjectGraphException e) {
assertTrue(e.getObjectsInvolvedInCycle().contains(cycle1));
assertTrue(e.getObjectsInvolvedInCycle().contains(cycle2));
}
}