@Test
  public void testBuild_ownership() throws IOException {
    Path testRoot = temporaryFolder.getRoot().toPath();
    Path someFile = createFile(testRoot, "someFile", "content", 54321);

    Blob blob =
        new ReproducibleLayerBuilder(
                ImmutableList.of(
                    defaultLayerEntry(someFile, AbsoluteUnixPath.get("/file1")),
                    new FileEntry(
                        someFile,
                        AbsoluteUnixPath.get("/file2"),
                        FilePermissions.fromOctalString("123"),
                        Instant.EPOCH,
                        ""),
                    new FileEntry(
                        someFile,
                        AbsoluteUnixPath.get("/file3"),
                        FilePermissions.fromOctalString("123"),
                        Instant.EPOCH,
                        ":"),
                    new FileEntry(
                        someFile,
                        AbsoluteUnixPath.get("/file4"),
                        FilePermissions.fromOctalString("123"),
                        Instant.EPOCH,
                        "333:"),
                    new FileEntry(
                        someFile,
                        AbsoluteUnixPath.get("/file5"),
                        FilePermissions.fromOctalString("123"),
                        Instant.EPOCH,
                        ":555"),
                    new FileEntry(
                        someFile,
                        AbsoluteUnixPath.get("/file6"),
                        FilePermissions.fromOctalString("123"),
                        Instant.EPOCH,
                        "333:555"),
                    new FileEntry(
                        someFile,
                        AbsoluteUnixPath.get("/file7"),
                        FilePermissions.fromOctalString("123"),
                        Instant.EPOCH,
                        "user:"),
                    new FileEntry(
                        someFile,
                        AbsoluteUnixPath.get("/file8"),
                        FilePermissions.fromOctalString("123"),
                        Instant.EPOCH,
                        ":group"),
                    new FileEntry(
                        someFile,
                        AbsoluteUnixPath.get("/file9"),
                        FilePermissions.fromOctalString("123"),
                        Instant.EPOCH,
                        "user:group")))
            .build();

    Path tarFile = temporaryFolder.newFile().toPath();
    try (OutputStream out = new BufferedOutputStream(Files.newOutputStream(tarFile))) {
      blob.writeTo(out);
    }

    try (TarArchiveInputStream in = new TarArchiveInputStream(Files.newInputStream(tarFile))) {
      TarArchiveEntry entry1 = in.getNextTarEntry();
      assertThat(entry1.getLongUserId()).isEqualTo(0);
      assertThat(entry1.getLongGroupId()).isEqualTo(0);
      assertThat(entry1.getUserName()).isEmpty();
      assertThat(entry1.getGroupName()).isEmpty();

      TarArchiveEntry entry2 = in.getNextTarEntry();
      assertThat(entry2.getLongUserId()).isEqualTo(0);
      assertThat(entry2.getLongGroupId()).isEqualTo(0);
      assertThat(entry2.getUserName()).isEmpty();
      assertThat(entry2.getGroupName()).isEmpty();

      TarArchiveEntry entry3 = in.getNextTarEntry();
      assertThat(entry3.getLongUserId()).isEqualTo(0);
      assertThat(entry3.getLongGroupId()).isEqualTo(0);
      assertThat(entry3.getUserName()).isEmpty();
      assertThat(entry3.getGroupName()).isEmpty();

      TarArchiveEntry entry4 = in.getNextTarEntry();
      assertThat(entry4.getLongUserId()).isEqualTo(333);
      assertThat(entry4.getLongGroupId()).isEqualTo(0);
      assertThat(entry4.getUserName()).isEmpty();
      assertThat(entry4.getGroupName()).isEmpty();

      TarArchiveEntry entry5 = in.getNextTarEntry();
      assertThat(entry5.getLongUserId()).isEqualTo(0);
      assertThat(entry5.getLongGroupId()).isEqualTo(555);
      assertThat(entry5.getUserName()).isEmpty();
      assertThat(entry5.getGroupName()).isEmpty();

      TarArchiveEntry entry6 = in.getNextTarEntry();
      assertThat(entry6.getLongUserId()).isEqualTo(333);
      assertThat(entry6.getLongGroupId()).isEqualTo(555);
      assertThat(entry6.getUserName()).isEmpty();
      assertThat(entry6.getGroupName()).isEmpty();

      TarArchiveEntry entry7 = in.getNextTarEntry();
      assertThat(entry7.getLongUserId()).isEqualTo(0);
      assertThat(entry7.getLongGroupId()).isEqualTo(0);
      assertThat(entry7.getUserName()).isEqualTo("user");
      assertThat(entry7.getGroupName()).isEmpty();

      TarArchiveEntry entry8 = in.getNextTarEntry();
      assertThat(entry8.getLongUserId()).isEqualTo(0);
      assertThat(entry8.getLongGroupId()).isEqualTo(0);
      assertThat(entry8.getUserName()).isEmpty();
      assertThat(entry8.getGroupName()).isEqualTo("group");

      TarArchiveEntry entry9 = in.getNextTarEntry();
      assertThat(entry9.getLongUserId()).isEqualTo(0);
      assertThat(entry9.getLongGroupId()).isEqualTo(0);
      assertThat(entry9.getUserName()).isEqualTo("user");
      assertThat(entry9.getGroupName()).isEqualTo("group");
    }
  }
Verifies that the next {@link TarArchiveEntry} in the {@link TarArchiveInputStream} is a
directory with correct permissions.

@param tarArchiveInputStream the {@link TarArchiveInputStream} to read from
@param expectedExtractionPath the expected extraction path of the next entry
@throws IOException if an I/O exception occurs
jib-core/src/test/java/com/google/cloud/tools/jib/image/ReproducibleLayerBuilderTest.java