Extract into tester
@@ -7,6 +7,7 @@ import ai.vespa.intellij.schema.findUsages.SdFindUsagesHandler;
import ai.vespa.intellij.schema.model.Schema;
import ai.vespa.intellij.schema.utils.Path;
import com.intellij.find.findUsages.FindUsagesOptions;
+import com.intellij.openapi.project.Project;
import com.intellij.usageView.UsageInfo;
import com.intellij.util.Processor;
import org.junit.Test;
@@ -22,14 +23,31 @@ public class FindUsagesTest extends PluginTestBase {
@Test
public void testFindUsages() {
useDir("src/test/applications/rankprofilemodularity");
- Schema schema = Schema.fromProjectFile(getProject(), Path.fromString("test.sd"));
- var handler = new SdFindUsagesHandler(schema.definition());
- var function = SdUtil.functionsIn(schema.rankProfile("in_schema2").get()).get("ff1").get(0).definition();
+ var tester = new UsagesTester("test.sd", getProject());
+ tester.assertFunctionUsages("Self reference + 2 local references", 3, "in_schema2", "ff1");
+ }
+
+ private static class UsagesTester {
+
+ final Project project;
+ final Schema schema;
+ final SdFindUsagesHandler handler;
+
+ UsagesTester(String schemaName, Project project) {
+ this.project = project;
+ this.schema = Schema.fromProjectFile(project, Path.fromString(schemaName));
+ this.handler = new SdFindUsagesHandler(schema.definition());
+ }
+
+ void assertFunctionUsages(String explanation, int expectedUsages, String profileName, String functionName) {
+ var function = SdUtil.functionsIn(schema.rankProfile(profileName).get()).get(functionName).get(0).definition();
var usageProcessor = new MockUsageProcessor();
- var options = new FindUsagesOptions(getProject());
+ var options = new FindUsagesOptions(project);
options.isUsages = true;
handler.processElementUsages(function, usageProcessor, options);
- assertEquals(3, usageProcessor.usages.size());
+ assertEquals(explanation, expectedUsages, usageProcessor.usages.size());
+ }
+
}
private static class MockUsageProcessor implements Processor<UsageInfo> {
