title: Can we create a mocked instance of java.lang.Class with PowerMock?
body: <p>I need to write a test that mocks a instance of the java.lang.Class class. 
  Is this possible via PowerMock?</p>
  
  <p>I tried to do following:</p>
  
  <pre><code>PowerMock.createMock(Class.class);
  </code></pre>
  
  <p>And the result is:</p>
  
  <pre><code>java.lang.IllegalAccessError: java.lang.Class
      at sun.reflect.GeneratedSerializationConstructorAccessor12.newInstance(Unknown Source)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
      at org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.newInstance(SunReflectionFactoryInstantiator.java:40)
      at org.powermock.reflect.internal.WhiteboxImpl.newInstance(WhiteboxImpl.java:223)
      at org.powermock.reflect.Whitebox.newInstance(Whitebox.java:139)
      at org.powermock.api.easymock.PowerMock.doMock(PowerMock.java:2146)
      at org.powermock.api.easymock.PowerMock.createMock(PowerMock.java:89)
  </code></pre>
  
  <p>According to the documentation of PowerMock this should be possible but still I get this error. </p>
  
  <p>Did someone manage to do this?</p>
  
  <p>Edit: 
  Why do I need this? 
  In the tested coding there is following statement:</p>
  
  <pre><code>if (someObject.getClass().getName().equals(SOME_CLASS_NAME_THAT_I_DONT_HAVE_ACCESS_TO)) { ... do some stuff ... }
  </code></pre>
  
  <p>I need my test to reach the coding inside the "if" and I CANNOT provide even a mocked instance of the class that has the corresponding name.</p>
  
  <p>As a workaround I can just create a class with the same name and package in the tests but it is ugly.</p>
  
  <p>Edit2: </p>
  
  <p>I tried also the suggestions from <a href="https://code.google.com/p/powermock/source/browse/trunk/modules/module-test/mockito/junit4/src/test/java/samples/powermockito/junit4/system/SystemClassUserTest.java" rel="noreferrer">this link</a> </p>
  
  <pre><code>import org.junit.runner.RunWith;
  import org.powermock.api.easymock.PowerMock;
  import org.powermock.core.classloader.annotations.PrepareForTest;
  import org.powermock.modules.junit4.PowerMockRunner;
  import org.junit.Test;
  
  @RunWith(PowerMockRunner.class)
  @PrepareForTest({Test1.class})
  public class Test1 {
  
      @Test
      public void test() {
          PowerMock.createMock(Class.class);
      }
  
  }
  </code></pre>
  
  <p>And the result is the same: "java.lang.IllegalAccessError: java.lang.Class"</p>
  
  <p>So as a final result - it seems that there is no way to create a mocked instance of java.lang.Class</p>
  
  <p>Thank you</p>