@VisibleForTesting
  static JavaContainerBuilder getJavaContainerBuilderWithBaseImage(
      RawConfiguration rawConfiguration,
      ProjectProperties projectProperties,
      InferredAuthProvider inferredAuthProvider)
      throws IncompatibleBaseImageJavaVersionException, InvalidImageReferenceException,
          FileNotFoundException {
    // Use image configuration as-is if it's a local base image
    Optional<String> image = rawConfiguration.getFromImage();
    String baseImageConfig =
        image.isPresent() ? image.get() : getDefaultBaseImage(projectProperties);
    if (baseImageConfig.startsWith(Jib.TAR_IMAGE_PREFIX)) {
      return JavaContainerBuilder.from(baseImageConfig);
    }

    // Verify Java version is compatible
    List<String> splits = Splitter.on("://").splitToList(baseImageConfig);
    String prefixRemoved = splits.get(splits.size() - 1);
    int javaVersion = projectProperties.getMajorJavaVersion();
    if (isKnownJava8Image(prefixRemoved) && javaVersion > 8) {
      throw new IncompatibleBaseImageJavaVersionException(8, javaVersion);
    }
    if (isKnownJava11Image(prefixRemoved) && javaVersion > 11) {
      throw new IncompatibleBaseImageJavaVersionException(11, javaVersion);
    }
    if (isKnownJava17Image(prefixRemoved) && javaVersion > 17) {
      throw new IncompatibleBaseImageJavaVersionException(17, javaVersion);
    }
    if (isKnownJava21Image(prefixRemoved) && javaVersion > 21) {
      throw new IncompatibleBaseImageJavaVersionException(21, javaVersion);
    }

    ImageReference baseImageReference = ImageReference.parse(prefixRemoved);
    if (baseImageConfig.startsWith(Jib.DOCKER_DAEMON_IMAGE_PREFIX)) {
      DockerDaemonImage dockerDaemonImage =
          DockerDaemonImage.named(baseImageReference)
              .setDockerEnvironment(rawConfiguration.getDockerEnvironment());
      Optional<Path> dockerExecutable = rawConfiguration.getDockerExecutable();
      if (dockerExecutable.isPresent()) {
        dockerDaemonImage.setDockerExecutable(dockerExecutable.get());
      }
      return JavaContainerBuilder.from(dockerDaemonImage);
    }

    RegistryImage baseImage = RegistryImage.named(baseImageReference);
    configureCredentialRetrievers(
        rawConfiguration,
        projectProperties,
        baseImage,
        baseImageReference,
        PropertyNames.FROM_AUTH_USERNAME,
        PropertyNames.FROM_AUTH_PASSWORD,
        rawConfiguration.getFromAuth(),
        inferredAuthProvider,
        rawConfiguration.getFromCredHelper());
    return JavaContainerBuilder.from(baseImage);
  }
@Test
  public void testGetJavaContainerBuilderWithBaseImage_java22NoBaseImage() {
    when(projectProperties.getMajorJavaVersion()).thenReturn(22);
    when(rawConfiguration.getFromImage()).thenReturn(Optional.empty());
    IncompatibleBaseImageJavaVersionException exception =
        assertThrows(
            IncompatibleBaseImageJavaVersionException.class,
            () ->
                PluginConfigurationProcessor.getJavaContainerBuilderWithBaseImage(
                    rawConfiguration, projectProperties, inferredAuthProvider));
    assertThat(exception.getBaseImageMajorJavaVersion()).isEqualTo(21);
    assertThat(exception.getProjectMajorJavaVersion()).isEqualTo(22);
  }