public void testSnapshot() {
EOEditingContext ec = ERXEC.newEditingContext();
Company company = Company.createCompany(ec, "Test Company");
Employee employee = Employee.createEmployee(ec, "John", "Doe", Boolean.FALSE, company);
Role role1 = Role.createRole(ec);
employee.addToRoles(role1);
NSDictionary<String, Object> snapshot = employee.snapshot();
NSDictionary committedSnapshot = employee.committedSnapshot();
/*
* Snapshot should have same values as the eo and committed snapshot should be all
* null values as eo has not yet been saved.
*/
EOEntity entity = employee.entity();
for (String key : (NSArray<String>) entity.classPropertyNames()) {
Object snapshotValue = snapshot.valueForKey(key);
assertEquals(employee.valueForKey(key), ERXValueUtilities.isNull(snapshotValue) ? null : snapshotValue);
assertTrue(ERXValueUtilities.isNull(committedSnapshot.valueForKey(key)));
}
ec.saveChanges();
Role role2 = Role.createRole(ec);
employee.addToRoles(role2);
employee.removeFromRoles(role1);
NSDictionary changesFromCommittedSnapshot = employee.changesFromCommittedSnapshot();