I know this post doesnt have much to do with the Spring framework but wanted to get some feedback from fellow developers as this must be a common problem.
Furthermore I using Spring for integration testing purposes where Im testing business methods expose by a service layer. More so the problem I have is that part of the integration testing is to create/mock domain models/objects used by the services ie.:
Two problems im facing:Code:Client client = EasyMock.createNiceMock(Client.class); EasyMock.expect(client.getPrimaryId()).andReturn("simpsonb"); EasyMock.replay(client); Collection<Address> data = getServiceLocator().getAddressService().findAddressesByClient(client); assertNotNull(data); assertEquals(3, data.size()); EasyMock.verify(client);
1. If I use EasyMock as above ALL my domain models that I want to mock have to be interfaces of which currently no domain models are as to me this is an extreme case of too many interfaces especially as all my models are hibernate specific. Find below an outline of the Client model:
2. Im trying to replicate an invocation to the "getPrimaryId()" method of which is causing an issue when I mock the Client.class using either Mockito and EasyMock as the getPrimaryId() method is used in the "equals()" method in the domain model. This is causing a StackOverflow as both mocking frameworks use the equals method to determine which mock object to evaluation and test against. The equals method is as follow:Code:@Entity @Table(name = "Client") public class Client extends BaseLookupModel<String> { @Id @GeneratedValue(generator = "ClientIDGenerator") @GenericGenerator(name = "ClientIDGenerator", strategy = ClientIDGenerator.STRATEGY) @Column(name = "ClientCode") @Audited private String primaryId; @Column(name = "GroupCode") @Audited private String group; @Column(name = "TitleCode") private String title; @Column(name = "Initials") private String initials; ... }
Any feedback will be awesome, thanks.Code:@Override public final boolean equals(Object obj) { if(!(obj instanceof BaseModel<?>)) { return false; } BaseModel<?> baseEntity = (BaseModel<?>)obj; if(baseEntity.getPrimaryId() != null && getPrimaryId() != null) { return baseEntity.getPrimaryId().equals(this.getPrimaryId()); } else { return super.equals(obj); } }


Reply With Quote
