org.mockito.exceptions.misusing.MissingMethodInvocationException: when() requires an argument which has to be 'a method call on a mock'
<p>I have developed one spring sample project with a controller and called a static method in it.</p>

<p>When I try to run the code, it leads me to an exception.</p>

<p><strong>LoginController .java</strong></p>

<pre><code>@Controller
public class LoginController {@ResponseBody
@RequestMapping(value="/login")
public String login(){
    System.out.println("in login method");
    String s = SampleClass.method();
    System.out.println("String value :  "+s);
    return "welcome to login page";
}}
</code></pre>

<p><strong>SampleClass.java</strong></p>

<pre><code>public class SampleClass {

public static String method(){
    System.out.println("in static method");
    return "static method";
}}
</code></pre>

<p><strong>LoginControllerTest.java</strong></p>

<pre><code>@PrepareForTest(SampleClass.class)
public class LoginControllerTest {

private MockMvc mockMvc;

@InjectMocks
private LoginController loginController;


@Before
public void setUp() {

    System.out.println("in setup");
    PowerMockito.mockStatic(SampleClass.class);

    MockitoAnnotations.initMocks(this);
    mockMvc = MockMvcBuilders.standaloneSetup(loginController).build();
    System.out.println("setupdone");

}

@Test
public void loginTest() throws Exception{
    System.out.println("in login test");
    PowerMockito.when(SampleClass.method()).thenReturn("hello");
    mockMvc.perform(get("/login"))
    //.andDo(print())
    .andExpect(status().isOk());
    System.out.println("test completed");
}}
</code></pre>

<p><strong>Error</strong></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>
  
  <p>Also, this error might show up because:
  1. you stub either of: final/private/equals()/hashCode() methods.    Those methods <em>cannot</em> be stubbed/verified.    Mocking methods
  declared on non-public parent classes is not supported.
  2. inside when() you don't call method on mock but on some other object.</p>
  
  <p>at org.powermock.api.mockito.PowerMockito.when(PowerMockito.java:495)
    at
  com.junit.example.controller.LoginControllerTest.setUp(LoginControllerTest.java:57)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at
  sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)   at
  sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)   at
  java.lang.reflect.Method.invoke(Unknown Source)   at
  org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at
  org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at
  org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at
  org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)    at
  org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at
  org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)  at
  org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)   at
  org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)     at
  org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)   at
  org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)  at
  org.junit.runners.ParentRunner.run(ParentRunner.java:309)     at
  org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at
  org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at
  org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at
  org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at
  org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at
  org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)</p>
</blockquote>

<p>Can any one help me out with a solution?</p>