title: Mocking method calls using power mockito - org.powermock.api.mockito.ClassNotPreparedException
body: <p>I have an image loader class and i need to test some static methods in it. Since Mockito does not support static methods i switched to Power Mockito. But the static method i am testing has a method call  </p>
  
  <pre><code> Base64.encodeToString(byteArray, Base64.DEFAULT);
  </code></pre>
  
  <p>To mock this i am using <strong>mockStatic</strong> method as below with @PrepareForTest annotation.</p>
  
  <pre><code> PowerMockito.mockStatic(Base64.class);
  </code></pre>
  
  <p>But Android studio is returning me still returning me an error as below.</p>
  
  <blockquote>
    <p>org.powermock.api.mockito.ClassNotPreparedException:  The class
    android.util.Base64 not prepared for test. To prepare this class, add
    class to the '@PrepareForTest' annotation.</p>
  </blockquote>
  
  <p>Below is my complete code.</p>
  
  <p>Code to be tested:</p>
  
  <pre><code>import android.graphics.Bitmap;
  import android.graphics.BitmapFactory;
  import android.util.Base64;
  import android.widget.ImageView;
  
    public static String convertBitmapToBase64(Bitmap imageBitmap, boolean withCompression) {
      ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
      imageBitmap.compress(Bitmap.CompressFormat.PNG, 120, byteArrayOutputStream);
      byte[] byteArray = byteArrayOutputStream.toByteArray();
      return Base64.encodeToString(byteArray, Base64.DEFAULT);
  }
  </code></pre>
  
  <p>Test class code</p>
  
  <pre><code>import android.graphics.Bitmap;
  import android.util.Base64;
  import org.junit.Before;
  import org.junit.runner.RunWith;
  import org.mockito.MockitoAnnotations;
  import org.powermock.api.mockito.PowerMockito;
  import org.powermock.core.classloader.annotations.PrepareForTest;
  import org.powermock.modules.junit4.PowerMockRunner;
  import org.testng.annotations.Test;
  
  @RunWith(PowerMockRunner.class)
  @PrepareForTest({Base64.class})
  public class ImageLoaderTest  {
  @Test
     public void testConvertBitmap(){
      byte[] array = new byte[20];
      PowerMockito.mockStatic(Base64.class);
      PowerMockito.when(Base64.encodeToString(array, Base64.DEFAULT)).thenReturn("asdfghjkl");
      Bitmap mockedBitmap= PowerMockito.mock(Bitmap.class);
      String output = ImageLoaderUtils.convertBitmapToBase64(mockedBitmap);
      assert (!output.isEmpty());
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Gradle dependencies</p>
  
  <pre><code>testCompile 'junit:junit:4.12'
  testCompile 'org.powermock:powermock:1.6.5'
  testCompile 'org.powermock:powermock-module-junit4:1.6.5'
  testCompile 'org.powermock:powermock-api-mockito:1.6.5'
  </code></pre>