title: Mockito: Unable to mock a static & non-static method
body: <p>I am unable to mock anything(static or non static methods) from mockito,</p>
  
  <p>These are my classes,</p>
  
  <p>Calculations.java</p>
  
  <pre><code>public class Calculations {
  
      public void printZero() {
          System.out.println("zero");
      }
  
      public static void printOne() { 
           System.out.println("one");
      }
  }
  </code></pre>
  
  <p>This is my PostData.java</p>
  
  <pre><code>public class PostData {
  
      public static Calculations calc = new Calculations();
      public static void postTheData() {
  
          calc.printZero();
          Calculations.printOne();
      }
  }
  </code></pre>
  
  <p>The unit test class,
  TestClass.java</p>
  
  <pre><code>public class TestClass {
  
      @Test
      public void addTest() {
  
          Calculations lmock = mock(Calculations.class);
  
          // can't have Calculations.calc.printZero() in when() :cause: argument passes to when() must be a mock object.
          doNothing().when(lmock).printZero();
  
          // cause: method when(void) is undefined for the type TestClass
          // when(lmock.printZero()).doNothing();
  
          // cause: argument passed to when() must be a mock object.
          // doNothing().when(Calculations.printOne());
  
          PostData.postTheData();
      }
  }
  </code></pre>
  
  <p>Its compiled and its printing "zero" as well as "one" in my output, which ideally should have been ignored.</p>
  
  <p>I am using cloud-mockito-all-1.10.19.jar for mockito.
  And junit's latest jar file.</p>
  
  <p>I know I am missing something here, but can't figure out what! It would be a great help if you can answer me.</p>