11/*
2- * Copyright 2020-2021 DiffPlug
2+ * Copyright 2020-2025 DiffPlug
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1717
1818import java .io .IOException ;
1919
20+ import org .gradle .testkit .runner .GradleRunner ;
2021import org .junit .jupiter .api .Test ;
2122
22- class ToggleOffOnTest extends GradleIntegrationHarness {
23+ abstract class ToggleOffOnTest extends GradleIntegrationHarness {
24+ private boolean useConfigCache ;
25+
26+ ToggleOffOnTest (boolean useConfigCache ) {
27+ this .useConfigCache = useConfigCache ;
28+ }
29+
30+ static class WithConfigCache extends ToggleOffOnTest {
31+ WithConfigCache () {
32+ super (true );
33+ }
34+ }
35+
36+ static class WithoutConfigCache extends ToggleOffOnTest {
37+ WithoutConfigCache () {
38+ super (false );
39+ }
40+ }
41+
42+ @ Override
43+ public GradleRunner gradleRunner () throws IOException {
44+ if (useConfigCache ) {
45+ setFile ("gradle.properties" ).toLines ("org.gradle.unsafe.configuration-cache=true" ,
46+ "org.gradle.configuration-cache=true" );
47+ return super .gradleRunner ().withGradleVersion (GradleVersionSupport .CONFIGURATION_CACHE .version );
48+ } else {
49+ return super .gradleRunner ();
50+ }
51+ }
52+
2353 @ Test
24- void toggleOffOn () throws IOException {
54+ void lowercase () throws IOException {
2555 setFile ("build.gradle" ).toLines (
2656 "plugins { id 'com.diffplug.spotless' }" ,
2757 "spotless {" ,
58+ " lineEndings 'UNIX'" ,
2859 " format 'toLower', {" ,
2960 " target '**/*.md'" ,
30- " custom 'lowercase', { str -> str.toLowerCase() } " ,
61+ " addStep(com.diffplug.spotless.TestingOnly.lowercase()) " ,
3162 " toggleOffOn()" ,
3263 " }" ,
3364 "}" );
@@ -37,12 +68,50 @@ void toggleOffOn() throws IOException {
3768 "D E F" ,
3869 "spotless:on" ,
3970 "G H I" );
40- gradleRunner ().withArguments ("spotlessApply" ).build ();
71+ gradleRunner ().withArguments ("spotlessApply" , "--stacktrace" ).build ();
72+ assertFile ("test.md" ).hasLines (
73+ "a b c" ,
74+ "spotless:off" ,
75+ "D E F" ,
76+ "spotless:on" ,
77+ "g h i" );
78+ gradleRunner ().withArguments ("spotlessApply" , "--stacktrace" ).build ();
79+ gradleRunner ().withArguments ("spotlessApply" , "--stacktrace" ).build ();
80+ gradleRunner ().withArguments ("spotlessApply" , "--stacktrace" ).build ();
81+ setFile ("test.md" ).toLines (
82+ "A B C" ,
83+ "spotless:off" ,
84+ "D E F" ,
85+ "spotless:on" ,
86+ "G H I" );
87+ gradleRunner ().withArguments ("spotlessApply" , "--stacktrace" ).build ();
4188 assertFile ("test.md" ).hasLines (
4289 "a b c" ,
4390 "spotless:off" ,
4491 "D E F" ,
4592 "spotless:on" ,
4693 "g h i" );
4794 }
95+
96+ @ Test
97+ void gjf () throws IOException {
98+ setFile ("build.gradle" ).toLines (
99+ "plugins {" ,
100+ " id 'com.diffplug.spotless'" ,
101+ "}" ,
102+ "repositories { mavenCentral() }" ,
103+ "" ,
104+ "spotless {" ,
105+ " java {" ,
106+ " target file('test.java')" ,
107+ " googleJavaFormat('1.17.0')" ,
108+ " toggleOffOn()" ,
109+ " }" ,
110+ "}" );
111+
112+ setFile ("test.java" ).toResource ("java/googlejavaformat/JavaCodeUnformatted.test" );
113+ gradleRunner ().withArguments ("spotlessApply" ).build ();
114+ assertFile ("test.java" ).sameAsResource ("java/googlejavaformat/JavaCodeFormatted.test" );
115+ gradleRunner ().withArguments ("spotlessCheck" ).build ();
116+ }
48117}
0 commit comments