Fixture.of(Father.class).addTemplate("valid", new Rule() {{
...
add("son", one(Son.class, "valid");
...
}});
Fixture.of(Son.class).addTemplate("valid", new Rule() {{
add("id", 1);
...
}});
I created a custom HibernateProcessor that persist generated fixtures to database but if generated fixture has id property different from null, instead of persist I want to load it from database.
public void execute(Object result) {
if(isIdDifferentFromNull()) {
result = session.load(result.class, id);
} else {
session.save(result);
}
}
I have a
Father
class that has oneSon
class.We defined
Father
andSon
templates.I created a custom
HibernateProcessor
that persist generated fixtures to database but if generated fixture hasid
property different from null, instead of persist I want to load it from database.The problem is that the loaded result is not used by Fixture-Factory, because result parameter has a reference copy of original result and applying loaded result to result parameter does no affect the generated result used internal by Fixture-Factory. (reference http://www.javaworld.com/article/2077424/learn-java/does-java-pass-by-reference-or-pass-by-value.html)
We can change
Processor
interface to return the processed object instead of return void.And in
ObjectFactory
we can use the processed object instead of generated object. Current implementation:Suggested implementation
@aparra @ahirata @bjornnborg @douglasrodrigo what do you guys think about it?