Skip to content

Commit 7355cb2

Browse files
committed
add test for min version check + adapt others
1 parent 30ef0d4 commit 7355cb2

File tree

5 files changed

+16
-10
lines changed

5 files changed

+16
-10
lines changed

lib/src/main/java/com/diffplug/spotless/Jvm.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ private String buildUnsupportedFormatterMessage(V fmtVersion) {
152152
// check if the formatter version is too low for the jvm version
153153
V minimumFormatterVersion = getMinimumRequiredFormatterVersion();
154154
if ((null != minimumFormatterVersion) && (fmtVersionComparator.compare(fmtVersion, minimumFormatterVersion) < 0)) {
155-
return String.format("You are running Spotless on JVM %d, which requires %s of at least %s (you are using %s).%n", Jvm.version(), fmtName, minimumFormatterVersion, fmtVersion);
155+
return String.format("You are running Spotless on JVM %d. This requires %s of at least %s (you are using %s).%n", Jvm.version(), fmtName, minimumFormatterVersion, fmtVersion);
156156
}
157157
// otherwise all is well
158158
return "";
@@ -228,7 +228,7 @@ private String buildUpgradeFormatterMessage(V fmtVersion) {
228228
V minimumFormatterVersion = getMinimumRequiredFormatterVersion();
229229
V recommendedFmtVersionOrNull = getRecommendedFormatterVersion();
230230
if ((null != minimumFormatterVersion) && (fmtVersionComparator.compare(fmtVersion, minimumFormatterVersion) < 0)) {
231-
builder.append(String.format("You are running Spotless on JVM %d, which requires %s of at least %s.%n", Jvm.version(), fmtName, minimumFormatterVersion));
231+
builder.append(String.format("You are running Spotless on JVM %d. This requires %s of at least %s.%n", Jvm.version(), fmtName, minimumFormatterVersion));
232232
builder.append(String.format("You are using %s %s.%n", fmtName, fmtVersion));
233233
if (null != recommendedFmtVersionOrNull) {
234234
builder.append(String.format("%s %s is the recommended version, which may have fixed this problem.%n", fmtName, recommendedFmtVersionOrNull));

lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public static FormatterStep create(String groupArtifact, String version, String
7070
}
7171

7272
static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME)
73-
.addMin(11, "1.8") // spotless requires java 11, so the min version of google java format we can support is 1.8
73+
.addMin(11, "1.8") // we only support google-java-format >= 1.8 due to api changes
7474
.add(11, "1.15.0"); // default version
7575

7676
public static String defaultGroupArtifact() {

testlib/src/main/resources/java/googlejavaformat/JavaCodeFormatted.test

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import mylib.UsedA;
32
import mylib.UsedB;
43

testlib/src/main/resources/java/googlejavaformat/JavaCodeFormattedAOSP.test

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import mylib.UsedA;
32
import mylib.UsedB;
43

testlib/src/test/java/com/diffplug/spotless/java/GoogleJavaFormatStepTest.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void behavior18() throws Exception {
5151

5252
@Test
5353
void behavior() throws Exception {
54-
FormatterStep step = GoogleJavaFormatStep.create("1.2", TestProvisioner.mavenCentral());
54+
FormatterStep step = GoogleJavaFormatStep.create("1.8", TestProvisioner.mavenCentral());
5555
StepHarness.forStep(step)
5656
.testResource("java/googlejavaformat/JavaCodeUnformatted.test", "java/googlejavaformat/JavaCodeFormatted.test")
5757
.testResource("java/googlejavaformat/JavaCodeWithLicenseUnformatted.test", "java/googlejavaformat/JavaCodeWithLicenseFormatted.test")
@@ -60,8 +60,16 @@ void behavior() throws Exception {
6060
}
6161

6262
@Test
63-
void behaviorWithAospStyle() throws Exception {
63+
void versionBelowMinimumRequiredVersionIsNotAllowed() throws Exception {
6464
FormatterStep step = GoogleJavaFormatStep.create("1.2", "AOSP", TestProvisioner.mavenCentral());
65+
StepHarness.forStep(step)
66+
.testResourceExceptionMsg("java/googlejavaformat/JavaCodeWithLicenseUnformatted.test")
67+
.contains("you are using 1.2");
68+
}
69+
70+
@Test
71+
void behaviorWithAospStyle() throws Exception {
72+
FormatterStep step = GoogleJavaFormatStep.create("1.8", "AOSP", TestProvisioner.mavenCentral());
6573
StepHarness.forStep(step)
6674
.testResource("java/googlejavaformat/JavaCodeUnformatted.test", "java/googlejavaformat/JavaCodeFormattedAOSP.test")
6775
.testResource("java/googlejavaformat/JavaCodeWithLicenseUnformatted.test", "java/googlejavaformat/JavaCodeWithLicenseFormattedAOSP.test")
@@ -83,7 +91,7 @@ void behaviorWithReflowLongStrings() throws Exception {
8391

8492
@Test
8593
void behaviorWithCustomGroupArtifact() throws Exception {
86-
FormatterStep step = GoogleJavaFormatStep.create(GoogleJavaFormatStep.defaultGroupArtifact(), "1.2", GoogleJavaFormatStep.defaultStyle(), TestProvisioner.mavenCentral(), false);
94+
FormatterStep step = GoogleJavaFormatStep.create(GoogleJavaFormatStep.defaultGroupArtifact(), "1.8", GoogleJavaFormatStep.defaultStyle(), TestProvisioner.mavenCentral(), false);
8795
StepHarness.forStep(step)
8896
.testResource("java/googlejavaformat/JavaCodeUnformatted.test", "java/googlejavaformat/JavaCodeFormatted.test")
8997
.testResource("java/googlejavaformat/JavaCodeWithLicenseUnformatted.test", "java/googlejavaformat/JavaCodeWithLicenseFormatted.test")
@@ -94,7 +102,7 @@ void behaviorWithCustomGroupArtifact() throws Exception {
94102
@Test
95103
void equality() throws Exception {
96104
new SerializableEqualityTester() {
97-
String version = "1.2";
105+
String version = "1.8";
98106
String style = "";
99107
boolean reflowLongStrings = false;
100108

@@ -103,7 +111,7 @@ protected void setupTest(API api) {
103111
// same version == same
104112
api.areDifferentThan();
105113
// change the version, and it's different
106-
version = "1.1";
114+
version = "1.9";
107115
api.areDifferentThan();
108116
// change the style, and it's different
109117
style = "AOSP";

0 commit comments

Comments
 (0)