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

Code before:
            () -> JarModeProcessor.computeEntrypointForExplodedStandard(standardJar));

    assertThat(ex)
        .hasMessageThat()
        .isEqualTo(
            "`Main-Class:` attribute for an application main class not defined in the input JAR's manifest (`META-INF/MANIFEST.MF` in the JAR).");
  }

  @Test
  public void testCreatePackagedModeLayersForStandardJar_emptyJar()
      throws IOException, URISyntaxException {
    Path standardJar = Paths.get(Resources.getResource(STANDARD_JAR_EMPTY).toURI());
    List<FileEntriesLayer> layers =
        JarModeProcessor.createPackagedModeLayersForStandardJar(standardJar);

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

    FileEntriesLayer jarLayer = layers.get(0);
    assertThat(jarLayer.getName()).isEqualTo("jar");
    assertThat(
            jarLayer
                .getEntries()
                .stream()
                .map(FileEntry::getExtractionPath)
                .collect(Collectors.toList())
                .get(0))
        .isEqualTo(AbsoluteUnixPath.get("/app/emptyStandardJar.jar"));
  }

  @Test
  public void testCreatePackagedModeLayersForStandardJar_withoutClassPathInManifest()
      throws IOException, URISyntaxException {
    Path standardJar =
        Paths.get(Resources.getResource(STANDARD_JAR_WITHOUT_CLASS_PATH_MANIFEST).toURI());
    List<FileEntriesLayer> layers =
        JarModeProcessor.createPackagedModeLayersForStandardJar(standardJar);

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

    FileEntriesLayer jarLayer = layers.get(0);

    assertThat(jarLayer.getName()).isEqualTo("jar");
    assertThat(
            jarLayer
                .getEntries()
                .stream()
                .map(FileEntry::getExtractionPath)
                .collect(Collectors.toList())
                .get(0))
        .isEqualTo(AbsoluteUnixPath.get("/app/standardJarWithoutClassPath.jar"));
  }

Review comment (refactor):
`jarLayer().getEntries().get(0).getExtractionPath()`?

And before this, also assert that the size of `jarLayer().getEntries()` is 1.

Code after:
  public void testCreateLayersForPackagedStandard_emptyJar()
      throws IOException, URISyntaxException {
    Path standardJar = Paths.get(Resources.getResource(STANDARD_JAR_EMPTY).toURI());
    List<FileEntriesLayer> layers = JarModeProcessor.createLayersForPackagedStandard(standardJar);

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

    FileEntriesLayer jarLayer = layers.get(0);
    assertThat(jarLayer.getName()).isEqualTo("jar");
    assertThat(jarLayer.getEntries().size()).isEqualTo(1);
    assertThat(jarLayer.getEntries().get(0).getExtractionPath())
        .isEqualTo(AbsoluteUnixPath.get("/app/emptyStandardJar.jar"));
  }

  @Test
  public void testCreateLayersForPackagedStandard_withClassPathInManifest()
      throws IOException, URISyntaxException {
    Path standardJar =
        Paths.get(Resources.getResource(STANDARD_JAR_WITH_CLASS_PATH_MANIFEST).toURI());
    List<FileEntriesLayer> layers = JarModeProcessor.createLayersForPackagedStandard(standardJar);

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

    FileEntriesLayer nonSnapshotLayer = layers.get(0);
    FileEntriesLayer snapshotLayer = layers.get(1);
    FileEntriesLayer jarLayer = layers.get(2);

    // Validate dependencies layers.
    assertThat(nonSnapshotLayer.getName()).isEqualTo("dependencies");
    assertThat(
            nonSnapshotLayer
                .getEntries()
                .stream()
                .map(FileEntry::getExtractionPath)
                .collect(Collectors.toList()))
        .isEqualTo(
            ImmutableList.of(
                AbsoluteUnixPath.get("/app/dependency1"),
                AbsoluteUnixPath.get("/app/dependency2"),
                AbsoluteUnixPath.get("/app/directory/dependency4")));
    assertThat(snapshotLayer.getName()).isEqualTo("snapshot dependencies");
    assertThat(
            snapshotLayer
                .getEntries()
                .stream()
                .map(FileEntry::getExtractionPath)
                .collect(Collectors.toList()))
        .isEqualTo(ImmutableList.of(AbsoluteUnixPath.get("/app/dependency3-SNAPSHOT-1.jar")));

    // Validate jar layer.
    assertThat(jarLayer.getName()).isEqualTo("jar");