See code just bellow
Our generic interface
public interface Repository<INSTANCE_CLASS, INSTANCE_ID_CLASS> {
void add(INSTANCE_CLASS instance);
INSTANCE_CLASS getById(INSTANCE_ID_CLASS id);
}
And a single class
public class Order {
private Integer id;
private Integer orderNumber;
// getter's and setter's
public void equals(Object o) {
if(o == null)
return false;
if(!(o instanceof Order))
return false;
// business key
if(getOrderNumber() == null)
return false;
final Order other = (Order) o;
if(!(getOrderNumber().equals(other.getOrderNumber())))
return false;
return true;
}
// hashcode
}
And when i do the following test
private Repository<Order, Integer> repository;
@Before
public void setUp {
repository = EasyMock.createMock(Repository.class);
Order order = new Order();
order.setOrderNumber(new Integer(1));
repository.add(order);
EasyMock.expectLasCall().once();
EasyMock.replay(repository);
}
@Test
public void addOrder() {
Order order = new Order();
order.setOrderNumber(new Integer(1));
repository.add(order);
EasyMock.verify(repository)
}
I get
Unexpected method call add(br.com.smac.model.domain.Order@ac66b62):
add(br.com.smac.model.domain.Order@ac66b62): expected: 1, actual: 0
at org.easymock.internal.MockInvocationHandler.invoke(MockInvocationHandler.java:43)
at org.easymock.internal.ObjectMethodsFilter.invoke(ObjectMethodsFilter.java:72)
at $Proxy4.add(Unknown Source)
Why does it not work as expected ??? What should i do to pass the test ??? Any workaround ???