title: Mock private final static object with Mockito/PowerMockito
body: <p>I'm currently trying to mock a private final static object within a class. It doesnt seem like my object is being mocked properly.  </p>
  
  <p>Example:<br>
  Code: In main class</p>
  
  <pre><code>public class Main {
  
      private final static serviceA obj = new serviceA();
  
      public somemethod { return true; }
  
  }
  </code></pre>
  
  <p>Mocked: In my test class I have </p>
  
  <pre><code>Public class TestMain {
  
      private Main mainObj;
      private static  serviceA obj;
  
      @Before
      public void setupBeforeTest() {
  
          obj = Mockito.mock(serviceA.class);
          PowerMockito.whenNew(serviceA.class).withNoArguments().thenReturn(obj);
          mainObj= Mockito.spy(new Main());
      }
  }
  </code></pre>
  
  <p>But obj doesnt return the values I specify when doing </p>
  
  <pre><code>Mockito.when(obj.returnsFalseMethod()).thenReturn(false);
  </code></pre>
  
  <p>and will actually run the code for <code>obj.returnsFalseMethod()</code>. </p>
  
  <p>Any advice would be helpful, also i cannot change any code in the Main class, thanks. </p>