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

Code before:
        "jib", new String(ByteStreams.toByteArray(tarArchiveInputStream), StandardCharsets.UTF_8));

    Assert.assertNull(tarArchiveInputStream.getNextTarEntry());
  }

  @Test
  public void testToBlob_modificationTime() throws IOException {
    testTarStreamBuilder.addByteEntry(
        "foo".getBytes(StandardCharsets.UTF_8), "foo", Instant.ofEpochSecond(1234));
    testTarStreamBuilder.addBlobEntry(
        Blobs.from("bar"),
        "bar".getBytes(StandardCharsets.UTF_8).length,
        "bar",
        Instant.ofEpochSecond(3));

    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    testTarStreamBuilder.writeAsTarArchiveTo(outStream);

    TarArchiveInputStream tarInStream =
        new TarArchiveInputStream(new ByteArrayInputStream(outStream.toByteArray()));

    TarArchiveEntry headerFile = tarInStream.getNextTarEntry();
    assertThat(headerFile.getName()).isEqualTo("foo");
    assertThat(headerFile.getModTime().toInstant()).isEqualTo(Instant.ofEpochSecond(1234));

    headerFile = tarInStream.getNextTarEntry();
    assertThat(headerFile.getName()).isEqualTo("bar");
    assertThat(headerFile.getModTime().toInstant()).isEqualTo(Instant.ofEpochSecond(3));
  }

  /** Creates a TarStreamBuilder using TarArchiveEntries. */
  private void setUpWithTarEntries() {
    // Prepares a test TarStreamBuilder.
    testTarStreamBuilder.addTarArchiveEntry(
        new TarArchiveEntry(fileA.toFile(), "some/path/to/resourceFileA"));
    testTarStreamBuilder.addTarArchiveEntry(new TarArchiveEntry(fileB.toFile(), "crepecake"));
    testTarStreamBuilder.addTarArchiveEntry(
        new TarArchiveEntry(directoryA.toFile(), "some/path/to"));
    testTarStreamBuilder.addTarArchiveEntry(
        new TarArchiveEntry(
            fileA.toFile(),
            "some/really/long/path/that/exceeds/100/characters/abcdefghijklmnopqrstuvwxyz0123456789012345678901234567890"));
  }

  /** Creates a TarStreamBuilder using Strings. */
  private void setUpWithStrings() {
    // Prepares a test TarStreamBuilder.
    testTarStreamBuilder.addByteEntry(fileAContents, "some/path/to/resourceFileA", Instant.EPOCH);
    testTarStreamBuilder.addByteEntry(fileBContents, "crepecake", Instant.EPOCH);
    testTarStreamBuilder.addTarArchiveEntry(
        new TarArchiveEntry(directoryA.toFile(), "some/path/to"));

Review comment (suggestion):
let's initialize all the `TarArchiveEntry headerFile` variables in the beginning? To keep the "arrange" and  "assert" blocks separate. 

Code after:
        "jib", new String(ByteStreams.toByteArray(tarArchiveInputStream), StandardCharsets.UTF_8));

    Assert.assertNull(tarArchiveInputStream.getNextTarEntry());
  }

  @Test
  public void testToBlob_modificationTime() throws IOException {
    testTarStreamBuilder.addByteEntry(
        "foo".getBytes(StandardCharsets.UTF_8), "foo", Instant.ofEpochSecond(1234));
    testTarStreamBuilder.addBlobEntry(
        Blobs.from("bar"),
        "bar".getBytes(StandardCharsets.UTF_8).length,
        "bar",
        Instant.ofEpochSecond(3));

    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    testTarStreamBuilder.writeAsTarArchiveTo(outStream);

    TarArchiveInputStream tarInStream =
        new TarArchiveInputStream(new ByteArrayInputStream(outStream.toByteArray()));
    TarArchiveEntry entry1 = tarInStream.getNextTarEntry();
    TarArchiveEntry entry2 = tarInStream.getNextTarEntry();

    assertThat(entry1.getName()).isEqualTo("foo");
    assertThat(entry1.getModTime().toInstant()).isEqualTo(Instant.ofEpochSecond(1234));
    assertThat(entry2.getName()).isEqualTo("bar");
    assertThat(entry2.getModTime().toInstant()).isEqualTo(Instant.ofEpochSecond(3));
  }

  /** Creates a TarStreamBuilder using TarArchiveEntries. */
  private void setUpWithTarEntries() {
    // Prepares a test TarStreamBuilder.
    testTarStreamBuilder.addTarArchiveEntry(
        new TarArchiveEntry(fileA.toFile(), "some/path/to/resourceFileA"));
    testTarStreamBuilder.addTarArchiveEntry(new TarArchiveEntry(fileB.toFile(), "crepecake"));
    testTarStreamBuilder.addTarArchiveEntry(
        new TarArchiveEntry(directoryA.toFile(), "some/path/to"));
    testTarStreamBuilder.addTarArchiveEntry(
        new TarArchiveEntry(
            fileA.toFile(),
            "some/really/long/path/that/exceeds/100/characters/abcdefghijklmnopqrstuvwxyz0123456789012345678901234567890"));
  }

  /** Creates a TarStreamBuilder using Strings. */
  private void setUpWithStrings() {
    // Prepares a test TarStreamBuilder.
    testTarStreamBuilder.addByteEntry(fileAContents, "some/path/to/resourceFileA", Instant.EPOCH);
    testTarStreamBuilder.addByteEntry(fileBContents, "crepecake", Instant.EPOCH);
    testTarStreamBuilder.addTarArchiveEntry(
        new TarArchiveEntry(directoryA.toFile(), "some/path/to"));
    testTarStreamBuilder.addByteEntry(