Revert "Revert "[code vision] IDEA-308383: add tests""

This reverts commit 2431e8827ad5eebd3b291007fd08847bd4d0691d.

GitOrigin-RevId: f8eae4a8f86970e7184d12bf4f9b40a9cc3f725f
This commit is contained in:
Alexandr Suhinin
2023-03-08 17:33:17 +02:00
committed by intellij-monorepo-bot
parent a4418b235a
commit 4e254303d0
9 changed files with 147 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
class ExternalUsage {
void foo(){
new Test().test();
<caret>
}
}

View File

@@ -0,0 +1,10 @@
class Test {
void use() {
test();
test();
}
void test() {
}
}

View File

@@ -0,0 +1,5 @@
class ExternalUsage {
void foo(){
new Test().test();
}
}

View File

@@ -0,0 +1,11 @@
class Test {
void use() {
test();
test();
<caret>
}
void test() {
}
}

View File

@@ -0,0 +1,5 @@
class ExternalUsage {
void foo(){
new Test().test();
}
}

View File

@@ -0,0 +1,10 @@
class Test<caret> {
void use() {
test();
test();
}
void test() {
}
}

View File

@@ -0,0 +1,5 @@
class ExternalUsage {
void foo(){
Test.test();
}
}

View File

@@ -0,0 +1,10 @@
class Test {
void use() {
test();
test();
}
public static void test<caret>() {
}
}

View File

@@ -0,0 +1,85 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.java.codeInsight.codeVision
import com.intellij.JavaTestUtil
import com.intellij.codeInsight.JavaCodeInsightTestCase
import com.intellij.codeInsight.daemon.impl.UsagesCountManager
import com.intellij.psi.JavaPsiFacade
import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiMember
import com.intellij.psi.search.GlobalSearchScope
class JavaCodeVisionCacheTest : JavaCodeInsightTestCase() {
override fun getTestDataPath(): String {
return JavaTestUtil.getJavaTestDataPath() + "/codeVision/"
}
fun testChangedMethodName() {
configureAndOpenLocalFile()
val testMember = findTestMember()
val initialUsages = countUsages(testMember)
require(initialUsages == 3)
typeAndCommit("random")
val currentUsages = countUsages(testMember)
require(currentUsages == 0)
}
fun testChangedClassName() {
configureAndOpenLocalFile()
val testMember = findTestMember()
val initialUsages = countUsages(testMember)
require(initialUsages == 3)
typeAndCommit("random")
val currentUsages = countUsages(testMember)
require(currentUsages == 2)
}
fun testAddedExternalUsage() {
configureAndOpenExternalFile()
val testMember = findTestMember()
val initialUsages = countUsages(testMember)
require(initialUsages == 3)
typeAndCommit("Test.test();")
val currentUsages = countUsages(testMember)
require(currentUsages == 4)
}
fun testAddedLocalUsage() {
configureAndOpenLocalFile()
val testMember = findTestMember()
val initialUsages = countUsages(testMember)
require(initialUsages == 3)
typeAndCommit("test();")
val currentUsages = countUsages(testMember)
require(currentUsages == 4)
}
private fun configureAndOpenLocalFile() {
configureByFiles(null, "${getTestDirectory()}/Test.java", "${getTestDirectory()}/ExternalUsage.java", )
}
private fun configureAndOpenExternalFile() {
configureByFiles(null, "${getTestDirectory()}/ExternalUsage.java", "${getTestDirectory()}/Test.java")
}
private fun getTestDirectory(): String = getTestName(true)
private fun findTestMember(): PsiMember {
val testClass = JavaPsiFacade.getInstance(project).findClass("Test", GlobalSearchScope.allScope(project))
val externalClass = JavaPsiFacade.getInstance(project).findClass("ExternalUsage", GlobalSearchScope.allScope(project))
require(externalClass != null)
val member: PsiMember? = testClass?.findMethodsByName("test", false)?.firstOrNull()
require(member != null)
return member
}
private fun countUsages(member: PsiMember): Int {
return UsagesCountManager.getInstance(project).countMemberUsages(member.containingFile, member)
}
private fun typeAndCommit(s: String) {
type(s)
PsiDocumentManager.getInstance(project).commitDocument(editor.document)
}
}