Skip to content

Commit 9dcead6

Browse files
committed
Add sealed class testCases
1 parent c836a67 commit 9dcead6

File tree

4 files changed

+98
-4
lines changed

4 files changed

+98
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2015-2023 the original author or authors.
3+
*
4+
* All rights reserved. This program and the accompanying materials are
5+
* made available under the terms of the Eclipse Public License v2.0 which
6+
* accompanies this distribution and is available at
7+
*
8+
* https://www.eclipse.org/legal/epl-v20.html
9+
*/
10+
11+
package java.removeunusedimports;
12+
13+
import static org.junit.jupiter.api.Assertions.assertTrue;
14+
import static org.junit.jupiter.api.Assertions.fail;
15+
16+
import org.junit.jupiter.api.Test;
17+
18+
class SealedClassTests extends AbstractJupiterTestEngineTests {
19+
20+
@Test
21+
void sealedTestClassesAreTestClasses() {
22+
executeTestsForClass(TestCase.class).testEvents() //
23+
.assertStatistics(stats -> stats.finished(2).succeeded(1).failed(1));
24+
}
25+
26+
sealed
27+
abstract static class AbstractTestCase
28+
permits TestCase
29+
{
30+
31+
@Test
32+
void succeedingTest() {
33+
assertTrue(true);
34+
}
35+
36+
@Test
37+
void failingTest() {
38+
fail("always fails");
39+
}
40+
}
41+
42+
static final class TestCase extends AbstractTestCase {
43+
}
44+
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2015-2023 the original author or authors.
3+
*
4+
* All rights reserved. This program and the accompanying materials are
5+
* made available under the terms of the Eclipse Public License v2.0 which
6+
* accompanies this distribution and is available at
7+
*
8+
* https://www.eclipse.org/legal/epl-v20.html
9+
*/
10+
11+
package java.removeunusedimports;
12+
13+
import static org.junit.jupiter.api.Assertions.assertTrue;
14+
import static org.junit.jupiter.api.Assertions.fail;
15+
16+
import org.junit.jupiter.api.Test;
17+
import useless.project.UnusedClass;
18+
19+
class SealedClassTests extends AbstractJupiterTestEngineTests {
20+
21+
@Test
22+
void sealedTestClassesAreTestClasses() {
23+
executeTestsForClass(TestCase.class).testEvents() //
24+
.assertStatistics(stats -> stats.finished(2).succeeded(1).failed(1));
25+
}
26+
27+
sealed
28+
abstract static class AbstractTestCase
29+
permits TestCase
30+
{
31+
32+
@Test
33+
void succeedingTest() {
34+
assertTrue(true);
35+
}
36+
37+
@Test
38+
void failingTest() {
39+
fail("always fails");
40+
}
41+
}
42+
43+
static final class TestCase extends AbstractTestCase {
44+
}
45+
46+
}

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ void behavior() throws Exception {
3232
.testResource("java/removeunusedimports/JavaCodeWithLicensePackageUnformatted.test", "java/removeunusedimports/JavaCodeWithLicensePackageFormatted.test")
3333
.testResource("java/removeunusedimports/JavaCodeWithPackageUnformatted.test", "java/removeunusedimports/JavaCodeWithPackageFormatted.test")
3434
.testResource("java/removeunusedimports/Jdk17TextBlockUnformatted.test", "java/removeunusedimports/Jdk17TextBlockFormatted.test")
35-
.testResource("java/removeunusedimports/RevelcUnformatted.test", "java/removeunusedimports/RevelcFormatted.test");
35+
.testResource("java/removeunusedimports/RevelcUnformatted.test", "java/removeunusedimports/RevelcFormatted.test")
36+
// Sealed classes are introduced with JDK15: This syntax is not supported by javaParser: such files are not trimmed from unused imports (for now)
37+
.testResource("java/removeunusedimports/SealedClassTestsUnformatted.test", "java/removeunusedimports/SealedClassTestsUnformatted.test");
3638
}
3739

3840
@Test

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ void behavior() throws Exception {
3131
.testResource("java/removeunusedimports/JavaCodeWithLicenseUnformatted.test", "java/removeunusedimports/JavaCodeWithLicenseFormatted.test")
3232
.testResource("java/removeunusedimports/JavaCodeWithLicensePackageUnformatted.test", "java/removeunusedimports/JavaCodeWithLicensePackageFormatted.test")
3333
.testResource("java/removeunusedimports/JavaCodeWithPackageUnformatted.test", "java/removeunusedimports/JavaCodeWithPackageFormatted.test")
34-
// GoogleFormat requires running over a JDK17 to handle JDK17 features
35-
// .testResource("java/removeunusedimports/Jdk17TextBlockUnformatted.test", "java/removeunusedimports/Jdk17TextBlockFormatted.test")
36-
.testResource("java/removeunusedimports/RevelcUnformatted.test", "java/removeunusedimports/RevelcFormatted.test");
34+
.testResource("java/removeunusedimports/RevelcUnformatted.test", "java/removeunusedimports/RevelcFormatted.test")
35+
// GoogleFormat requires running over a JDK17 to handle JDK17 features
36+
// .testResource("java/removeunusedimports/Jdk17TextBlockUnformatted.test", "java/removeunusedimports/Jdk17TextBlockFormatted.test")
37+
//.testResource("java/removeunusedimports/SealedClassTestsUnformatted.test", "java/removeunusedimports/SealedClassTestsFormatted.test");
3738
}
3839

3940
@Test

0 commit comments

Comments
 (0)