title: How to throw exception in JUnit Test for SSLContextBuilder.create().loadTrustMaterial?
body: <p>I have tried to write junit tests for the following piece of code but was unable to throw the exception in the test case.
  The following is the implementation:</p>
  
  <pre><code>public static HttpClientBuilder createTrustAllHttpClientBuilder() {
      try {
          SSLContext sslContext = SSLContextBuilder
                      .create()
                      .loadTrustMaterial(null, (certificate, authType) -&gt; true) &lt;= How to throw exception for this line
                      .build();
      }
      catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
          throw new IllegalStateException(e);
      }
  }
  </code></pre>
  
  <p>The following is my junit Test: </p>
  
  <pre><code>@RunWith(PowerMockRunner.class)
  @PrepareForTest({SSLContextBuilder.class})
  public class testClass {
  
       public void testCase() {
             SSLContextBuilder sslContextBuilder = mock(SSLContextBuilder.class, RETURNS_DEEP_STUBS);
             PowerMockito.mockStatic(SSLContextBuilder.class);
             PowerMockito.when(SSLContextBuilder.create()).thenReturn(sslContextBuilder);
             PowerMockito.when(sslContextBuilder.loadTrustMaterial(null, (certificate, authType) -&gt; true)).thenThrow(new NoSuchAlgorithmException());
       }
  }
  </code></pre>
  
  <p>I would greatly appreciate any form of help or sharing of knowledge if you have encountered the following issue previously. Thank you!</p>