What should i do to test EasyMock objects when using Generics ? EasyMock

Posted by Arthur Ronald F D Garcia on Stack Overflow See other posts from Stack Overflow or by Arthur Ronald F D Garcia
Published on 2010-03-24T21:16:52Z Indexed on 2010/03/24 21:33 UTC
Read the original article Hit count: 417

Filed under:
|
|
|

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

Why does it not work as expected ??? What should i do to pass the test ???

© Stack Overflow or respective owner

Related posts about java

Related posts about generics