I have tried to mock the KeyStore.getInstance() which returns the keyStore object here the below code which I had tired,
Junit:
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);
unable to mock keyStore.getInstance() which returns the of KeyStore class mock object.
Source Code:
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
keystore.load(new FileInputStream(filename), password.toCharArray());
X509Certificate certificate = (X509Certificate)keystore.getCertificate("Cert_name");
endate = certificate.getNotAfter();
I think KeyStore.getInstance() returns null, how to overcome this issue.
Colud any one plz help me out to mock the keystore.getInstance() method.