Repository: GoogleContainerTools/jib
File: jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarExtractorTest.java (Java)

Code before:
        .isEqualTo(FileTime.from(Instant.parse("2019-08-01T16:13:30Z")));
    assertThat(Files.getLastModifiedTime(destination.resolve("folder/nested folder/file C")))
        .isEqualTo(FileTime.from(Instant.parse("2019-08-01T16:12:21Z")));
  }

  @Test
  public void testExtract_reproducibleTimestampsEnabled() throws URISyntaxException, IOException {
    // The tarfile has only level1/level2/level3/file.txt packaged
    Path source = Paths.get(Resources.getResource("core/tarfile-only-file-packaged.tar").toURI());

    Path destination = temporaryFolder.getRoot().toPath();

    TarExtractor.extract(source, destination, true);

    assertThat(Files.getLastModifiedTime(destination.resolve("level-1")))
        .isEqualTo(FileTime.fromMillis(1000L));
    assertThat(Files.getLastModifiedTime(destination.resolve("level-1/level-2")))
        .isEqualTo(FileTime.fromMillis(1000L));
    assertThat(Files.getLastModifiedTime(destination.resolve("level-1/level-2/level-3")))
        .isEqualTo(FileTime.fromMillis(1000L));
    assertThat(Files.getLastModifiedTime(destination.resolve("level-1/level-2/level-3/file.txt")))
        .isEqualTo(FileTime.from(Instant.parse("2021-01-29T21:10:02Z")));
  }

  @Test
  public void testExtract_reproducibleTimestampsEnabled_invalidDestination() throws IOException {
    Path destination = temporaryFolder.getRoot().toPath();
    Files.createDirectory(destination.resolve("directory"));

    assertThrows(
        IllegalStateException.class,
        () -> TarExtractor.extract(Paths.get("ignore"), destination, true));
  }
}


Review comment (refactor):
```suggestion
  public void testExtract_reproducibleTimestampsEnabled_destinationNotEmpty() throws IOException {
```

Code after:
        .isEqualTo(FileTime.from(Instant.parse("2019-08-01T16:13:30Z")));
    assertThat(Files.getLastModifiedTime(destination.resolve("folder/nested folder/file C")))
        .isEqualTo(FileTime.from(Instant.parse("2019-08-01T16:12:21Z")));
  }

  @Test
  public void testExtract_reproducibleTimestampsEnabled() throws URISyntaxException, IOException {
    // The tarfile has only level1/level2/level3/file.txt packaged
    Path source = Paths.get(Resources.getResource("core/tarfile-only-file-packaged.tar").toURI());

    Path destination = temporaryFolder.getRoot().toPath();

    TarExtractor.extract(source, destination, true);

    assertThat(Files.getLastModifiedTime(destination.resolve("level-1")))
        .isEqualTo(FileTime.fromMillis(1000L));
    assertThat(Files.getLastModifiedTime(destination.resolve("level-1/level-2")))
        .isEqualTo(FileTime.fromMillis(1000L));
    assertThat(Files.getLastModifiedTime(destination.resolve("level-1/level-2/level-3")))
        .isEqualTo(FileTime.fromMillis(1000L));
    assertThat(Files.getLastModifiedTime(destination.resolve("level-1/level-2/level-3/file.txt")))
        .isEqualTo(FileTime.from(Instant.parse("2021-01-29T21:10:02Z")));
  }

  @Test
  public void testExtract_reproducibleTimestampsEnabled_destinationNotEmpty() throws IOException {
    Path destination = temporaryFolder.getRoot().toPath();
    temporaryFolder.newFile();

    IllegalStateException exception =
        assertThrows(
            IllegalStateException.class,
            () -> TarExtractor.extract(Paths.get("ignore"), destination, true));
    assertThat(exception).hasMessageThat().startsWith("Cannot enable reproducible timestamps");
  }
}