title: how to mock keystore.getInstance() which returns the keystore object?
body: <p>I have tried to mock the KeyStore.getInstance() which returns the keyStore object
  here the below code which I had tired,</p>
  
  <p><strong>Junit:</strong>   </p>
  
  <pre><code>KeyStore keyStoreMock = PowerMockito.mock(KeyStore.class); 
  PowerMockito.when(KeyStore.getInstance(any())).thenReturn(keyStoreMock); 
  PowerMockito.doNothing().when(keyStoreMock).load(any(InputStream.class),Mockito.any(char[].class)); 
  X509Certificate cert = Mockito.mock(X509Certificate.class); 
  when(keyStoreMock.getCertificate(any())).thenReturn(cert); 
  when(cert.getNotAfter()).thenReturn(mockDate);
  </code></pre>
  
  <p>unable to mock keyStore.getInstance() which returns the of KeyStore class mock object.</p>
  
  <p><strong>Source Code:</strong></p>
  
  <pre><code>KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
  keystore.load(new FileInputStream(filename), password.toCharArray());
  X509Certificate certificate = (X509Certificate)keystore.getCertificate("Cert_name");  
  endate = certificate.getNotAfter();
  </code></pre>
  
  <p>I think KeyStore.getInstance() returns null, how to overcome this issue.</p>
  
  <p>Colud any one plz help me out to mock the keystore.getInstance() method.      </p>