EasyMock failed with java.lang.IllegalStateException

49 views Asked by At

I have below -

List<Long> getEmployeeId(Long deptId, Date joiningDate, List<String> technologies);

I am trying to write a Junit for above method by using EasyMock

EasyMock.expect(empDao.getEmployeeId(EasyMock.anyLong(),  EasyMock.anyObject(Date.class),EasyMock.anyObject(List.class))).andReturn(empIdList).anyTimes();
replay(empDao);

but I am getting java.lang.IllegalStateException for EasyMock.expect(..)

I am not sure what I am missing here.

1

There are 1 answers

0
Henri On

I will need a bit more input. The EasyMock version, the full error and so on. Because when trying the following, it works perfectly.

import java.util.Collections;
import java.util.Date;
import java.util.List;

import static org.easymock.EasyMock.anyLong;
import static org.easymock.EasyMock.anyObject;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.mock;
import static org.easymock.EasyMock.replay;

public class MyTest {

    public List<Long> getEmployeeId(Long deptId, Date joiningDate, List<String> technologies) {
        return null;
    }

    @Test
    public void test() {
        MyTest test = mock(MyTest.class);
        expect(test.getEmployeeId(anyLong(), anyObject(Date.class), anyObject(List.class))).andReturn(Collections.emptyList()).anyTimes();
        replay(test);
    }
}