title: How to get intance of InvocationContext for unit tests
body: <p>I am trying to write a unit test for a method taking the InvocationContext as parameter. More specifically here's the signature and essentials of the method.</p>
  
  <pre><code>@AroundInvoke
  public Object autoLogMethodCall(final InvocationContext context) throws Exception {
  
      String className = context.getClass().getSimpleName();
      String packageName = context.getClass().getPackage().getName();
      String methodName = context.getMethod().getName();
  
      // Some logging stuff that is the target of actual testing
  }
  </code></pre>
  
  <p>As you see, it is an interceptor method I intend to use for doing some basic logging for certain method calls.</p>
  
  <p>Then I have unit test which I want to test that the logged messages will be properly formatted. But the problem is that that I can not create an instance of the <strong>InvocationContext</strong> to pass as a parameter for testing.</p>
  
  <p>I have tried the following mocking. </p>
  
  <pre><code>@RunWith(PowerMockRunner.class)
  public class AutoLoggingTest extends TestCase {
  
      @Test
      public void testAutoLogger() {
          Logger log = new MyLogger(); // This is an implementation of org.apache.logging.log4j.Logger, which will hold the generated messages to check at the test
          InvocationContext mockContext = PowerMockito.mock(InvocationContext.class);
          Class clazz = AutoLoggingTest.class;
          // The row causing the error 'MissingMethodInvocation'
          PowerMockito.when(mockContext.getClass()).thenReturn(clazz);
  
  try {
      InterceptingClass ic = new InterceptingClass();
      ic.setLogger(log);
      ic.autoLogMethodCall(mockContext);
      MyLogger myLogger = (MyLogger) ic.getLogger();
      assertEquals(2, myLogger.getMessages().size());
          } catch (Exception e) {
              e.printStackTrace();
              fail("Should not cause an exception in any case");
          }
      }
      // Check the actual messages based on the information given in mocked InvocationContext object
  }
  </code></pre>
  
  <p>But it does not work.<br/>
      causes:</p>
  
  <blockquote>
    <p>Tests in error: 
        AutoLoggingTest.testAutoLogger:25 » MissingMethodInvocation.<br/>
        when() requires an argument which has to be 'a method call on a mock'.).</p>
  </blockquote>
  
  <p>Any advice on how to do the mocking properly?</p>