### Question:
JaasUtils { public static Subject getCurrentSubject() { final Subject subject = Subject.getSubject(AccessController.getContext()); if (subject == null) throw new IllegalStateException("No subject found in current context."); return subject; }  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 testGetCurrentSubject() { final Subject subject = new Subject(); assertThat(Subject.doAs(subject, new PrivilegedAction<Subject>() { @Override public Subject run() { return JaasUtils.getCurrentSubject(); } })).isEqualTo(subject); }
@Test public void testGetCurrentSubjectNoSubject() { IllegalStateException e = assertThrows(IllegalStateException.class, () -> { JaasUtils.getCurrentSubject(); }); assertThat(e.getMessage()).isEqualTo("No subject found in current context."); }