title: doNothing() method is calling actual method
body: <p>I'm trying to doNothing() when a final void method is called, but the doNothing() call is calling the actual method instead.</p>
  
  <p>SwitchWorker class</p>
  
  <pre><code>public class SwitchWorker {
  
      public boolean switchMethod(String id){
          this.methodA(id);
          return true;
      }
  
      public void methodA(String id){
          final Switch switchObj = Switch.getSwitchInstance(); 
          switchObj.finalVoidMethod(id);
          // XYZ......
      }
  }
  </code></pre>
  
  <p>Switch Class</p>
  
  <pre><code>public final class Switch {
      private static final Switch INSTANCE = new Switch();
      private Switch() { //Private Constructor
          super();
      }
      public static Switch getSwitchInstance() {
          return INSTANCE;
      }
      public final synchronized void finalVoidMethod(String param) {
          // Do Something
      }    
  }
  </code></pre>
  
  <p>Test code:</p>
  
  <pre><code> @RunWith(PowerMockRunner.class)
   @SuppressStaticInitializationFor("com.application.switching.Switch")
   public class SwitchWorkerTest {
  
          @Test
          public void test() throws Exception {
              SwitchWorker swObj = new SwitchWorker();
  
              final String channelId = "0001";
  
              Switch switchMock = mock(Switch.class);
              PowerMockito.mockStatic(Switch.class);
              when(Switch.getSwitchInstance()).thenReturn(switchMock);
  
              doNothing().when(switchMock).finalVoidMethod(channelId);
  
              boolean result = swObj.switchMethod(channelId);
              assertTrue(result);                            
          }
  </code></pre>
  
  <p>Am I missing anything for the doNothing() method?   </p>
  
  <pre><code>"doNothing().when(switchMock).finalVoidMethod(channelId);"
  </code></pre>
  
  <p>doNothing() is calling the actual finalVoidMethod() instead of mocking. But, switchMock is a Mocked object. </p>
  
  <p>I've looked at almost every question on stack overflow regarding PowerMockito, mocking static methods, and doNothing methods, I'm not sure if I'm missing anything as I've followed most examples to build the code. I've added @PrepareForTest too but later removed it.  </p>
  
  <p>Thank you.</p>
  
  <p>edit: I snipped the code to be more abstract and changed slightly to fit @kswaughs comment </p>
  
  <pre><code>public boolean mockedMethod(final String input) {
      System.out.println("0----------------------");
      final Switch switchObj = Switch.getSwitchInstance();
      System.out.println("1:switchObj: "+ switchObj);
      switches.refresh("input");
      System.out.println("2----------------------");
      return true;
  }
  </code></pre>
  
  <p>With test code:   </p>
  
  <pre><code>@RunWith(PowerMockRunner.class)
  @PrepareForTest({Switch.class, SwitchWorker.class})
  public class SwitchWorkerTest {
      @Test
      public void test() throws Exception {
          SwitchWorker swObj = new SwitchWorker();
  
          Switch switchMock = mock(Switch.class);
          PowerMockito.mockStatic(Switch.class);
          when(Switch.getSwitchInstance()).thenReturn(switchMock);
          boolean result = swObj.mockedMethod("0001");
          assertTrue(result); 
  </code></pre>
  
  <p>returns . </p>
  
  <pre><code>0----------------------
  1:switchObj: Mock for Switch, hashCode: 1659309731
  
  java.lang.NullPointerException
  at com.application.switching.Switch.refresh(Switch.java:238)
  at com.application.switching.SwitchWorker$1.run(SwitchWorker.java:51)
  </code></pre>