title: Using EasyMock to mock an interface that accepts arguments
body: <p>I have a class <code>MyClass</code> that contains a constructor that calls an interface <code>MyInterface</code>. <code>MyInterface</code> contains a method <code>validator</code> that accepts an <code>Int</code> and a <code>String</code>.</p>
  
  <p>I need to use EasyMock to mock a return <code>Boolean</code> value from <code>MyInterface.validator</code> within a JUnit test.</p>
  
  <p>I have made several attempts at this put I only get Java Exceptions when I try to call <code>MyInterface.validator</code> from <code>MyClass</code>.</p>
  
  <pre><code>public class MyClass {
  
  public MyInterface myInterface;
  public int test;
  
  public MyClass (int INT, String STRING, MyInterface myInterface) {
  
      this.myInterface = myInterface;
      this.test = INT;
      myInterface.validator(INT, STRING);
  
  }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>public interface MyInterface {
  public Boolean validator(int INT, String STRING);
  }
  </code></pre>
  
  <hr>
  
  <pre><code>public class MyClassTest {
  MyInterface mockMyInterface;
  MyClass myClass;
  
  @Before
  public void setUp() throws Exception {
      mockMyInterface = createMock(MyInterface.class);
  }
  
  @Test
  public void test() {
      myClass = new MyClass(10, "Test", mockMyInterface);
      expect(mockMyInterface.validator(10, "Test")).andStubReturn(true);
      replay(mockMyInterface);
      assertEquals(myClass.test, 10);
      verify(mockMyInterface);
  }
  }
  </code></pre>