Repository: GoogleContainerTools/jib
File: jib-gradle-plugin/src/test/java/com/google/cloud/tools/jib/gradle/GradleProjectPropertiesTest.java (Java)

Code before:

  @Test
  public void testCreateContainerBuilder_noErrorIfWebInfLibDoesNotExist()
      throws IOException, InvalidImageReferenceException, CacheDirectoryCreationException {
    temporaryFolder.newFolder("WEB-INF", "classes");
    setUpWarProject(temporaryFolder.getRoot().toPath());
    setupBuildContext(); // should pass
  }

  @Test
  public void testCreateContainerBuilder_noErrorIfWebInfDoesNotExist()
      throws IOException, InvalidImageReferenceException, CacheDirectoryCreationException {
    setUpWarProject(temporaryFolder.getRoot().toPath());
    setupBuildContext(); // should pass
  }

  @Test
  public void testGetWarFilePath() throws IOException {
    Path outputDir = temporaryFolder.newFolder("output").toPath();

    project.getPlugins().apply("war");
    War war = project.getTasks().withType(War.class).getByName("war");
    war.getDestinationDirectory().set(outputDir.toFile());

    assertThat(gradleProjectProperties.getWarFilePath())
        .isEqualTo(outputDir.resolve("my-app.war").toString());
  }

  @Test
  public void testGetWarFilePath_bootWar() throws IOException {
    Path outputDir = temporaryFolder.newFolder("output").toPath();

    project.getPlugins().apply("war");
    project.getPlugins().apply("org.springframework.boot");
    War bootWar = project.getTasks().withType(War.class).getByName("bootWar");
    bootWar.getDestinationDirectory().set(outputDir.toFile());

    assertThat(gradleProjectProperties.getWarFilePath())
        .isEqualTo(outputDir.resolve("my-app.war").toString());
  }

  @Test
  public void testGetWarFilePath_bootWarDisabled() throws IOException {
    Path outputDir = temporaryFolder.newFolder("output").toPath();

    project.getPlugins().apply("war");
    War war = project.getTasks().withType(War.class).getByName("war");
    war.getDestinationDirectory().set(outputDir.toFile());

    project.getPlugins().apply("org.springframework.boot");
    project.getTasks().getByName("bootWar").setEnabled(false);

Review comment (refactor):
This test wasn't even testing if the extraction paths start with `DEFAULT_WEB_APP_ROOT`. The test is identical to the one right above. 

Code after:
            gradleProjectProperties.createJibContainerBuilder(
                JavaContainerBuilder.from("ignored"), ContainerizingMode.EXPLODED))
        .isNotNull();
  }

  @Test
  public void testCreateContainerBuilder_noErrorIfWebInfLibDoesNotExist()
      throws IOException, InvalidImageReferenceException {
    temporaryFolder.newFolder("WEB-INF", "classes");
    setUpWarProject(temporaryFolder.getRoot().toPath());

    assertThat(
            gradleProjectProperties.createJibContainerBuilder(
                JavaContainerBuilder.from("ignored"), ContainerizingMode.EXPLODED))
        .isNotNull();
  }

  @Test
  public void testCreateContainerBuilder_noErrorIfWebInfDoesNotExist()
      throws IOException, InvalidImageReferenceException {
    setUpWarProject(temporaryFolder.getRoot().toPath());

    assertThat(
            gradleProjectProperties.createJibContainerBuilder(
                JavaContainerBuilder.from("ignored"), ContainerizingMode.EXPLODED))
        .isNotNull();
  }

  @Test
  public void testGetWarFilePath() throws IOException {
    Path outputDir = temporaryFolder.newFolder("output").toPath();

    project.getPlugins().apply("war");
    War war = project.getTasks().withType(War.class).getByName("war");
    war.getDestinationDirectory().set(outputDir.toFile());

    assertThat(gradleProjectProperties.getWarFilePath())
        .isEqualTo(outputDir.resolve("my-app.war").toString());
  }

  @Test
  public void testGetWarFilePath_bootWar() throws IOException {
    Path outputDir = temporaryFolder.newFolder("output").toPath();

    project.getPlugins().apply("war");
    project.getPlugins().apply("org.springframework.boot");
    War bootWar = project.getTasks().withType(War.class).getByName("bootWar");
    bootWar.getDestinationDirectory().set(outputDir.toFile());

    assertThat(gradleProjectProperties.getWarFilePath())
        .isEqualTo(outputDir.resolve("my-app.war").toString());