### Question:
JaasUtils { public static boolean hasPrincipal(final Class<? extends Principal> principalClass) { if (principalClass == null) throw new IllegalArgumentException("Principal class cannot be null."); return !getCurrentSubject().getPrincipals(principalClass).isEmpty(); }  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 testHasPrincipal() { final Principal principal = mock(Principal.class); final Subject subject = new Subject(); subject.getPrincipals().add(principal); assertThat(Subject.doAs(subject, new PrivilegedAction<Boolean>() { @Override public Boolean run() { return JaasUtils.hasPrincipal(principal.getClass()); } })).isTrue(); assertThat(Subject.doAs(subject, new PrivilegedAction<Boolean>() { @Override public Boolean run() { return JaasUtils.hasPrincipal(MillenniumDomainPrincipal.class); } })).isFalse(); }
@Test public void testHasPrincipalNullClass() { IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> { JaasUtils.hasPrincipal(null); }); assertThat(e.getMessage()).isEqualTo("Principal class cannot be null."); }