Repository: GoogleContainerTools/jib
File: jib-cli/src/test/java/com/google/cloud/tools/jib/cli/jar/JarProcessorTest.java (Java)

Code before:
            AbsoluteUnixPath.get("/app/explodedJar/directory1/class1.class"),
            AbsoluteUnixPath.get("/app/explodedJar/directory1/class2.class"),
            AbsoluteUnixPath.get("/app/explodedJar/directory2"),
            AbsoluteUnixPath.get("/app/explodedJar/directory2/class4.class"),
            AbsoluteUnixPath.get("/app/explodedJar/directory2/directory3"),
            AbsoluteUnixPath.get("/app/explodedJar/directory2/directory3/class3.class"),
            AbsoluteUnixPath.get("/app/explodedJar/directory4"));

    // Validate resources layer.
    // TODO: Validate order of file paths once
    // https://github.com/GoogleContainerTools/jib/issues/2821 is fixed.
    assertThat(resourcesLayer.getEntries().size()).isEqualTo(9);
    assertThat(resourcesLayer.getName()).isEqualTo("Resources");
    List<AbsoluteUnixPath> actualResourcesPaths =
        resourcesLayer
            .getEntries()
            .stream()
            .map(FileEntry::getExtractionPath)
            .collect(Collectors.toList());
    assertThat(actualResourcesPaths)
        .containsExactly(
            AbsoluteUnixPath.get("/app/explodedJar/META-INF/"),
            AbsoluteUnixPath.get("/app/explodedJar/META-INF/MANIFEST.MF"),
            AbsoluteUnixPath.get("/app/explodedJar/directory1"),
            AbsoluteUnixPath.get("/app/explodedJar/directory1/resource1.txt"),
            AbsoluteUnixPath.get("/app/explodedJar/directory2"),
            AbsoluteUnixPath.get("/app/explodedJar/directory2/directory3"),
            AbsoluteUnixPath.get("/app/explodedJar/directory2/directory3/resource2.sql"),
            AbsoluteUnixPath.get("/app/explodedJar/directory4"),
            AbsoluteUnixPath.get("/app/explodedJar/directory4/resource3.txt"));

    // Validate dependencies layer.
    assertThat(dependenciesLayer.getEntries().size()).isEqualTo(3);
    assertThat(dependenciesLayer.getName()).isEqualTo("Dependencies");
    assertThat(
            dependenciesLayer
                .getEntries()
                .stream()
                .map(FileEntry::getExtractionPath)
                .collect(Collectors.toList()))
        .isEqualTo(
            ImmutableList.of(
                AbsoluteUnixPath.get("/app/dependencies/dependency1"),
                AbsoluteUnixPath.get("/app/dependencies/dependency2"),
                AbsoluteUnixPath.get("/app/dependencies/directory/dependency3")));
  }
}


Review comment (suggestion):
Assert before attempting `layers.get(2)`. Otherwise, for example, if the code base accidentally changes to produce only two layer, we'll hit an index-out-of-bound error when attempting `.get(2)`.

Code after:
            .collect(Collectors.toList());
    assertThat(actualResourcesPath)
        .containsExactly(
            AbsoluteUnixPath.get("/app/explodedJar/META-INF"),
            AbsoluteUnixPath.get("/app/explodedJar/META-INF/MANIFEST.MF"));

    // Validate classes layer.
    List<AbsoluteUnixPath> actualClassesPath =
        classesLayer
            .getEntries()
            .stream()
            .map(FileEntry::getExtractionPath)
            .collect(Collectors.toList());
    assertThat(actualClassesPath)
        .containsExactly(AbsoluteUnixPath.get("/app/explodedJar/META-INF"));
  }

  @Test
  public void testExplodeMode_standard_withClassPathInManifest()
      throws IOException, URISyntaxException {
    Path standardJar =
        Paths.get(Resources.getResource(STANDARD_JAR_WITH_CLASS_PATH_MANIFEST).toURI());
    Path destDir = temporaryFolder.newFolder().toPath();
    List<FileEntriesLayer> layers = JarProcessor.explodeStandardJar(standardJar, destDir);

    assertThat(layers.size()).isEqualTo(3);

    FileEntriesLayer dependenciesLayer = layers.get(0);
    FileEntriesLayer resourcesLayer = layers.get(1);
    FileEntriesLayer classesLayer = layers.get(2);

    // Validate dependencies layer.
    assertThat(dependenciesLayer.getName()).isEqualTo("dependencies");
    assertThat(
            dependenciesLayer
                .getEntries()
                .stream()
                .map(FileEntry::getExtractionPath)
                .collect(Collectors.toList()))
        .isEqualTo(
            ImmutableList.of(
                AbsoluteUnixPath.get("/app/dependencies/dependency1"),
                AbsoluteUnixPath.get("/app/dependencies/dependency2"),
                AbsoluteUnixPath.get("/app/dependencies/directory/dependency3")));

    // Validate resources layer.
    // TODO: Validate order of file paths once
    // https://github.com/GoogleContainerTools/jib/issues/2821 is fixed.
    assertThat(resourcesLayer.getName()).isEqualTo("resources");
    List<AbsoluteUnixPath> actualResourcesPaths =
        resourcesLayer