Skip to content

Commit f2eac77

Browse files
committed
refactor: move each eclipse wtp file type into its own test
(for using gradles fork-every-test to have completely separate jvms for each of these tests, because they store static values in the jvm)
1 parent dbf5ca8 commit f2eac77

15 files changed

+286
-203
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2025 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.spotless.cli.steps;
17+
18+
import org.junit.jupiter.api.Test;
19+
import org.junit.jupiter.api.parallel.Isolated;
20+
21+
import com.diffplug.spotless.tag.CliNativeTest;
22+
import com.diffplug.spotless.tag.CliProcessTest;
23+
import com.diffplug.spotless.tag.SeparateJvmTest;
24+
25+
@Isolated
26+
@SeparateJvmTest
27+
@CliNativeTest
28+
@CliProcessTest
29+
public class EclipseWtpCssTest extends EclipseWtpTestBase {
30+
31+
@Test
32+
void itSupportsFormattingCssFileType() {
33+
String fileName = runEclipseWtpWithType(EclipseWtp.Type.CSS, "body {\n" + "a: v; b: \n" + "v;\n" + "} \n");
34+
selfie().expectResource(fileName).toMatchDisk();
35+
}
36+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2025 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.spotless.cli.steps;
17+
18+
import org.junit.jupiter.api.Test;
19+
import org.junit.jupiter.api.parallel.Isolated;
20+
21+
import com.diffplug.spotless.tag.CliNativeTest;
22+
import com.diffplug.spotless.tag.CliProcessTest;
23+
import com.diffplug.spotless.tag.SeparateJvmTest;
24+
25+
@Isolated
26+
@SeparateJvmTest
27+
@CliNativeTest
28+
@CliProcessTest
29+
public class EclipseWtpHtmlTest extends EclipseWtpTestBase {
30+
31+
@Test
32+
void itSupportsFormattingHtmlFileType() {
33+
String fileName = runEclipseWtpWithType(
34+
EclipseWtp.Type.HTML,
35+
"<!DOCTYPE html> <html>\t<head> <meta charset=\"UTF-8\"></head>\n" + "</html> ");
36+
selfie().expectResource(fileName).toMatchDisk();
37+
}
38+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2025 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.spotless.cli.steps;
17+
18+
import org.junit.jupiter.api.Test;
19+
import org.junit.jupiter.api.parallel.Isolated;
20+
21+
import com.diffplug.spotless.tag.CliNativeTest;
22+
import com.diffplug.spotless.tag.CliProcessTest;
23+
import com.diffplug.spotless.tag.SeparateJvmTest;
24+
25+
@Isolated
26+
@SeparateJvmTest
27+
@CliNativeTest
28+
@CliProcessTest
29+
public class EclipseWtpJsTest extends EclipseWtpTestBase {
30+
31+
@Test
32+
void itSupportsFormattingJsFileType() {
33+
String fileName = runEclipseWtpWithType(EclipseWtp.Type.JS, "function f( ) {\n" + "a.b(1,\n" + "2);}");
34+
selfie().expectResource(fileName).toMatchDisk();
35+
}
36+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2025 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.spotless.cli.steps;
17+
18+
import org.junit.jupiter.api.Test;
19+
import org.junit.jupiter.api.parallel.Isolated;
20+
21+
import com.diffplug.spotless.tag.CliNativeTest;
22+
import com.diffplug.spotless.tag.CliProcessTest;
23+
import com.diffplug.spotless.tag.SeparateJvmTest;
24+
25+
@Isolated
26+
@SeparateJvmTest
27+
@CliNativeTest
28+
@CliProcessTest
29+
public class EclipseWtpJsonTest extends EclipseWtpTestBase {
30+
31+
@Test
32+
void itSupportsFormattingJsonFileType() {
33+
String fileName =
34+
runEclipseWtpWithType(EclipseWtp.Type.JSON, "{\"a\": \"b\",\t\"c\": { \"d\": \"e\",\"f\": \"g\"}}");
35+
selfie().expectResource(fileName).toMatchDisk();
36+
}
37+
}

app/src/test/java/com/diffplug/spotless/cli/steps/EclipseWtpSecondTest.java

Lines changed: 0 additions & 101 deletions
This file was deleted.

app/src/test/java/com/diffplug/spotless/cli/steps/EclipseWtpTest.java

Lines changed: 0 additions & 100 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2025 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.spotless.cli.steps;
17+
18+
import com.diffplug.spotless.cli.CLIIntegrationHarness;
19+
import com.diffplug.spotless.cli.SpotlessCLIRunner;
20+
21+
public abstract class EclipseWtpTestBase extends CLIIntegrationHarness {
22+
23+
protected String runEclipseWtpWithType(EclipseWtp.Type type, String unformatted) {
24+
String fileName = "test." + type.name().toLowerCase();
25+
setFile(fileName).toContent(unformatted);
26+
27+
SpotlessCLIRunner.Result result = cliRunner()
28+
.withTargets(fileName)
29+
.withStep(EclipseWtp.class)
30+
.withOption("--type", type.name())
31+
.run();
32+
33+
return fileName;
34+
}
35+
}

0 commit comments

Comments
 (0)