title: How to mock static final variable in a final class
body: <p>Please note : Don't delete this thread / post as There is no proper answer available an any of page of StackOverflow. My question is totally different.</p>
  
  <p>I want to mock a private static final field OF A FINAL CLASS</p>
  
  <p>I ahve tried with solution given on <a href="https://stackoverflow.com/questions/9697531/how-to-mock-a-static-final-variable-using-junit-easymock-or-powermock">How to mock a static final variable using JUnit, EasyMock or PowerMock</a></p>
  
  <p>static void setFinalStatic(Field field, Object newValue) throws IllegalAccessException, NoSuchFieldException{
          field.setAccessible(true);</p>
  
  <pre><code>    // remove final modifier from field
      Field modifiersField = Field.class.getDeclaredField("modifiers");
      modifiersField.setAccessible(true);
      modifiersField.setInt(field, field.getModifiers() &amp; ~Modifier.FINAL);
  
      field.set(null, newValue);
  }
  </code></pre>
  
  <p>But it is giving me ExceptionInInitializerError at "field.set(null, newValue);"</p>
  
  <p>Please advice</p>