/**
   * Should not cause a fatal error even for an empty selector.
   *
   * @throws Exception
   */
  @Test
  public void testEmptySelector() throws Exception {
    FreeStyleProject copiee = j.createFreeStyleProject();
    FreeStyleProject copier = j.createFreeStyleProject();

    ParameterizedBuildSelector pbs = new ParameterizedBuildSelector("SELECTOR");
    copier
        .getBuildersList()
        .add(
            CopyArtifactUtil.createCopyArtifact(
                copiee.getFullName(),
                null, // parameters
                pbs,
                "**/*", // filter
                "", // excludes
                false, // flatten
                true, // optional
                false // finterprintArtifacts
                ));
    FreeStyleBuild b =
        (FreeStyleBuild)
            copier
                .scheduleBuild2(0, new ParametersAction(new StringParameterValue("SELECTOR", "")))
                .get();
    j.assertBuildStatusSuccess(b);
  }
  /**
   * Should not cause a fatal error even for an undefined variable.
   *
   * @throws Exception
   */
  @Issue("JENKINS-30357")
  @Test
  public void testUndefinedParameter() throws Exception {
    FreeStyleProject copiee = j.createFreeStyleProject();
    FreeStyleProject copier = j.createFreeStyleProject();

    ParameterizedBuildSelector pbs = new ParameterizedBuildSelector("NosuchVariable");
    copier
        .getBuildersList()
        .add(
            CopyArtifactUtil.createCopyArtifact(
                copiee.getFullName(),
                null, // parameters
                pbs,
                "**/*", // filter
                "", // excludes
                false, // flatten
                true, // optional
                false // finterprintArtifacts
                ));
    FreeStyleBuild b = copier.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b);
  }
  /**
   * Also accepts variable expression.
   *
   * @throws Exception
   */
  @Test
  public void testVariableExpression() throws Exception {
    // Prepare an artifact to be copied.
    FreeStyleProject copiee = j.createFreeStyleProject();
    copiee.getBuildersList().add(new FileWriteBuilder("artifact.txt", "foobar"));
    copiee.getPublishersList().add(new ArtifactArchiver("artifact.txt"));
    j.assertBuildStatusSuccess(copiee.scheduleBuild2(0));

    FreeStyleProject copier = j.createFreeStyleProject();
    ParameterizedBuildSelector pbs = new ParameterizedBuildSelector("${SELECTOR}");
    copier
        .getBuildersList()
        .add(
            CopyArtifactUtil.createCopyArtifact(
                copiee.getFullName(),
                null, // parameters
                pbs,
                "**/*", // filter
                "", // excludes
                false, // flatten
                false, // optional
                false // finterprintArtifacts
                ));
    FreeStyleBuild b =
        j.assertBuildStatusSuccess(
            (FreeStyleBuild)
                copier
                    .scheduleBuild2(
                        0,
                        new ParametersAction(
                            new StringParameterValue(
                                "SELECTOR",
                                "<StatusBuildSelector><stable>true</stable></StatusBuildSelector>")))
                    .get());

    assertEquals("foobar", b.getWorkspace().child("artifact.txt").readToString());
  }