Skip to content

Commit

Permalink
Add sealed class testCases
Browse files Browse the repository at this point in the history
  • Loading branch information
blacelle committed Mar 7, 2023
1 parent c836a67 commit 9dcead6
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2015-2023 the original author or authors.
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v2.0 which
* accompanies this distribution and is available at
*
* https://www.eclipse.org/legal/epl-v20.html
*/

package java.removeunusedimports;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import org.junit.jupiter.api.Test;

class SealedClassTests extends AbstractJupiterTestEngineTests {

@Test
void sealedTestClassesAreTestClasses() {
executeTestsForClass(TestCase.class).testEvents() //
.assertStatistics(stats -> stats.finished(2).succeeded(1).failed(1));
}

sealed
abstract static class AbstractTestCase
permits TestCase
{

@Test
void succeedingTest() {
assertTrue(true);
}

@Test
void failingTest() {
fail("always fails");
}
}

static final class TestCase extends AbstractTestCase {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2015-2023 the original author or authors.
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v2.0 which
* accompanies this distribution and is available at
*
* https://www.eclipse.org/legal/epl-v20.html
*/

package java.removeunusedimports;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import org.junit.jupiter.api.Test;
import useless.project.UnusedClass;

class SealedClassTests extends AbstractJupiterTestEngineTests {

@Test
void sealedTestClassesAreTestClasses() {
executeTestsForClass(TestCase.class).testEvents() //
.assertStatistics(stats -> stats.finished(2).succeeded(1).failed(1));
}

sealed
abstract static class AbstractTestCase
permits TestCase
{

@Test
void succeedingTest() {
assertTrue(true);
}

@Test
void failingTest() {
fail("always fails");
}
}

static final class TestCase extends AbstractTestCase {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ void behavior() throws Exception {
.testResource("java/removeunusedimports/JavaCodeWithLicensePackageUnformatted.test", "java/removeunusedimports/JavaCodeWithLicensePackageFormatted.test")
.testResource("java/removeunusedimports/JavaCodeWithPackageUnformatted.test", "java/removeunusedimports/JavaCodeWithPackageFormatted.test")
.testResource("java/removeunusedimports/Jdk17TextBlockUnformatted.test", "java/removeunusedimports/Jdk17TextBlockFormatted.test")
.testResource("java/removeunusedimports/RevelcUnformatted.test", "java/removeunusedimports/RevelcFormatted.test");
.testResource("java/removeunusedimports/RevelcUnformatted.test", "java/removeunusedimports/RevelcFormatted.test")
// Sealed classes are introduced with JDK15: This syntax is not supported by javaParser: such files are not trimmed from unused imports (for now)
.testResource("java/removeunusedimports/SealedClassTestsUnformatted.test", "java/removeunusedimports/SealedClassTestsUnformatted.test");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ void behavior() throws Exception {
.testResource("java/removeunusedimports/JavaCodeWithLicenseUnformatted.test", "java/removeunusedimports/JavaCodeWithLicenseFormatted.test")
.testResource("java/removeunusedimports/JavaCodeWithLicensePackageUnformatted.test", "java/removeunusedimports/JavaCodeWithLicensePackageFormatted.test")
.testResource("java/removeunusedimports/JavaCodeWithPackageUnformatted.test", "java/removeunusedimports/JavaCodeWithPackageFormatted.test")
// GoogleFormat requires running over a JDK17 to handle JDK17 features
// .testResource("java/removeunusedimports/Jdk17TextBlockUnformatted.test", "java/removeunusedimports/Jdk17TextBlockFormatted.test")
.testResource("java/removeunusedimports/RevelcUnformatted.test", "java/removeunusedimports/RevelcFormatted.test");
.testResource("java/removeunusedimports/RevelcUnformatted.test", "java/removeunusedimports/RevelcFormatted.test")
// GoogleFormat requires running over a JDK17 to handle JDK17 features
// .testResource("java/removeunusedimports/Jdk17TextBlockUnformatted.test", "java/removeunusedimports/Jdk17TextBlockFormatted.test")
//.testResource("java/removeunusedimports/SealedClassTestsUnformatted.test", "java/removeunusedimports/SealedClassTestsFormatted.test");
}

@Test
Expand Down

0 comments on commit 9dcead6

Please sign in to comment.