title: In testing in java how to check if a method of an interface is called or not?
body: <p>I want to test this class which calls a method of interface using anonymous class.</p>
  
  <pre><code>public class ClassToTest 
  {
      public void methodToTest()
      {
          InterefaceToMock interefaceToMockReference = new InterefaceToMock() {
  
              @Override
              public int methodToMock()
              {
                  return 0;
              }
          };
          interefaceToMockReference.methodToMock();
      }
  }
  </code></pre>
  
  <p>This is the interface</p>
  
  <pre><code>public interface InterefaceToMock 
  {
      public int methodToMock();
  }
  </code></pre>
  
  <p>I am using this approch to check it methodToMock is called or not</p>
  
  <pre><code>import static org.junit.Assert.*;
  
  import org.junit.Test;
  
  import mockit.FullVerificationsInOrder;
  import mockit.Mocked;
  import mockit.NonStrictExpectations;
  public class TestAClass 
  {
      @Mocked InterefaceToMock interefaceToMockReferenceMocked;
      @Test
      public void test1()
      {
          new NonStrictExpectations()
          {
              {
                  interefaceToMockReferenceMocked.methodToMock();times=1;
              }
          };
          (new ClassToTest()).methodToTest();
          new FullVerificationsInOrder(interefaceToMockReferenceMocked)
          {
          };
          assertTrue(true);
      }
  }
  </code></pre>
  
  <p>But test case fails.
  Can anyone help.</p>