summaryrefslogtreecommitdiff
path: root/jvm/jvm-analysis-java-tests
diff options
context:
space:
mode:
authorAndrej Shadura <andrew.shadura@collabora.co.uk>2019-08-28 14:13:29 +0200
committerAndrej Shadura <andrew.shadura@collabora.co.uk>2019-08-29 17:48:13 +0200
commite19ef5983707e6a5c8d127f1ac8f02754cef82fd (patch)
tree9e3852cb9abc81ed6aa444465928d45fd7763dea /jvm/jvm-analysis-java-tests
New upstream version 0~183.5153.4+dfsg
Diffstat (limited to 'jvm/jvm-analysis-java-tests')
-rw-r--r--jvm/jvm-analysis-java-tests/intellij.jvm.analysis.java.tests.iml12
-rw-r--r--jvm/jvm-analysis-java-tests/testSrc/com/intellij/codeInspection/tests/java/BlockingMethodInNonBlockingContextInspectionTest.java80
-rw-r--r--jvm/jvm-analysis-java-tests/testSrc/com/intellij/codeInspection/tests/java/NonNlsUastUtilTest.java49
-rw-r--r--jvm/jvm-analysis-java-tests/testSrc/com/intellij/codeInspection/tests/java/ScheduledForRemovalInspectionTest.kt22
-rw-r--r--jvm/jvm-analysis-java-tests/testSrc/com/intellij/codeInspection/tests/java/StringToUpperWithoutLocaleInspectionTest.java27
-rw-r--r--jvm/jvm-analysis-java-tests/testSrc/com/intellij/codeInspection/tests/java/UastCallMatcherTest.java30
-rw-r--r--jvm/jvm-analysis-java-tests/testSrc/com/intellij/codeInspection/tests/java/UnstableApiUsageInspectionTest.kt23
-rw-r--r--jvm/jvm-analysis-java-tests/testSrc/com/intellij/jvm/analysis/JvmAnalysisTestsUtil.java9
8 files changed, 252 insertions, 0 deletions
diff --git a/jvm/jvm-analysis-java-tests/intellij.jvm.analysis.java.tests.iml b/jvm/jvm-analysis-java-tests/intellij.jvm.analysis.java.tests.iml
new file mode 100644
index 00000000..43a9d1f7
--- /dev/null
+++ b/jvm/jvm-analysis-java-tests/intellij.jvm.analysis.java.tests.iml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="JAVA_MODULE" version="4">
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
+ <exclude-output />
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/testSrc" isTestSource="true" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="module" module-name="intellij.jvm.analysis.tests" />
+ </component>
+</module> \ No newline at end of file
diff --git a/jvm/jvm-analysis-java-tests/testSrc/com/intellij/codeInspection/tests/java/BlockingMethodInNonBlockingContextInspectionTest.java b/jvm/jvm-analysis-java-tests/testSrc/com/intellij/codeInspection/tests/java/BlockingMethodInNonBlockingContextInspectionTest.java
new file mode 100644
index 00000000..aed9c149
--- /dev/null
+++ b/jvm/jvm-analysis-java-tests/testSrc/com/intellij/codeInspection/tests/java/BlockingMethodInNonBlockingContextInspectionTest.java
@@ -0,0 +1,80 @@
+// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+package com.intellij.codeInspection.tests.java;
+
+import com.intellij.codeInspection.blockingCallsDetection.BlockingMethodInNonBlockingContextInspection;
+import com.intellij.openapi.application.ex.PathManagerEx;
+import com.intellij.openapi.module.Module;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.roots.JavaModuleExternalPaths;
+import com.intellij.openapi.roots.ModuleRootModificationUtil;
+import com.intellij.openapi.vfs.VfsUtilCore;
+import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
+import com.intellij.testFramework.UsefulTestCase;
+import com.intellij.testFramework.builders.JavaModuleFixtureBuilder;
+import com.intellij.testFramework.fixtures.*;
+
+import java.util.Collections;
+
+public class BlockingMethodInNonBlockingContextInspectionTest extends UsefulTestCase {
+
+ private CodeInsightTestFixture myFixture;
+
+ @Override
+ protected void tearDown() throws Exception {
+ try {
+ myFixture.tearDown();
+ }
+ finally {
+ myFixture = null;
+ super.tearDown();
+ }
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ final TestFixtureBuilder<IdeaProjectTestFixture>
+ projectBuilder = IdeaTestFixtureFactory.getFixtureFactory().createFixtureBuilder(getName());
+
+ myFixture = JavaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(projectBuilder.getFixture());
+ final String dataPath = PathManagerEx.getTestDataPath() + "/codeInspection/blockingCallsDetection";
+ myFixture.setTestDataPath(dataPath);
+ final JavaModuleFixtureBuilder builder = projectBuilder.addModule(JavaModuleFixtureBuilder.class);
+ builder.setMockJdkLevel(JavaModuleFixtureBuilder.MockJdkLevel.jdk15);
+
+ myFixture.setUp();
+ Module module = builder.getFixture().getModule();
+ ModuleRootModificationUtil.updateModel(module, model -> {
+ String contentUrl = VfsUtilCore.pathToUrl(myFixture.getTempDirPath());
+ model.addContentEntry(contentUrl).addSourceFolder(contentUrl, false);
+ final JavaModuleExternalPaths extension = model.getModuleExtension(JavaModuleExternalPaths.class);
+ extension.setExternalAnnotationUrls(new String[]{VfsUtilCore.pathToUrl(myFixture.getTempDirPath())});
+ });
+
+ Project project = myFixture.getProject();
+
+ JavaCodeStyleSettings.getInstance(project).USE_EXTERNAL_ANNOTATIONS = true;
+
+ BlockingMethodInNonBlockingContextInspection myInspection = new BlockingMethodInNonBlockingContextInspection();
+ myInspection.myBlockingAnnotations =
+ Collections.singletonList(BlockingMethodInNonBlockingContextInspection.DEFAULT_BLOCKING_ANNOTATION);
+ myInspection.myNonBlockingAnnotations =
+ Collections.singletonList(BlockingMethodInNonBlockingContextInspection.DEFAULT_NONBLOCKING_ANNOTATION);
+ myFixture.enableInspections(myInspection);
+ }
+
+ public void testSimpleAnnotationDetection() {
+ myFixture.configureByFiles("TestSimpleAnnotationsDetection.java", "Blocking.java", "NonBlocking.java");
+ myFixture.testHighlighting(true, false, true, "TestSimpleAnnotationsDetection.java");
+ }
+
+ public void testExternalBlockingAnnotationDetection() {
+ myFixture.configureByFiles("TestExternalAnnotationsDetection.java", "Blocking.java", "NonBlocking.java", "annotations.xml");
+ myFixture.testHighlighting(true, false, true, "TestExternalAnnotationsDetection.java");
+ }
+
+ public void testThrowsTypeDetection() {
+ myFixture.configureByFiles("TestThrowsTypeDetection.java", "Blocking.java", "NonBlocking.java");
+ myFixture.testHighlighting(true, false, true, "TestThrowsTypeDetection.java");
+ }
+}
diff --git a/jvm/jvm-analysis-java-tests/testSrc/com/intellij/codeInspection/tests/java/NonNlsUastUtilTest.java b/jvm/jvm-analysis-java-tests/testSrc/com/intellij/codeInspection/tests/java/NonNlsUastUtilTest.java
new file mode 100644
index 00000000..7e2ac8d4
--- /dev/null
+++ b/jvm/jvm-analysis-java-tests/testSrc/com/intellij/codeInspection/tests/java/NonNlsUastUtilTest.java
@@ -0,0 +1,49 @@
+package com.intellij.codeInspection.tests.java;
+
+import com.intellij.jvm.analysis.JvmAnalysisTestsUtil;
+import com.intellij.psi.PsiFile;
+import com.intellij.testFramework.TestDataPath;
+import com.intellij.testFramework.builders.JavaModuleFixtureBuilder;
+import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase;
+import com.intellij.util.PathUtil;
+import org.jetbrains.annotations.NonNls;
+import org.jetbrains.uast.ULiteralExpression;
+
+import java.util.Set;
+
+import static com.intellij.codeInspection.NonNlsUastUtil.isNonNlsStringLiteral;
+import static com.intellij.codeInspection.tests.JvmAnalysisTestsUastUtil.getUElementsOfTypeFromFile;
+
+@TestDataPath("$CONTENT_ROOT/testData/codeInspection/nonNls")
+public class NonNlsUastUtilTest extends JavaCodeInsightFixtureTestCase {
+ @Override
+ protected String getTestDataPath() {
+ return JvmAnalysisTestsUtil.TEST_DATA_PROJECT_RELATIVE_BASE_PATH + "/codeInspection/nonNls";
+ }
+
+ @Override
+ protected void tuneFixture(JavaModuleFixtureBuilder moduleBuilder) {
+ moduleBuilder.addLibrary("annotations", PathUtil.getJarPathForClass(NonNls.class));
+ }
+
+ public void testNonNlsStringLiterals() {
+ PsiFile file = myFixture.configureByFile("NonNlsStringLiteral.java");
+ Set<ULiteralExpression> expressions = getUElementsOfTypeFromFile(file, ULiteralExpression.class);
+ assertSize(12, expressions);
+ expressions.forEach(expression -> assertTrue(isNonNlsStringLiteral(expression)));
+ }
+
+ public void testPlainStringLiterals() {
+ PsiFile file = myFixture.configureByFile("PlainStringLiteral.java");
+ Set<ULiteralExpression> expressions = getUElementsOfTypeFromFile(file, ULiteralExpression.class);
+ assertSize(7, expressions);
+ expressions.forEach(expression -> assertFalse(isNonNlsStringLiteral(expression)));
+ }
+
+ public void testLiteralsInNonNlsClass() {
+ PsiFile file = myFixture.configureByFile("LiteralsInNonNlsClass.java");
+ Set<ULiteralExpression> expressions = getUElementsOfTypeFromFile(file, ULiteralExpression.class);
+ assertSize(7, expressions);
+ expressions.forEach(expression -> assertTrue(isNonNlsStringLiteral(expression)));
+ }
+}
diff --git a/jvm/jvm-analysis-java-tests/testSrc/com/intellij/codeInspection/tests/java/ScheduledForRemovalInspectionTest.kt b/jvm/jvm-analysis-java-tests/testSrc/com/intellij/codeInspection/tests/java/ScheduledForRemovalInspectionTest.kt
new file mode 100644
index 00000000..f79b9009
--- /dev/null
+++ b/jvm/jvm-analysis-java-tests/testSrc/com/intellij/codeInspection/tests/java/ScheduledForRemovalInspectionTest.kt
@@ -0,0 +1,22 @@
+package com.intellij.codeInspection.tests.java
+
+import com.intellij.codeInspection.tests.ScheduledForRemovalInspectionTestBase
+import com.intellij.jvm.analysis.JvmAnalysisTestsUtil.TEST_DATA_PROJECT_RELATIVE_BASE_PATH
+import com.intellij.testFramework.TestDataPath
+
+@TestDataPath("/testData/codeInspection/scheduledForRemoval")
+class ScheduledForRemovalInspectionTest: ScheduledForRemovalInspectionTestBase() {
+ override fun getBasePath() = ""
+
+ override fun getTestDataPath() = "${TEST_DATA_PROJECT_RELATIVE_BASE_PATH}/codeInspection/scheduledForRemoval"
+
+ fun testInspection() {
+ getInspection().myIgnoreInsideImports = false
+ myFixture.testHighlighting(true, false, false, "ScheduledForRemovalElementsTest.java")
+ }
+
+ fun testIgnoreImports() {
+ getInspection().myIgnoreInsideImports = true
+ myFixture.testHighlighting(true, false, false, "ScheduledForRemovalElementsIgnoreImportsTest.java")
+ }
+} \ No newline at end of file
diff --git a/jvm/jvm-analysis-java-tests/testSrc/com/intellij/codeInspection/tests/java/StringToUpperWithoutLocaleInspectionTest.java b/jvm/jvm-analysis-java-tests/testSrc/com/intellij/codeInspection/tests/java/StringToUpperWithoutLocaleInspectionTest.java
new file mode 100644
index 00000000..99868639
--- /dev/null
+++ b/jvm/jvm-analysis-java-tests/testSrc/com/intellij/codeInspection/tests/java/StringToUpperWithoutLocaleInspectionTest.java
@@ -0,0 +1,27 @@
+package com.intellij.codeInspection.tests.java;
+
+import com.intellij.codeInspection.tests.StringToUpperWithoutLocaleInspectionTestBase;
+import com.intellij.jvm.analysis.JvmAnalysisTestsUtil;
+import com.intellij.testFramework.TestDataPath;
+
+@TestDataPath("$CONTENT_ROOT/testData/codeInspection/toUpperWithoutLocale")
+public class StringToUpperWithoutLocaleInspectionTest extends StringToUpperWithoutLocaleInspectionTestBase {
+ @Override
+ protected String getTestDataPath() {
+ return JvmAnalysisTestsUtil.TEST_DATA_PROJECT_RELATIVE_BASE_PATH + "/codeInspection/toUpperWithoutLocale";
+ }
+
+ public void testSimpleCases() {
+ myFixture.testHighlighting("SimpleCases.java");
+ //TODO test after quickfix once it's implemented
+ }
+
+ public void testNonNlsCases() {
+ //TODO test #4 (about equals())
+ //TODO test #5 (about @NonNls in the left side of assignment expression)
+ //TODO test #6 with assigning method return value to variable? If this is not super hard to support.
+ myFixture.testHighlighting("NonNlsCases.java");
+ }
+
+ //TODO test pkg/subPkg
+}
diff --git a/jvm/jvm-analysis-java-tests/testSrc/com/intellij/codeInspection/tests/java/UastCallMatcherTest.java b/jvm/jvm-analysis-java-tests/testSrc/com/intellij/codeInspection/tests/java/UastCallMatcherTest.java
new file mode 100644
index 00000000..ca6fa47f
--- /dev/null
+++ b/jvm/jvm-analysis-java-tests/testSrc/com/intellij/codeInspection/tests/java/UastCallMatcherTest.java
@@ -0,0 +1,30 @@
+package com.intellij.codeInspection.tests.java;
+
+import com.intellij.codeInspection.tests.UastCallMatcherTestBase;
+import com.intellij.jvm.analysis.JvmAnalysisTestsUtil;
+import com.intellij.pom.java.LanguageLevel;
+import com.intellij.testFramework.TestDataPath;
+import com.intellij.testFramework.builders.JavaModuleFixtureBuilder;
+
+@TestDataPath("$CONTENT_ROOT/testData/codeInspection/uastCallMatcher")
+public class UastCallMatcherTest extends UastCallMatcherTestBase {
+ @Override
+ protected String getTestDataPath() {
+ return JvmAnalysisTestsUtil.TEST_DATA_PROJECT_RELATIVE_BASE_PATH + "/codeInspection/uastCallMatcher";
+ }
+
+ @Override
+ protected void tuneFixture(JavaModuleFixtureBuilder moduleBuilder) {
+ super.tuneFixture(moduleBuilder);
+ moduleBuilder.setLanguageLevel(LanguageLevel.JDK_1_8);
+ }
+
+
+ public void testCallExpressions() {
+ doTestCallExpressions("MyClass.java");
+ }
+
+ public void testCallableReferences() {
+ doTestCallableReferences("MethodReferences.java");
+ }
+}
diff --git a/jvm/jvm-analysis-java-tests/testSrc/com/intellij/codeInspection/tests/java/UnstableApiUsageInspectionTest.kt b/jvm/jvm-analysis-java-tests/testSrc/com/intellij/codeInspection/tests/java/UnstableApiUsageInspectionTest.kt
new file mode 100644
index 00000000..1b509c20
--- /dev/null
+++ b/jvm/jvm-analysis-java-tests/testSrc/com/intellij/codeInspection/tests/java/UnstableApiUsageInspectionTest.kt
@@ -0,0 +1,23 @@
+// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+package com.intellij.codeInspection.tests.java
+
+import com.intellij.codeInspection.tests.UnstableApiUsageInspectionTestBase
+import com.intellij.jvm.analysis.JvmAnalysisTestsUtil.TEST_DATA_PROJECT_RELATIVE_BASE_PATH
+import com.intellij.testFramework.TestDataPath
+
+@TestDataPath("/testData/codeInspection/unstableApiUsage")
+class UnstableApiUsageInspectionTest : UnstableApiUsageInspectionTestBase() {
+ override fun getBasePath() = ""
+
+ override fun getTestDataPath() = "${TEST_DATA_PROJECT_RELATIVE_BASE_PATH}/codeInspection/unstableApiUsage"
+
+ fun testInspection() {
+ getInspection().myIgnoreInsideImports = false
+ myFixture.testHighlighting(true, false, false, "UnstableElementsTest.java")
+ }
+
+ fun testIgnoreImports() {
+ getInspection().myIgnoreInsideImports = true
+ myFixture.testHighlighting(true, false, false, "UnstableElementsIgnoreImportsTest.java")
+ }
+}
diff --git a/jvm/jvm-analysis-java-tests/testSrc/com/intellij/jvm/analysis/JvmAnalysisTestsUtil.java b/jvm/jvm-analysis-java-tests/testSrc/com/intellij/jvm/analysis/JvmAnalysisTestsUtil.java
new file mode 100644
index 00000000..c5fceb66
--- /dev/null
+++ b/jvm/jvm-analysis-java-tests/testSrc/com/intellij/jvm/analysis/JvmAnalysisTestsUtil.java
@@ -0,0 +1,9 @@
+// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+package com.intellij.jvm.analysis;
+
+import com.intellij.openapi.application.ex.PathManagerEx;
+
+public final class JvmAnalysisTestsUtil {
+ public static final String TEST_DATA_PROJECT_RELATIVE_BASE_PATH =
+ PathManagerEx.getCommunityHomePath() + "/jvm/jvm-analysis-java-tests/testData";
+}