mercredi 6 avril 2016

Testing expected method with EasyMock gets IllegalStateException

I am trying to test the service class to see if it calls the right method of the repository. The repository simply extends from CouchDbRepositorySupport

ServiceTest

@RunWith(EasyMockRunner.class)
@SpringApplicationConfiguration(App.class)
public class ServiceTest {

    @Rule
    public EasyMockRule mocks = new EasyMockRule(this);

    @TestSubject
    UserService userService = new UserServiceImpl();

    @Mock
    UserRepository userRepositoryMock;

@Test
    public void testGetUser() {
        User user = new User("Bob","bob87);

        user.setId("bob87"); //username is the id

        userService.getUser(user.getId());

        EasyMock.expect(userRepositoryMock.get(user.getId())).andReturn(user); //the line where the error occurs

        EasyMock.expectLastCall().times(1);

        EasyMock.replay(userRepositoryMock);

        EasyMock.verify(userRepositoryMock);
    }
}

However I get an IllegalStateException

java.lang.IllegalStateException: missing behavior definition for the preceding method call: CompanyRepository.get("Optis") Usage is: expect(a.foo()).andXXX()

Aucun commentaire:

Enregistrer un commentaire