would be nice to get the generated object without proxy to perform direct equals check
Hi,
Assuming the faked objects have proper hashcode / equals implementation, I would expect below test to work...
@Test
public void twoInstancesShouldBeEqualIfBuiltTheSameWay_notWorking(){
NormalRequest req1=fakeA(NormalRequest.class);
NormalRequest req2=fakeA(NormalRequest.class);
assertEquals(req1,req2);
}
.. but it doesn't probably because of all the proxy-ing that goes on.
It would be really helpful to get a real instance, through a specific method, to be able to run this. Something like :
@Test
public void twoInstancesShouldBeEqualIfBuiltTheSameWay(){
NormalRequest req1=fakeA(NormalRequest.class).getRealObject();
NormalRequest req2=fakeA(NormalRequest.class).getRealObject();
assertEquals(req1,req2);
}
Hey, sorry, wasn't notified of your issue for some reason.
I can see that, for the value objects that Fakir is designed for, equality based on value would be a bonus. For now though it looks really hard when combined with backing fields allowing setting properties.
I don't understand what realObject you're looking for. Is it an instance of NormalRequest with all the fields initialised to those that the fake has?
Could you spell out your use case in a bit more detail?
Hi, yes your understanding is correct. getRealObject would return an instance of NormalRequest (ie not proxified by anything), with all the fields having the values that were there in the fake object. This way, all assertions would work. I'll try to give you a gist with a clear example in coming days
Hi, on one of my existing project I added a branch showing the issue. you can check out https://github.com/vincent-fuchs/in-memory-testing/tree/fakir_issue5 or have a look at the test directly here :
https://github.com/vincent-fuchs/in-memory-testing/blob/fakir_issue5/src/test/java/com/github/vincent_fuchs/processors/CustomerUpgradeStatusProcessorTest.java
if I assert on field value, it works, but if I try to compare the 2 instances of CustomerStatusRequest created by Fakir, it doesn't work, even though all their fields are equal.