use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.
the class BlazeJavaTestClassConfigurationProducer method getSingleJUnitTestClass.
/**
* Returns the {@link TestLocation} corresponding to the single selected JUnit test class, or
* {@code null} if something else is selected.
*/
@Nullable
private TestLocation getSingleJUnitTestClass(ConfigurationContext context) {
Location<?> location = context.getLocation();
if (location == null) {
return null;
}
location = JavaExecutionUtil.stepIntoSingleClass(location);
if (location == null) {
return null;
}
// check for contexts handled by a different producer
if (!SmRunnerUtils.getSelectedSmRunnerTreeElements(context).isEmpty()) {
return null;
}
if (JUnitConfigurationUtil.isMultipleElementsSelected(context)) {
return null;
}
if (JavaTestCaseIdentifier.isAnyTestCase(context)) {
return null;
}
PsiClass testClass = JUnitUtil.getTestClass(location);
if (testClass == null || testClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
return null;
}
TestSize testSize = TestSizeAnnotationMap.getTestSize(testClass);
TargetInfo target = RunUtil.targetForTestClass(testClass, testSize);
return target != null ? new TestLocation(testClass, target) : null;
}
use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.
the class RunUtil method targetForTestClass.
/**
* @return The Blaze test rule containing the target test class. In the case of multiple
* containing rules, the first rule sorted alphabetically by label.
*/
@Nullable
public static TargetInfo targetForTestClass(PsiClass testClass, @Nullable TestSize testSize) {
File testFile = getFileForClass(testClass);
if (testFile == null) {
return null;
}
Project project = testClass.getProject();
Collection<TargetInfo> targets = SourceToTargetFinder.findTargetsForSourceFile(project, testFile, Optional.of(RuleType.TEST));
return TestTargetHeuristic.chooseTestTargetForSourceFile(project, testClass.getContainingFile(), testFile, targets, testSize);
}
use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.
the class CombinedTestHeuristicTest method testSizeAndJUnit4Combination.
@Test
public void testSizeAndJUnit4Combination() {
Collection<TargetInfo> targets = ImmutableList.of(createTarget("//foo:SmallJUnit3Tests", TestSize.SMALL), createTarget("//foo:MediumJUnit3Tests", TestSize.MEDIUM), createTarget("//foo:LargeJUnit3Tests", TestSize.LARGE), createTarget("//foo:SmallJUnit4Tests", TestSize.SMALL), createTarget("//foo:MediumJUnit4Tests", TestSize.MEDIUM), createTarget("//foo:LargeJUnit4Tests", TestSize.LARGE));
PsiFile psiFile = workspace.createPsiFile(new WorkspacePath("java/com/google/lib/JavaTest.java"), "package com.google.lib;", "import org.junit.Test;", "import org.junit.runner.RunWith;", "import org.junit.runners.JUnit4;", "@RunWith(JUnit4.class)", "public class JavaTest {", " @Test", " public void testMethod1() {}", " @Test", " public void testMethod2() {}", "}");
File source = new File(psiFile.getVirtualFile().getPath());
TargetInfo match = TestTargetHeuristic.chooseTestTargetForSourceFile(getProject(), psiFile, source, targets, TestSize.LARGE);
assertThat(match.label).isEqualTo(Label.create("//foo:LargeJUnit4Tests"));
match = TestTargetHeuristic.chooseTestTargetForSourceFile(getProject(), psiFile, source, targets, TestSize.MEDIUM);
assertThat(match.label).isEqualTo(Label.create("//foo:MediumJUnit4Tests"));
}
use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.
the class QualifiedClassNameHeuristicTest method testMatchesQualifiedClassNames.
@Test
public void testMatchesQualifiedClassNames() {
PsiFile psiFile = workspace.createPsiFile(new WorkspacePath("com/google/lib/JavaClass.java"), "package com.google.lib;", "public class JavaClass {}");
File file = new File(psiFile.getVirtualFile().getPath());
TargetInfo target = TargetIdeInfo.builder().setLabel("//foo:lib.JavaClass").setKind("java_test").build().toTargetInfo();
assertThat(new QualifiedClassNameHeuristic().matchesSource(getProject(), target, psiFile, file, null)).isTrue();
target = TargetIdeInfo.builder().setLabel("//foo:google.lib.JavaClass").setKind("java_test").build().toTargetInfo();
assertThat(new QualifiedClassNameHeuristic().matchesSource(getProject(), target, psiFile, file, null)).isTrue();
target = TargetIdeInfo.builder().setLabel("//foo:com.google.lib.JavaClass").setKind("java_test").build().toTargetInfo();
assertThat(new QualifiedClassNameHeuristic().matchesSource(getProject(), target, psiFile, file, null)).isTrue();
}
use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.
the class QualifiedClassNameHeuristicTest method testDoesNotMatchUnqualifiedClassName.
@Test
public void testDoesNotMatchUnqualifiedClassName() {
PsiFile psiFile = workspace.createPsiFile(new WorkspacePath("com/google/lib/JavaClass.java"), "package com.google.lib;", "public class JavaClass {}");
File file = new File(psiFile.getVirtualFile().getPath());
TargetInfo target = TargetIdeInfo.builder().setLabel("//foo:JavaClass").setKind("java_test").build().toTargetInfo();
assertThat(new QualifiedClassNameHeuristic().matchesSource(getProject(), target, psiFile, file, null)).isFalse();
}
Aggregations