private static String getToken(HttpClient clientInstance) throws badcredentailsexception{
try{
    // some process here throws IOException
    }
catch(IOexception e){
    throw new badcredentailsexception(message, e)
   }
}
Now I need to write Junit test for the above method, My Junit code for above function is below
@Test(expected = badcredentailsexception.class)
public void testGetTokenForExceptions() throws ClientProtocolException, IOException, NoSuchMethodException, SecurityException, IllegalAccessException, 
                        IllegalArgumentException, InvocationTargetException {
  Mockito.when(mockHttpClient.execute(Mockito.any(HttpPost.class))).thenThrow(IOException.class);
 // mocked mockHttpClient to throw IOException
    final Method method = Client.class.getDeclaredMethod("getToken", HttpClient.class);
    method.setAccessible(true);
    Object actual = method.invoke(null, mockHttpClient);
    }
But this test is not being passed, any improvements??
Can we check the exception thrown by private method from junit ??
 
     
    