请参见下面的代码
我们的通用接口
public interface Repository<INSTANCE_CLASS, INSTANCE_ID_CLASS> {
void add(INSTANCE_CLASS instance);
INSTANCE_CLASS getById(INSTANCE_ID_CLASS id);
}
和一个单一的班级
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
}
当我进行以下测试时
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)
}
我明白了
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)
为什么它不能按预期工作???我该怎么做才能通过测试???任何解决方法???