title: Mocking Java Constant variables (public static) using Mockito/JUnit
body: <p>I need to mock the constant variable in order to test one of my method. How can I do it with Mokito and Junit.</p>
  
  <pre><code>  @Component( "mybean" )
    @org.springframework.context.annotation.Scope( value="session" )  
    public class MyBean {
  
      Public void methodToBeTested() {
         if (!AppConst.SOME_CONST.equals(obj.getCostCode())) {
           // some logic
         }
      }
   }
  </code></pre>
  
  <p>AppConst class</p>
  
  <pre><code>@Configuration
  public class AppConst
  {
     public static  String  SOME_CONST;
     public static  String  HOST_URL;
  
     @PostConstruct
     public void postConstruct()
     {
       SOME_CONST = "My Code";
       HOST_URL  = "Some URL";
  
     }
  }
  </code></pre>
  
  <p>So, from my junit test class, how can I mock the AppConst and it's variables? Now, when I run it, i hit a nullpointer error.</p>
  
  <p>Can this be done with powermock? if yes please give some sample</p>
  
  <p>Mockito version I use.</p>
  
  <p><code>compile "org.mockito:mockito-all:1.9.5"
  compile "org.powermock:powermock-mockito-release-full:1.6.1"</code></p>