@Test
  public void testHoKSubjectConfirmation() throws Exception {
    SubjectProvider subjectProvider =
        new DefaultSubjectProvider(
            Guice.createInjector(new MyModule()).getInstance(KeyInfoFactory.class));
    Date issueInstant = new Date();
    Subject subject =
        subjectProvider.get(
            SUBJECT_ID,
            AUDIENCE_ID,
            createSAML2Config(),
            SAML2SubjectConfirmation.HOLDER_OF_KEY,
            issueInstant,
            getProofState());
    assertEquals(SUBJECT_ID, subject.getNameID().getValue());
    assertEquals(NAME_ID_FORMAT, subject.getNameID().getFormat());

    SubjectConfirmation subjectConfirmation =
        (SubjectConfirmation) subject.getSubjectConfirmation().get(0);
    assertEquals(
        SAML2Constants.SUBJECT_CONFIRMATION_METHOD_HOLDER_OF_KEY, subjectConfirmation.getMethod());
    SubjectConfirmationData subjectConfirmationData =
        subjectConfirmation.getSubjectConfirmationData();
    assertTrue(subjectConfirmationData != null);
    assertEquals(subjectConfirmationData.getContentType(), KEY_INFO_CONFIRMATION_DATA_TYPE);
    // see if we can go from xml back to class instance.
    AssertionFactory.getInstance()
        .createSubjectConfirmationData(subjectConfirmationData.toXMLString(true, true));
  }
  @Test
  public void testBearerStateSettings() throws TokenCreationException {
    SubjectProvider subjectProvider =
        new DefaultSubjectProvider(
            Guice.createInjector(new MyModule()).getInstance(KeyInfoFactory.class));
    Date issueInstant = new Date();
    ProofTokenState proof = null; // must be set only when SubjectConfirmation is HoK
    Subject subject =
        subjectProvider.get(
            SUBJECT_ID,
            AUDIENCE_ID,
            createSAML2Config(),
            SAML2SubjectConfirmation.BEARER,
            issueInstant,
            proof);
    assertTrue(SUBJECT_ID.equals(subject.getNameID().getValue()));
    assertTrue(NAME_ID_FORMAT.equals(subject.getNameID().getFormat()));

    SubjectConfirmation subjectConfirmation =
        (SubjectConfirmation) subject.getSubjectConfirmation().get(0);
    assertTrue(
        SAML2Constants.SUBJECT_CONFIRMATION_METHOD_BEARER.equals(subjectConfirmation.getMethod()));
    SubjectConfirmationData subjectConfirmationData =
        subjectConfirmation.getSubjectConfirmationData();
    assertTrue(
        (issueInstant.getTime() + (TOKEN_LIFETIME_SECONDS * 1000))
            == subjectConfirmationData.getNotOnOrAfter().getTime());
  }