Skip to content

Commit

Permalink
Suppress IDEA's "malformed declaration" warning for TestCase classes
Browse files Browse the repository at this point in the history
  • Loading branch information
marcphilipp committed Oct 10, 2024
1 parent 43c8341 commit 1210901
Show file tree
Hide file tree
Showing 89 changed files with 371 additions and 8 deletions.
5 changes: 5 additions & 0 deletions documentation/src/test/java/example/TempDirectoryDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ void copyFileFromSourceToTarget(@TempDir Path source, @TempDir Path target) thro
}
// end::user_guide_multiple_directories[]

@SuppressWarnings("JUnitMalformedDeclaration")
static
// tag::user_guide_field_injection[]
class SharedTempDirectoryDemo {
Expand All @@ -87,6 +88,7 @@ void anotherTestThatUsesTheSameTempDir() {
}
// end::user_guide_field_injection[]

@SuppressWarnings("JUnitMalformedDeclaration")
static
// tag::user_guide_cleanup_mode[]
class CleanupModeDemo {
Expand All @@ -99,6 +101,7 @@ void fileTest(@TempDir(cleanup = ON_SUCCESS) Path tempDir) {
}
// end::user_guide_cleanup_mode[]

@SuppressWarnings("JUnitMalformedDeclaration")
static
// tag::user_guide_factory_name_prefix[]
class TempDirFactoryDemo {
Expand All @@ -121,6 +124,7 @@ public Path createTempDirectory(AnnotatedElementContext elementContext, Extensio
}
// end::user_guide_factory_name_prefix[]

@SuppressWarnings("JUnitMalformedDeclaration")
static
// tag::user_guide_factory_jimfs[]
class InMemoryTempDirDemo {
Expand Down Expand Up @@ -158,6 +162,7 @@ public void close() throws IOException {
}
// end::user_guide_composed_annotation[]

@SuppressWarnings("JUnitMalformedDeclaration")
static
// tag::user_guide_composed_annotation_usage[]
class JimfsTempDirAnnotationDemo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ private TestDescriptor discover(EngineDiscoveryRequest request) {
return new VintageDiscoverer().discover(request, engineId());
}

@SuppressWarnings("JUnitMalformedDeclaration")
public static class Foo {

@org.junit.Test
Expand All @@ -133,6 +134,7 @@ public void test() {

}

@SuppressWarnings("JUnitMalformedDeclaration")
public static class Bar {

@org.junit.Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import junit.framework.TestCase;
import junit.framework.TestSuite;

@SuppressWarnings("JUnitMalformedDeclaration")
public class JUnit3ParallelSuiteWithSubsuites extends TestCase {
private final String arg;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import junit.framework.TestCase;
import junit.framework.TestSuite;

@SuppressWarnings("JUnitMalformedDeclaration")
public class JUnit3SuiteWithSubsuites extends TestCase {
private final String arg;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ void this_is_a_test() {
}
}

@SuppressWarnings("JUnitMalformedDeclaration")
static class StaticNestedTestCase {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ static class UnderscoreStyleInheritedFromSuperClassTestCase extends UnderscoreSt

// -------------------------------------------------------------------

@SuppressWarnings("JUnitMalformedDeclaration")
@DisplayName("A stack")
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
static class StackTestCase {
Expand Down Expand Up @@ -353,6 +354,7 @@ void peek_returns_that_element_without_removing_it_from_the_stack() {

// -------------------------------------------------------------------

@SuppressWarnings("JUnitMalformedDeclaration")
@DisplayName("A stack")
@IndicativeSentencesGeneration(generator = DisplayNameGenerator.ReplaceUnderscores.class)
static class IndicativeGeneratorTestCase {
Expand Down Expand Up @@ -397,6 +399,7 @@ void is_no_longer_empty() {

// -------------------------------------------------------------------

@SuppressWarnings("JUnitMalformedDeclaration")
@DisplayName("A stack")
@IndicativeSentencesGeneration(separator = " >> ", generator = DisplayNameGenerator.ReplaceUnderscores.class)
static class IndicativeGeneratorWithCustomSeparatorTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ void this_is_a_test() {
}
}

@SuppressWarnings("JUnitMalformedDeclaration")
static class StaticNestedTestCase {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ void closesCloseableResourcesInReverseInsertOrder() {
reportEntry(Map.of("1", "closed")));
}

@SuppressWarnings("JUnitMalformedDeclaration")
@ExtendWith(ExtensionContextParameterResolver.class)
static class TestCase {
@Test
Expand Down Expand Up @@ -64,6 +65,7 @@ void exceptionsDuringCloseAreReportedAsSuppressed() {
))));
}

@SuppressWarnings("JUnitMalformedDeclaration")
@ExtendWith(ThrowingOnCloseExtension.class)
static class ExceptionInCloseableResourceTestCase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ void invokeMethodViaExtensionContext() {
assertEquals(2, ExecuteTestsTwiceTestCase.testInvocations);
}

@SuppressWarnings("JUnitMalformedDeclaration")
@ExtendWith(ExecuteTestsTwiceExtension.class)
static class ExecuteTestsTwiceTestCase {

static int testInvocations = 0;

@SuppressWarnings("JUnitMalformedDeclaration")
@Test
void testWithResolvedParameter(TestInfo testInfo,
@ExtendWith(ExtensionContextParameterResolver.class) ExtensionContext extensionContext) {
Expand All @@ -54,6 +56,7 @@ void testWithResolvedParameter(TestInfo testInfo,

}

@SuppressWarnings("JUnitMalformedDeclaration")
@ExtendWith(ExecuteConstructorTwiceExtension.class)
static class ExecuteConstructorTwiceTestCase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void beforeAllAndAfterAllAsMetaAnnotations() {
assertThat(methodsInvoked).containsExactly("beforeAll", "test", "afterAll");
}

@SuppressWarnings("JUnitMalformedDeclaration")
static class TestCase {

@CustomBeforeAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void beforeEachAndAfterEachAsMetaAnnotations() {
assertThat(methodsInvoked).containsExactly("beforeEach", "test", "afterEach");
}

@SuppressWarnings("JUnitMalformedDeclaration")
static class TestCase {

@CustomBeforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ private <T extends TestDescriptor> T firstChild(TestDescriptor engineDescriptor,
.orElseGet(() -> fail("No child of type " + testDescriptorClass + " found"));
}

@SuppressWarnings("JUnitMalformedDeclaration")
static class TestCase {

@Test
Expand Down Expand Up @@ -155,6 +156,7 @@ static class ConcurrentTestCase extends TestCase {
static class SameThreadTestCase extends TestCase {
}

@SuppressWarnings("JUnitMalformedDeclaration")
static class OuterTestCase {
@Nested
class LevelOne {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ default void afterAll() {

}

@SuppressWarnings("JUnitMalformedDeclaration")
static class GenericTestCaseWithDefaultMethod implements GenericTestInterface<Long> {

@Test
Expand All @@ -210,6 +211,7 @@ void test(Double number) {

}

@SuppressWarnings("JUnitMalformedDeclaration")
static class GenericTestCaseWithOverriddenDefaultMethod implements GenericTestInterface<Long> {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void executeTestsWithDisabledTestMethods() throws Exception {

// -------------------------------------------------------------------

@SuppressWarnings("JUnitMalformedDeclaration")
@Disabled
static class DisabledTestClassTestCase {

Expand All @@ -59,6 +60,7 @@ void disabledTest() {
}
}

@SuppressWarnings("JUnitMalformedDeclaration")
static class DisabledTestMethodsTestCase {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ void cleanUpExceptions() {

// -------------------------------------------------------------------------

@SuppressWarnings("JUnitMalformedDeclaration")
static class FailureTestCase {

static Optional<Throwable> exceptionToThrowInBeforeAll = Optional.empty();
Expand Down Expand Up @@ -309,6 +310,7 @@ void abortedTest() {

}

@SuppressWarnings("JUnitMalformedDeclaration")
@TestInstance(PER_METHOD)
@ExtendWith(ThrowingAfterAllCallback.class)
static class TestCaseWithInvalidConstructorAndThrowingAfterAllCallbackAndPerMethodLifecycle {
Expand All @@ -322,6 +324,7 @@ void test() {

}

@SuppressWarnings("JUnitMalformedDeclaration")
@TestInstance(PER_CLASS)
@ExtendWith(ThrowingAfterAllCallback.class)
static class TestCaseWithInvalidConstructorAndThrowingAfterAllCallbackAndPerClassLifecycle {
Expand All @@ -334,6 +337,7 @@ void test() {
}
}

@SuppressWarnings("JUnitMalformedDeclaration")
@ExtendWith(ThrowingBeforeAllCallback.class)
@ExtendWith(ThrowingAfterAllCallback.class)
static class TestCaseWithThrowingBeforeAllAndAfterAllCallbacks {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void assumptionViolatedExceptionInBeforeAll() {

// -------------------------------------------------------------------

@SuppressWarnings("JUnitMalformedDeclaration")
static class TestAbortedExceptionInBeforeAllTestCase {

@BeforeAll
Expand All @@ -54,6 +55,7 @@ void test() {
}
}

@SuppressWarnings("JUnitMalformedDeclaration")
static class AssumptionViolatedExceptionInBeforeAllTestCase {

@BeforeAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,19 @@ private void assertContainerFailed(Class<?> invalidTestClass) {

// -------------------------------------------------------------------------

@SuppressWarnings("JUnitMalformedDeclaration")
static class TestCase {

@Test
void test() {
}
}

@SuppressWarnings("JUnitMalformedDeclaration")
static class TestCaseWithInvalidNonStaticBeforeAllMethod {

// must be static
@SuppressWarnings("JUnitMalformedDeclaration")
@BeforeAll
void beforeAll() {
}
Expand All @@ -92,9 +95,11 @@ void test() {
}
}

@SuppressWarnings("JUnitMalformedDeclaration")
static class TestCaseWithInvalidNonStaticAfterAllMethod {

// must be static
@SuppressWarnings("JUnitMalformedDeclaration")
@AfterAll
void afterAll() {
}
Expand All @@ -104,9 +109,11 @@ void test() {
}
}

@SuppressWarnings("JUnitMalformedDeclaration")
static class TestCaseWithInvalidStaticBeforeEachMethod {

// must NOT be static
@SuppressWarnings("JUnitMalformedDeclaration")
@BeforeEach
static void beforeEach() {
}
Expand All @@ -116,9 +123,11 @@ void test() {
}
}

@SuppressWarnings("JUnitMalformedDeclaration")
static class TestCaseWithInvalidStaticAfterEachMethod {

// must NOT be static
@SuppressWarnings("JUnitMalformedDeclaration")
@AfterEach
static void afterEach() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ void testAndRepeatedTest(@TrackLogRecords LogRecordListener listener) {
// @formatter:on
}

@SuppressWarnings("JUnitMalformedDeclaration")
static class TestCase {

@SuppressWarnings("JUnitMalformedDeclaration")
@Test
@RepeatedTest(1)
void testAndRepeatedTest(RepetitionInfo repetitionInfo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ private void assertNestedCycle(Class<?> start, Class<?> from, Class<?> to) {

// -------------------------------------------------------------------

@SuppressWarnings("JUnitMalformedDeclaration")
static class TestCaseWithNesting {

@Test
Expand All @@ -210,6 +211,7 @@ void failing() {
}
}

@SuppressWarnings("JUnitMalformedDeclaration")
static class TestCaseWithDoubleNesting {

static int beforeTopCount = 0;
Expand Down Expand Up @@ -283,6 +285,7 @@ void failing() {

interface InterfaceWithNestedClass {

@SuppressWarnings("JUnitMalformedDeclaration")
@Nested
class NestedInInterface {

Expand Down Expand Up @@ -334,6 +337,7 @@ class ConcreteInner2 extends AbstractSuperClass {
static class AbstractOuterClass {
}

@SuppressWarnings("JUnitMalformedDeclaration")
static class OuterClass extends AbstractOuterClass {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ class NonVoidTestableMethodIntegrationTests {
void valid() {
}

@SuppressWarnings("JUnitMalformedDeclaration")
@Test
int invalidMethodReturningPrimitive() {
fail("This method should never have been called.");
return 1;
}

@SuppressWarnings("JUnitMalformedDeclaration")
@Test
String invalidMethodReturningObject() {
fail("This method should never have been called.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ void executeTestCaseWithOverloadedMethodsWithSingleMethodThatAcceptsArgumentsSel
assertTrue(first.isPresent());
}

@SuppressWarnings("JUnitMalformedDeclaration")
static class TestCase {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ void recordsAreTestClasses() {
.assertStatistics(stats -> stats.finished(2).succeeded(1).failed(1));
}

@SuppressWarnings("JUnitMalformedDeclaration")
record TestCase() {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void reportEntriesArePublished() {
.reportingEntryPublished(7));
}

@SuppressWarnings("JUnitMalformedDeclaration")
static class MyReportingTestCase {

@BeforeEach
Expand Down
Loading

0 comments on commit 1210901

Please sign in to comment.