use of com.intellij.execution.actions.ConfigurationFromContext in project intellij by bazelbuild.
the class BlazeJavaAbstractTestCaseConfigurationProducerTest method testIgnoreTestClassWitNoTestSubclasses.
@Test
public void testIgnoreTestClassWitNoTestSubclasses() {
PsiFile javaFile = createAndIndexFile(new WorkspacePath("java/com/google/test/TestClass.java"), "package com.google.test;", "@org.junit.runner.RunWith(org.junit.runners.JUnit4.class)", "public class TestClass {", " @org.junit.Test", " public void testMethod1() {}", " @org.junit.Test", " public void testMethod2() {}", "}");
PsiClass javaClass = ((PsiClassOwner) javaFile).getClasses()[0];
assertThat(javaClass).isNotNull();
ConfigurationContext context = createContextFromPsi(javaClass);
ConfigurationFromContext fromContext = new BlazeJavaAbstractTestCaseConfigurationProducer().createConfigurationFromContext(context);
assertThat(fromContext).isNull();
}
use of com.intellij.execution.actions.ConfigurationFromContext in project intellij by bazelbuild.
the class MultipleJavaClassesTestConfigurationProducerTest method testProducedFromTestFiles.
@Test
public void testProducedFromTestFiles() {
MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("java_test").setLabel("//java/com/google/test:allTests").addSource(sourceRoot("java/com/google/test/TestClass1.java")).addSource(sourceRoot("java/com/google/test/TestClass2.java")).build()).build());
registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
workspace.createPsiDirectory(new WorkspacePath("java/com/google/test"));
PsiFile testClass1 = createAndIndexFile(new WorkspacePath("java/com/google/test/TestClass1.java"), "package com.google.test;", "@org.junit.runner.RunWith(org.junit.runners.JUnit4.class)", "public class TestClass1 {", " @org.junit.Test", " public void testMethod() {}", "}");
PsiFile testClass2 = createAndIndexFile(new WorkspacePath("java/com/google/test/TestClass2.java"), "package com.google.test;", "@org.junit.runner.RunWith(org.junit.runners.JUnit4.class)", "public class TestClass2 {", " @org.junit.Test", " public void testMethod() {}", "}");
ConfigurationContext context = createContextFromMultipleElements(new PsiElement[] { testClass1, testClass2 });
ConfigurationFromContext fromContext = new MultipleJavaClassesTestConfigurationProducer().createConfigurationFromContext(context);
assertThat(fromContext).isNotNull();
assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
assertThat(config.getTarget()).isEqualTo(TargetExpression.fromStringSafe("//java/com/google/test:allTests"));
assertThat(getTestFilterContents(config)).isEqualTo("--test_filter=com.google.test.TestClass1#|com.google.test.TestClass2#");
assertThat(config.getName()).isEqualTo("Blaze test TestClass1 and 1 others");
assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
use of com.intellij.execution.actions.ConfigurationFromContext in project intellij by bazelbuild.
the class MultipleJavaClassesTestConfigurationProducerTest method testNoFilterIfDirectoryAtPackageRoot.
@Test
public void testNoFilterIfDirectoryAtPackageRoot() {
MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("java_test").setLabel("//java/com/google/test:TestClass").addSource(sourceRoot("java/com/google/test/TestClass.java")).build()).build());
registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
PsiDirectory directory = workspace.createPsiDirectory(new WorkspacePath("java"));
createAndIndexFile(new WorkspacePath("java/com/google/test/TestClass.java"), "package com.google.test;", "@org.junit.runner.RunWith(org.junit.runners.JUnit4.class)", "public class TestClass {", " @org.junit.Test", " public void testMethod() {}", "}");
ConfigurationContext context = createContextFromPsi(directory);
List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
assertThat(configurations).hasSize(1);
ConfigurationFromContext fromContext = configurations.get(0);
assertThat(fromContext.isProducedBy(MultipleJavaClassesTestConfigurationProducer.class)).isTrue();
assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
assertThat(getTestFilterContents(config)).isNull();
assertThat(config.getName()).isEqualTo("Blaze test test:TestClass");
assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
use of com.intellij.execution.actions.ConfigurationFromContext in project intellij by bazelbuild.
the class MultipleJavaClassesTestConfigurationProducerTest method testNotProducedFromNonTestFiles.
@Test
public void testNotProducedFromNonTestFiles() {
MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("java_test").setLabel("//java/com/google/test:allTests").addSource(sourceRoot("java/com/google/test/NonTestClass1.java")).addSource(sourceRoot("java/com/google/test/NonTestClass2.java")).build()).build());
registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
workspace.createPsiDirectory(new WorkspacePath("java/com/google/test"));
PsiFile testClass1 = createAndIndexFile(new WorkspacePath("java/com/google/test/NonTestClass1.java"), "package com.google.test;", "public class NonTestClass1 {");
PsiFile testClass2 = createAndIndexFile(new WorkspacePath("java/com/google/test/NonTestClass2.java"), "package com.google.test;", "public class NonTestClass2 {}");
ConfigurationContext context = createContextFromMultipleElements(new PsiElement[] { testClass1, testClass2 });
ConfigurationFromContext fromContext = new MultipleJavaClassesTestConfigurationProducer().createConfigurationFromContext(context);
assertThat(fromContext).isNull();
}
use of com.intellij.execution.actions.ConfigurationFromContext in project intellij by bazelbuild.
the class AllInPackageBlazeConfigurationProducerTest method testProducedFromPsiDirectory.
@Test
public void testProducedFromPsiDirectory() {
PsiDirectory directory = workspace.createPsiDirectory(new WorkspacePath("java/com/google/test"));
workspace.createPsiFile(new WorkspacePath("java/com/google/test/BUILD"), "java_test(name='unit_tests'");
ConfigurationContext context = createContextFromPsi(directory);
List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
assertThat(configurations).hasSize(1);
ConfigurationFromContext fromContext = configurations.get(0);
assertThat(fromContext.isProducedBy(AllInPackageBlazeConfigurationProducer.class)).isTrue();
assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
assertThat(config.getTarget()).isEqualTo(TargetExpression.fromStringSafe("//java/com/google/test/...:all"));
assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
Aggregations