diff --git a/java/java-tests/testData/codeInsight/unwrapElseBranch/afterSimple4.java b/java/java-tests/testData/codeInsight/unwrapElseBranch/afterSimple4.java deleted file mode 100644 index 14bc08a4cd6e..000000000000 --- a/java/java-tests/testData/codeInsight/unwrapElseBranch/afterSimple4.java +++ /dev/null @@ -1,11 +0,0 @@ -// "Unwrap 'else' branch (changes semantics)" "true" - -class T { - String f(boolean b) { - if (b) - System.out.println("When true"); - else - return "Otherwise"; - return "Default"; - } -} \ No newline at end of file diff --git a/java/java-tests/testData/inspection/java9CollectionFactory/afterHashSetAsListRepeating.java b/java/java-tests/testData/inspection/java9CollectionFactory/beforeHashSetAsListRepeating.java similarity index 71% rename from java/java-tests/testData/inspection/java9CollectionFactory/afterHashSetAsListRepeating.java rename to java/java-tests/testData/inspection/java9CollectionFactory/beforeHashSetAsListRepeating.java index a01fa043f554..838015396e81 100644 --- a/java/java-tests/testData/inspection/java9CollectionFactory/afterHashSetAsListRepeating.java +++ b/java/java-tests/testData/inspection/java9CollectionFactory/beforeHashSetAsListRepeating.java @@ -7,5 +7,5 @@ import java.util.Set; public class Test { static final String CONST = "b"; - public static final Set MY_SET = Set.of("a", "b", "c", CONST); + public static final Set MY_SET = Set.of("a", "b", "c", CONST); } diff --git a/java/java-tests/testData/inspection/requireNonNull/afterSimpleCheck.java b/java/java-tests/testData/inspection/requireNonNull/afterSimpleCheck.java deleted file mode 100644 index 75afa6cd2271..000000000000 --- a/java/java-tests/testData/inspection/requireNonNull/afterSimpleCheck.java +++ /dev/null @@ -1,9 +0,0 @@ -// "Replace condition with Objects.requireNonNullElse" "true" - -import java.util.*; - -class Test { - public void test(Object o) { - o = Objects.requireNonNullElse(o, ""); - } -} \ No newline at end of file diff --git a/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/LightQuickFixParameterizedTestCase.java b/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/LightQuickFixParameterizedTestCase.java index 6ef64aa118d0..ae9fb5e35580 100644 --- a/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/LightQuickFixParameterizedTestCase.java +++ b/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/LightQuickFixParameterizedTestCase.java @@ -17,6 +17,7 @@ package com.intellij.codeInsight.daemon.quickFix; import com.intellij.testFramework.FileBasedTestCaseHelperEx; import com.intellij.testFramework.Parameterized; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.junit.Test; import org.junit.runner.RunWith; @@ -35,6 +36,13 @@ public abstract class LightQuickFixParameterizedTestCase extends LightQuickFixTe return fileName.substring(BEFORE_PREFIX.length()); } + @Nullable + @Override + public String getFileAfterSuffix(@NotNull String fileName) { + if (!fileName.startsWith(AFTER_PREFIX)) return null; + return fileName.substring(AFTER_PREFIX.length()); + } + @Test public void runSingle() throws Throwable { runSingleTest(() -> doSingleTest(myFileSuffix, myTestDataPath)); diff --git a/platform/testFramework/src/com/intellij/testFramework/FileBasedTestCaseHelper.java b/platform/testFramework/src/com/intellij/testFramework/FileBasedTestCaseHelper.java index 615656901f4a..b8a016bae2fc 100644 --- a/platform/testFramework/src/com/intellij/testFramework/FileBasedTestCaseHelper.java +++ b/platform/testFramework/src/com/intellij/testFramework/FileBasedTestCaseHelper.java @@ -15,6 +15,7 @@ */ package com.intellij.testFramework; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -33,4 +34,12 @@ public interface FileBasedTestCaseHelper { */ @Nullable String getFileSuffix(String fileName); + + /** + * @return for 'after' files should return core file name or null otherwise + */ + @Nullable + default String getFileAfterSuffix(@NotNull String fileName) { + return null; + } } diff --git a/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java b/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java index f6f0011ca7cd..a9cb6e670aaf 100644 --- a/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java @@ -55,9 +55,7 @@ import org.junit.runners.Parameterized; import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import java.util.*; public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTestCase { private Editor myEditor; @@ -716,13 +714,24 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest fail("Test files not found in " + testDir.getPath()); } + final Set beforeFileSuffixes = new HashSet<>(); + final Set afterFileSuffixes = new HashSet<>(); final List result = new ArrayList<>(); for (File file : files) { final String fileSuffix = fileBasedTestCase.getFileSuffix(file.getName()); + String fileAfterSuffix = fileBasedTestCase.getFileAfterSuffix(file.getName()); + if (fileAfterSuffix != null) { + afterFileSuffixes.add(fileAfterSuffix); + } if (fileSuffix != null) { + beforeFileSuffixes.add(fileSuffix); result.add(new Object[] {fileSuffix, testDataPath}); } } + afterFileSuffixes.removeAll(beforeFileSuffixes); + if (!afterFileSuffixes.isEmpty()) { + fail("'After' file has no corresponding 'before' file: " + String.join(", ", afterFileSuffixes)); + } return result; }