title: How to inject EasyMock mock into tested class private field
body: <p>I'm using EasyMock to create mock that is one of private parameters (without setter) in tested class. I tried using reflection - but it does not work correctly. </p>
  
  <pre><code>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);
     }
  }
  </code></pre>
  
  <p>Im getting FAILED info:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Im sure this method is fired on "MockedClass" object during tested "instance.someAction()"</p>
  
  <p>How to resolve this problem?</p>
  
  <p>Edited - Answer :
  After correcting doubled <code>replay.mocked()</code> I found (so simple!) that one more void method should be declared using   <code>EasyMock.expectLastCall()</code></p>