How to insert EasyMock into a specific class

I use EasyMock to create a layout, which is one of the private parameters (without setter) in the tested class. I tried using reflection, but it does not work correctly.

public class TestedClassTest{
    @Test
    public void test(){
      TestedClass instance = new TestedClass();
      MockedClass mocked = EasyMock.createMock(MockedClass.class);
      Data data = new Data();

      //Void setter
      DataType dataType = (myDataType.DataType) EasyMock.anyObject();
      mocked.setDataType(dataType);
      EasyMock.expectLastCall();

      //expect
      EasyMock.expect(mocked.getData()).andReturn(data);
      EasyMock.replay(mocked);

      Field field = instance.getClass().getDeclaredField("mockedClass")
      field.setAccessible(true);
      field.set(instance, mocked);

      //run tested method
      instance.someAction();

      EasyMock.verify(mocked);
   }
}

Im getting FAILED info:

Unexpected method call MockedClass.setDataType(myData.MyData@104306d75):
MockedClass.getData(): expected: 1, actual: 0
junit.framework.AssertionFailedError: 
Unexpected method call MockedClass.setDataType(myData.MyData@132006d75):
MockedClass.getData(): expected: 1, actual: 0

I am sure that this method is launched on the "MockedClass" object during the tested "instance.someAction ()"

How to solve this problem?

Edited - Answer: After fixing the double replay.mocked()I found (so easy!) That another void method should be declared usingEasyMock.expectLastCall()

+5
source share
1 answer

The reflection code looks fine.

, EasyMock, replay ? . replay.

, , mock, ? , , .

EDIT - - , setDataType mock, , . , , , , ( , ).

+3

All Articles