title: Mocking static method throws error with parameters
body: <p>I have custom Log4j2 appender:</p>
  <pre><code>    @Plugin(
              name = &quot;MyAppender&quot;,
              category = &quot;Core&quot;,
              elementType = Appender.ELEMENT_TYPE)
      public class MyAppender extends AbstractAppender {
      
          private static final Logger LOGGER = LoggerFactory.getLogger(MyAppender.class);
          private final Lock lock = new ReentrantLock();
      
      
          private MyAppender(final String name, final Layout&lt;? extends Serializable&gt; layout ) {
              super(name, null, layout, false, Property.EMPTY_ARRAY);
          }
      
      
          @Override
          public void append(LogEvent event) {
             ....
          }
      
          @PluginFactory
          public static MyAppender createAppender(
                  @PluginAttribute(&quot;name&quot;) String name,
                  @PluginElement(&quot;Layout&quot;) Layout&lt;? extends Serializable&gt; layout){
              if (layout == null) {
                  layout = PatternLayout.createDefaultLayout();
              }
              return new MyAppender(name, layout);
          }
  }
  </code></pre>
  <p>And i want to mock the <code>createAppenderMethod</code>:</p>
  <pre><code> try (MockedStatic&lt;MyAppender&gt; mocked = mockStatic(MyAppender.class)) {
              MyAppender appender = Mockito.mock(MyAppender.class);
              mocked.when(() -&gt; MyAppender.createAppender(&quot;myAppender&quot;, Mockito.any(Layout.class))).thenReturn(appender);
                ....
          }
  </code></pre>
  <p>However this trows</p>
  <blockquote>
  <p>org.mockito.exceptions.misusing.WrongTypeOfReturnValue:  MyAppender
  cannot be returned by toString() toString() should return String</p>
  </blockquote>
  <p>I tried to implement <code>toString()</code> method but the error remains the same.</p>
  <p>If u use
  <code> mocked.when(() -&gt; MyAppender.createAppender(&quot;myAppender&quot;, Mockito.anyObject())).thenReturn(appender);</code></p>
  <p>then i recieve:</p>
  <blockquote>
  <p>org.mockito.exceptions.misusing.MissingMethodInvocationException:
  when() requires an argument which has to be 'a method call on a mock'.
  For example:
  when(mock.getArticles()).thenReturn(articles);</p>
  </blockquote>
  <p>Why is this happening? What is the correct way to mock this? So far this way of mocking static methods worked for me</p>