### Question:
JaasUtils { public static <T> T getPrivateCredential(final Class<T> credentialClass) { if (credentialClass == null) throw new IllegalArgumentException("Credential class cannot be null."); final Set<T> credentials = getCurrentSubject().getPrivateCredentials(credentialClass); if (credentials.size() != 1) throw new IllegalArgumentException("Incorrect number of private credentials of type " + credentialClass.getCanonicalName() + " on subject : " + Integer.toString(credentials.size())); return credentials.iterator().next(); }  static Subject getCurrentSubject(); static P getPrincipal(final Class<P> principalClass); static T getPrivateCredential(final Class<T> credentialClass); static boolean hasPrincipal(final Class<? extends Principal> principalClass);  }### Answer:
@Test public void testGetPrivateCredential() { final Object credential = new Object(); final Subject subject = new Subject(); subject.getPrivateCredentials().add(credential); assertThat(Subject.doAs(subject, new PrivilegedAction<Object>() { @Override public Object run() { return JaasUtils.getPrivateCredential(credential.getClass()); } })).isEqualTo(credential); }
@Test public void testGetPrivateCredentialNoCredential() { IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> { Subject.doAs(new Subject(), new PrivilegedAction<Void>() { @Override public Void run() { JaasUtils.getPrivateCredential(Integer.class); return null; } }); }); assertThat(e.getMessage()).isEqualTo("Incorrect number of private credentials of type " + Integer.class.getCanonicalName() + " on subject : " + Integer.toString(0)); }
@Test public void testGetPrivateCredentialNullClass() { IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> { JaasUtils.getPrivateCredential(null); }); assertThat(e.getMessage()).isEqualTo("Credential class cannot be null."); }