aboutsummaryrefslogtreecommitdiffstats
path: root/integration
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2022-02-14 09:32:54 +0100
committerJon Bratseth <bratseth@gmail.com>2022-02-14 09:32:54 +0100
commitc509ce4b8c700edda928f6f95f6e5b29b3ba9ec3 (patch)
tree353a7c0aa58c2545aae5ce280fc21755a3a8bad5 /integration
parentc197c97e70262daaaa6a1f70c98e41daee3a1bbc (diff)
Extract into tester
Diffstat (limited to 'integration')
-rw-r--r--integration/intellij/src/test/java/ai/vespa/intellij/findUsages/FindUsagesTest.java34
1 files changed, 26 insertions, 8 deletions
diff --git a/integration/intellij/src/test/java/ai/vespa/intellij/findUsages/FindUsagesTest.java b/integration/intellij/src/test/java/ai/vespa/intellij/findUsages/FindUsagesTest.java
index ede86906a3e..fb0e7b685eb 100644
--- a/integration/intellij/src/test/java/ai/vespa/intellij/findUsages/FindUsagesTest.java
+++ b/integration/intellij/src/test/java/ai/vespa/intellij/findUsages/FindUsagesTest.java
@@ -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 usageProcessor = new MockUsageProcessor();
- var options = new FindUsagesOptions(getProject());
- options.isUsages = true;
- handler.processElementUsages(function, usageProcessor, options);
- assertEquals(3, usageProcessor.usages.size());
+ 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(project);
+ options.isUsages = true;
+ handler.processElementUsages(function, usageProcessor, options);
+ assertEquals(explanation, expectedUsages, usageProcessor.usages.size());
+ }
+
}
private static class MockUsageProcessor implements Processor<UsageInfo> {