title: Creating Mock object using Mockito and PowerMockito
body: <p>I'm having a class called <code>SampleClass</code>. This has many static fields and this class is currently used in some other class. I'm new to Mockito and Power Mockito. I have been struggling to mock <code>SampleClass</code>. Can you guys please help by letting me know how to mock the <code>SampleClass</code>.</p>
  
  <p>I have provided both the SampleClass and its usage details below for your reference.</p>
  
  <p><strong><em>SampleClass.java:</em></strong></p>
  
  <pre><code>public class SampleClass {
      private static CatFactory catFactory = null;
      private static String catPath = SampleConfigurationManager.getInstance().getProperty("locale_path", "");
      private static URI catURI = (new File(catPath)).toURI();
  
      private static SampleClass catBusinessLogic;
      private static Logger logger = Logger.getInstance(SampleClass.class);
  
  
      private SampleClass() {
          initializeCatFactory();
      }
  
      public static SampleClass getInstance() {   
          try{
              if(catBusinessLogic == null) {
                  catBusinessLogic = new SampleClass();   
              }
          }catch(Exception e ){
              e.printStackTrace();
          }
  
          return catBusinessLogic;
      }
  
      public Cat getCat(String code) throws CatException {
          logger.log(LogLevel.DEBUG, "SampleClass::getCat ENTRY");
          Cat countryCat = null;
          if (catFactory != null) {
              countryCat = catFactory.getCat(code);
          }
          logger.log(LogLevel.DEBUG, "SampleClass::getCat EXIT");
  
          if( countryCat == null ) {
              throw new CatException("Failed to create CAT object");
          }
          return countryCat;
      }
  
      public static void initializeCatFactory() throws CatException{
          logger.log(LogLevel.DEBUG, "SampleClass::initializeCatFactory ENTRY");
          try {
              catFactory = new CatFactory(catURI.toURL());
          } catch (MalformedURLException mue) {
              logger.log(LogLevel.FATAL, "MalformedURLException while creating CATFactory " + mue.toString());
              throw new CatException("Failed to create CATFactory");
          }
          logger.log(LogLevel.DEBUG, "SampleClass::initializeCatFactory EXIT");
      }
  }
  </code></pre>
  
  <p><strong><em>Usage of SampleClass in some other class:</em></strong></p>
  
  <pre><code>SampleClass sampleClass = SampleClass.getInstance();
  String code = "ABC";
  Cat cat = sampleClass.getCat(code);
  CATUtil catUtil = new CATUtil(cow);
  </code></pre>