@SuppressWarnings("unchecked")
  // CHECKSTYLE:OFF
  public static AuthnRequest createAuthnRequest(
      String serviceURL,
      boolean forceAuthn,
      boolean isPassive,
      String protocolBinding,
      SAMLVersion version,
      Issuer issuer,
      NameIDPolicy nameIDPolicy,
      RequestedAuthnContext requestedAuthnCtx) {
    // CHECKSTYLE:ON
    if (authnRequestBuilder == null) {
      authnRequestBuilder =
          (SAMLObjectBuilder<AuthnRequest>)
              builderFactory.getBuilder(AuthnRequest.DEFAULT_ELEMENT_NAME);
    }
    AuthnRequest authnRequest = authnRequestBuilder.buildObject();
    authnRequest.setAssertionConsumerServiceURL(serviceURL);
    authnRequest.setForceAuthn(forceAuthn);
    authnRequest.setID("_" + UUID.randomUUID());
    authnRequest.setIsPassive(isPassive);
    authnRequest.setIssueInstant(new DateTime());
    authnRequest.setProtocolBinding(protocolBinding);
    authnRequest.setVersion(version);

    authnRequest.setIssuer(issuer);
    authnRequest.setNameIDPolicy(nameIDPolicy);
    authnRequest.setRequestedAuthnContext(requestedAuthnCtx);

    return authnRequest;
  }
  /** {@inheritDoc} */
  @Test
  public void testChildElementsMarshall() {
    QName qname =
        new QName(
            SAMLConstants.SAML20P_NS,
            AuthnRequest.DEFAULT_ELEMENT_LOCAL_NAME,
            SAMLConstants.SAML20P_PREFIX);
    AuthnRequest req = (AuthnRequest) buildXMLObject(qname);

    super.populateChildElements(req);

    QName subjectQName =
        new QName(
            SAMLConstants.SAML20_NS,
            Subject.DEFAULT_ELEMENT_LOCAL_NAME,
            SAMLConstants.SAML20_PREFIX);
    req.setSubject((Subject) buildXMLObject(subjectQName));

    QName nameIDPolicyQName =
        new QName(
            SAMLConstants.SAML20P_NS,
            NameIDPolicy.DEFAULT_ELEMENT_LOCAL_NAME,
            SAMLConstants.SAML20P_PREFIX);
    req.setNameIDPolicy((NameIDPolicy) buildXMLObject(nameIDPolicyQName));

    QName conditionsQName =
        new QName(
            SAMLConstants.SAML20_NS,
            Conditions.DEFAULT_ELEMENT_LOCAL_NAME,
            SAMLConstants.SAML20_PREFIX);
    req.setConditions((Conditions) buildXMLObject(conditionsQName));

    QName requestedAuthnContextQName =
        new QName(
            SAMLConstants.SAML20P_NS,
            RequestedAuthnContext.DEFAULT_ELEMENT_LOCAL_NAME,
            SAMLConstants.SAML20P_PREFIX);
    req.setRequestedAuthnContext(
        (RequestedAuthnContext) buildXMLObject(requestedAuthnContextQName));

    QName scopingQName =
        new QName(
            SAMLConstants.SAML20P_NS,
            Scoping.DEFAULT_ELEMENT_LOCAL_NAME,
            SAMLConstants.SAML20P_PREFIX);
    req.setScoping((Scoping) buildXMLObject(scopingQName));

    assertXMLEquals(expectedChildElementsDOM, req);
  }