public static String resolveMainClass(
      @Nullable String configuredMainClass, ProjectProperties projectProperties)
      throws MainClassInferenceException, IOException {
    if (configuredMainClass != null) {
      if (isValidJavaClass(configuredMainClass)) {
        return configuredMainClass;
      }
      throw new MainClassInferenceException(
          HelpfulSuggestions.forMainClassNotFound(
              "'mainClass' configured in "
                  + projectProperties.getPluginName()
                  + " is not a valid Java class: "
                  + configuredMainClass,
              projectProperties.getPluginName()));
    }

    projectProperties.log(
        LogEvent.info(
            "Searching for main class... Add a 'mainClass' configuration to '"
                + projectProperties.getPluginName()
                + "' to improve build speed."));

    String mainClassFromJarPlugin = projectProperties.getMainClassFromJarPlugin();
    if (mainClassFromJarPlugin != null && isValidJavaClass(mainClassFromJarPlugin)) {
      return mainClassFromJarPlugin;
    }

    if (mainClassFromJarPlugin != null) {
      projectProperties.log(
          LogEvent.warn(
              "'mainClass' configured in "
                  + projectProperties.getJarPluginName()
                  + " is not a valid Java class: "
                  + mainClassFromJarPlugin));
    }
    projectProperties.log(
        LogEvent.info(
            "Could not find a valid main class from "
                + projectProperties.getJarPluginName()
                + "; looking into all class files to infer main class."));

    MainClassFinder.Result mainClassFinderResult =
        MainClassFinder.find(projectProperties.getClassFiles(), projectProperties::log);
    switch (mainClassFinderResult.getType()) {
      case MAIN_CLASS_FOUND:
        return mainClassFinderResult.getFoundMainClass();

      case MAIN_CLASS_NOT_FOUND:
        throw new MainClassInferenceException(
            HelpfulSuggestions.forMainClassNotFound(
                "Main class was not found", projectProperties.getPluginName()));

      case MULTIPLE_MAIN_CLASSES:
        throw new MainClassInferenceException(
            HelpfulSuggestions.forMainClassNotFound(
                "Multiple valid main classes were found: "
                    + String.join(", ", mainClassFinderResult.getFoundMainClasses()),
                projectProperties.getPluginName()));

      default:
        throw new IllegalStateException("Cannot reach here");
    }
  }
@Test
  public void testResolveMainClass_invalidMainClassConfigured() throws IOException {
    try {
      MainClassResolver.resolveMainClass("In Val id", mockProjectProperties);
      Assert.fail();

    } catch (MainClassInferenceException ex) {
      MatcherAssert.assertThat(
          ex.getMessage(),
          CoreMatchers.containsString(
              "'mainClass' configured in jib-plugin is not a valid Java class: In Val id"));

      Mockito.verify(mockProjectProperties, Mockito.never()).log(Mockito.any());
    }
  }