Search in sources :

Example 46 with TargetInfo

use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.

the class JUnitTestHeuristicTest method testMatchesJunit4Annotation.

@Test
public void testMatchesJunit4Annotation() {
    PsiFile psiFile = workspace.createPsiFile(new WorkspacePath("java/com/google/lib/JavaClass.java"), "package com.google.lib;", "import org.junit.Test;", "import org.junit.runner.RunWith;", "import org.junit.runners.JUnit4;", "@RunWith(JUnit4.class)", "public class JavaClass {", "  @Test", "  public void testMethod1() {}", "  @Test", "  public void testMethod2() {}", "}");
    File file = new File(psiFile.getVirtualFile().getPath());
    TargetInfo target = TargetIdeInfo.builder().setLabel("//foo:AllJUnit4Tests").setKind("java_test").build().toTargetInfo();
    assertThat(new JUnitTestHeuristic().matchesSource(getProject(), target, psiFile, file, null)).isTrue();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) PsiFile(com.intellij.psi.PsiFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) Test(org.junit.Test)

Example 47 with TargetInfo

use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.

the class JUnitTestHeuristicTest method testNonJavaFileDoesNotMatch.

@Test
public void testNonJavaFileDoesNotMatch() {
    PsiFile psiFile = workspace.createPsiFile(new WorkspacePath("foo/script_test.py"));
    File file = new File(psiFile.getVirtualFile().getPath());
    TargetInfo target = TargetIdeInfo.builder().setLabel("//foo:unrelatedName").setKind("py_test").build().toTargetInfo();
    assertThat(new JUnitTestHeuristic().matchesSource(getProject(), target, psiFile, file, null)).isFalse();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) PsiFile(com.intellij.psi.PsiFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) Test(org.junit.Test)

Example 48 with TargetInfo

use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.

the class JUnitTestHeuristicTest method testIgnoresJunit4AnnotationIfTargetNameDoesNotMatch.

@Test
public void testIgnoresJunit4AnnotationIfTargetNameDoesNotMatch() {
    PsiFile psiFile = workspace.createPsiFile(new WorkspacePath("java/com/google/lib/JavaClass.java"), "package com.google.lib;", "import org.junit.Test;", "import org.junit.runner.RunWith;", "import org.junit.runners.JUnit4;", "@RunWith(JUnit4.class)", "public class JavaClass {", "  @Test", "  public void testMethod1() {}", "  @Test", "  public void testMethod2() {}", "}");
    File file = new File(psiFile.getVirtualFile().getPath());
    TargetInfo target = TargetIdeInfo.builder().setLabel("//foo:unrelatedName").setKind("java_test").build().toTargetInfo();
    assertThat(new JUnitTestHeuristic().matchesSource(getProject(), target, psiFile, file, null)).isFalse();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) PsiFile(com.intellij.psi.PsiFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) Test(org.junit.Test)

Example 49 with TargetInfo

use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.

the class JUnitTestHeuristicTest method testNullPsiFileDoesNotMatch.

@Test
public void testNullPsiFileDoesNotMatch() {
    File file = new File("foo/script_test.py");
    TargetInfo target = TargetIdeInfo.builder().setLabel("//foo:unrelatedName").setKind("py_test").build().toTargetInfo();
    assertThat(new JUnitTestHeuristic().matchesSource(getProject(), target, null, file, null)).isFalse();
}
Also used : TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) Test(org.junit.Test)

Example 50 with TargetInfo

use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.

the class JUnitTestHeuristicTest method testJunit4SourceDoesNotMatchJunit3TargetName.

@Test
public void testJunit4SourceDoesNotMatchJunit3TargetName() {
    PsiFile psiFile = workspace.createPsiFile(new WorkspacePath("java/com/google/lib/JavaClass.java"), "package com.google.lib;", "import org.junit.Test;", "import org.junit.runner.RunWith;", "import org.junit.runners.JUnit4;", "@RunWith(JUnit4.class)", "public class JavaClass {", "  @Test", "  public void testMethod1() {}", "  @Test", "  public void testMethod2() {}", "}");
    File file = new File(psiFile.getVirtualFile().getPath());
    TargetInfo target = TargetIdeInfo.builder().setLabel("//foo:AllJUnit3Tests").setKind("java_test").build().toTargetInfo();
    assertThat(new JUnitTestHeuristic().matchesSource(getProject(), target, psiFile, file, null)).isFalse();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) PsiFile(com.intellij.psi.PsiFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) Test(org.junit.Test)

Aggregations

TargetInfo (com.google.idea.blaze.base.dependencies.TargetInfo)69 File (java.io.File)43 Test (org.junit.Test)40 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)19 PsiFile (com.intellij.psi.PsiFile)18 Nullable (javax.annotation.Nullable)15 BlazeCommandRunConfigurationCommonState (com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState)14 PsiElement (com.intellij.psi.PsiElement)9 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)7 Label (com.google.idea.blaze.base.model.primitives.Label)7 PsiClass (com.intellij.psi.PsiClass)7 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)6 RuleType (com.google.idea.blaze.base.model.primitives.RuleType)6 BlazeProjectDataManager (com.google.idea.blaze.base.sync.data.BlazeProjectDataManager)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 Truth.assertThat (com.google.common.truth.Truth.assertThat)5 BlazeTestCase (com.google.idea.blaze.base.BlazeTestCase)5 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)5 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)5 TargetMapBuilder (com.google.idea.blaze.base.ideinfo.TargetMapBuilder)5