### Question:
SpiffeSslContextFactory { public static SSLContext getSslContext(@NonNull final SslContextOptions options) throws NoSuchAlgorithmException, KeyManagementException { if (options.x509Source == null) { throw new IllegalArgumentException("x509Source option cannot be null, an X.509 Source must be provided"); } if (!options.acceptAnySpiffeId && options.acceptedSpiffeIdsSupplier == null) { throw new IllegalArgumentException("SSL context should be configured either with a Supplier " + "of accepted SPIFFE IDs or with acceptAnySpiffeId=true"); } val sslContext = newSslContext(options); val trustManagers = newTrustManager(options); val keyManagers = new SpiffeKeyManagerFactory().engineGetKeyManagers(options.x509Source); sslContext.init(keyManagers, trustManagers, null); return sslContext; } private  SpiffeSslContextFactory(); static SSLContext getSslContext(@NonNull final SslContextOptions options);  }### Answer:
@Test void getSslContext_withX509Source() { SpiffeSslContextFactory.SslContextOptions options = SpiffeSslContextFactory.SslContextOptions .builder() .x509Source(x509Source) .acceptAnySpiffeId() .build(); try { assertNotNull(SpiffeSslContextFactory.getSslContext(options)); } catch (NoSuchAlgorithmException | KeyManagementException e) { fail(e); } }
@Test void getSslContext_withSupplierOfSpiffeIds() { SpiffeSslContextFactory.SslContextOptions options = SpiffeSslContextFactory.SslContextOptions .builder() .x509Source(x509Source) .acceptedSpiffeIdsSupplier(Collections::emptySet) .build(); try { assertNotNull(SpiffeSslContextFactory.getSslContext(options)); } catch (NoSuchAlgorithmException | KeyManagementException e) { fail(e); } }
@Test void getSslContext_withAcceptAny() { SpiffeSslContextFactory.SslContextOptions options = SpiffeSslContextFactory.SslContextOptions .builder() .x509Source(x509Source) .acceptAnySpiffeId() .build(); try { assertNotNull(SpiffeSslContextFactory.getSslContext(options)); } catch (NoSuchAlgorithmException | KeyManagementException e) { fail(e); } }
@Test void getSslContext_withOtherSslProtocol() { SpiffeSslContextFactory.SslContextOptions options = SpiffeSslContextFactory.SslContextOptions .builder() .x509Source(x509Source) .acceptAnySpiffeId() .sslProtocol("TLSv1.1") .build(); try { assertNotNull(SpiffeSslContextFactory.getSslContext(options)); } catch (NoSuchAlgorithmException | KeyManagementException e) { fail(e); } }
@Test void getSslContext_nullOptions() throws KeyManagementException, NoSuchAlgorithmException { try { SpiffeSslContextFactory.getSslContext(null); } catch (NullPointerException e) { assertEquals("options is marked non-null but is null", e.getMessage()); } }
@Test void getSslContext_nullX509Source() throws KeyManagementException, NoSuchAlgorithmException { SpiffeSslContextFactory.SslContextOptions options = SpiffeSslContextFactory.SslContextOptions .builder() .acceptAnySpiffeId() .build(); try { SpiffeSslContextFactory.getSslContext(options); } catch (IllegalArgumentException e) { assertEquals("x509Source option cannot be null, an X.509 Source must be provided", e.getMessage()); } }
@Test void getSslContext_noSupplierAndAcceptAnyNotSet() { SpiffeSslContextFactory.SslContextOptions options = SpiffeSslContextFactory.SslContextOptions .builder() .x509Source(x509Source) .build(); try { SpiffeSslContextFactory.getSslContext(options); fail(); } catch (NoSuchAlgorithmException | KeyManagementException e) { fail(e); } catch (IllegalArgumentException e) { assertEquals("SSL context should be configured either with a Supplier " + "of accepted SPIFFE IDs or with acceptAnySpiffeId=true", e.getMessage()); } }