title: Mock ClassLoader.getSystemClassLoader().loadClass with Powermockito
body: <p>I am trying to test utility method which check if particular class is on class path, if yes <code>return true</code> else <code>return false</code>.</p>
  
  <p>Why I am doing this: I have to independent classes extending same class, and only one of it will be on classpath. Need to do specific thing if one particular is on classpath.</p>
  
  <p>Using kind of below method to check if particular class is on class path. 
  This check will be done only once after first request.
  I'd checked <code>Class.forName()</code> also but decided to go with below approach.</p>
  
  <p>My utility method looks something like this:</p>
  
  <pre><code>public static boolean isMyClassOnClassPath() {
      try {
          ClassLoader.getSystemClassLoader().loadClass("com.MyClass");
          return true;
      } catch (ClassNotFoundException ex) {
          return false;
      }
  </code></pre>
  
  <p>}</p>
  
  <p>Checking <code>false</code> condition is easy as particular class is not not the ClassPath.
  I'm trying to write <code>Junit</code> for positive scenario when this method will return <code>true</code>.</p>
  
  <pre><code>@Test
  public void isMyClassOnClassPathShouldReturnTrueWhenMyClassIsOnClassPath() throws Exception{
      PowerMockito.mockStatic(MyClass.class);
      ClassLoader classLoader = PowerMockito.mock(ClassLoader.class);
      PowerMockito.mockStatic(ClassLoader.class);
      PowerMockito.when(ClassLoader.getSystemClassLoader()).thenReturn(classLoader);
  
      //trying to mock classLoader.loadClass, below way is incorrect
      //PowerMockito.when(classLoader.loadClass("com.MyClass")).thenReturn(Class&lt;java.lang.Object.class&gt;);
      Assert.assertTrue(MyClassUtil.isMyClassOnClassPath());
  }
  </code></pre>
  
  <p>So is it possible to mock <code>classLoader.loadClass()</code> method? </p>