GoogleJavaFormatStep { private static FormatterFunc suggestJre11(FormatterFunc in) { if (JRE_VERSION >= 11) { return in; } else { return unixIn -> { try { return in.apply(unixIn); } catch (Exception e) { throw new Exception("You are running Spotless on JRE " + JRE_VERSION + ", which limits you to google-java-format " + LATEST_VERSION_JRE_8 + "\n" + "If you upgrade your build JVM to 11+, then you can use google-java-format " + LATEST_VERSION_JRE_11 + ", which may have fixed this problem.", e); } }; } } private  GoogleJavaFormatStep(); static FormatterStep create(Provisioner provisioner); static FormatterStep create(String version, Provisioner provisioner); static FormatterStep create(String version, String style, Provisioner provisioner); static String defaultVersion(); static String defaultStyle();  }
@Test public void suggestJre11() throws Exception { try (StepHarness step = StepHarness.forStep(GoogleJavaFormatStep.create(TestProvisioner.mavenCentral()))) { if (JreVersion.thisVm() < 11) { step.testResourceException("java/googlejavaformat/TextBlock.dirty", throwable -> { throwable.hasMessageStartingWith("You are running Spotless on JRE 8") .hasMessageEndingWith(", which limits you to google-java-format 1.7\n" + "If you upgrade your build JVM to 11+, then you can use google-java-format 1.9, which may have fixed this problem."); }); } else if (JreVersion.thisVm() < 13) { step.testResourceException("java/googlejavaformat/TextBlock.dirty", throwable -> { throwable.isInstanceOf(InvocationTargetException.class) .extracting(exception -> exception.getCause().getMessage()).asString().contains("7:18: error: unclosed string literal"); }); } else { step.testResource("java/googlejavaformat/TextBlock.dirty", "java/googlejavaformat/TextBlock.clean"); } } }