use of com.intellij.execution.actions.ConfigurationFromContext in project intellij by bazelbuild.
the class BlazeJavaTestClassConfigurationProducerTest method testProducedFromPsiClassWithInnerTestClass.
@Test
public void testProducedFromPsiClassWithInnerTestClass() throws Throwable {
PsiFile javaFile = createAndIndexFile(new WorkspacePath("java/com/google/test/OuterClass.java"), "package com.google.test;", "@org.junit.runner.RunWith(org.junit.runners.Suite.class)", "@org.junit.runners.Suite.SuiteClasses({OuterClass.InnerClass.class})", "public class OuterClass {", " @org.junit.runner.RunWith(org.junit.runners.JUnit4.class)", " public static class InnerClass {", " @org.junit.Test", " public void testMethod1() {}", " @org.junit.Test", " public void testMethod2() {}", " }", "}");
MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("java_test").setLabel("//java/com/google/test:OuterClass").addSource(sourceRoot("java/com/google/test/OuterClass.java")).build()).build());
registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
PsiClass javaClass = ((PsiClassOwner) javaFile).getClasses()[0];
assertThat(javaClass).isNotNull();
ConfigurationContext context = createContextFromPsi(javaClass);
List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
assertThat(configurations).hasSize(1);
ConfigurationFromContext fromContext = configurations.get(0);
assertThat(fromContext.isProducedBy(TestContextRunConfigurationProducer.class)).isTrue();
assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
assertThat(config.getTargets()).containsExactly(TargetExpression.fromStringSafe("//java/com/google/test:OuterClass"));
assertThat(getTestFilterContents(config)).isEqualTo("--test_filter=\"com.google.test.OuterClass#|com.google.test.OuterClass.InnerClass#\"");
assertThat(config.getName()).isEqualTo("Blaze test OuterClass");
assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
use of com.intellij.execution.actions.ConfigurationFromContext in project intellij by bazelbuild.
the class MultipleJavaClassesTestContextProviderTest method testNotProducedFromDirectoryWithoutTests.
@Test
public void testNotProducedFromDirectoryWithoutTests() {
MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("java_binary").setLabel("//java/com/google/other:BinaryClass").addSource(sourceRoot("java/com/google/other/BinaryClass.java")).build()).build());
registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
PsiDirectory directory = workspace.createPsiDirectory(new WorkspacePath("java/com/other"));
ConfigurationContext context = createContextFromPsi(directory);
ConfigurationFromContext fromContext = new TestContextRunConfigurationProducer().createConfigurationFromContext(context);
assertThat(fromContext).isNotNull();
assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
assertThat(config.getTargets()).containsExactly(TargetExpression.fromStringSafe("//java/com/other/...:all"));
assertThat(getTestFilterContents(config)).isNull();
}
use of com.intellij.execution.actions.ConfigurationFromContext in project intellij by bazelbuild.
the class MultipleJavaClassesTestContextProviderTest method testProducedFromDirectoryWithNestedTests.
@Test
public void testProducedFromDirectoryWithNestedTests() throws Throwable {
MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("java_test").setLabel("//java/com/google/test/sub:TestClass").addSource(sourceRoot("java/com/google/test/sub/TestClass.java")).build()).build());
registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
PsiDirectory directory = workspace.createPsiDirectory(new WorkspacePath("java/com/google/test"));
createAndIndexFile(new WorkspacePath("java/com/google/test/sub/TestClass.java"), "package com.google.test.sub;", "@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(TestContextRunConfigurationProducer.class)).isTrue();
assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
assertThat(config.getTargets()).containsExactly(TargetExpression.fromStringSafe("//java/com/google/test/sub:TestClass"));
assertThat(getTestFilterContents(config)).isEqualTo("--test_filter=com.google.test");
assertThat(config.getName()).isEqualTo("Blaze test all in directory 'test'");
assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
use of com.intellij.execution.actions.ConfigurationFromContext in project intellij by bazelbuild.
the class BlazeJavaAbstractTestCaseConfigurationProducerTest method testIgnoreAbstractTestClassWithNoTestSubclasses.
@Test
public void testIgnoreAbstractTestClassWithNoTestSubclasses() throws Throwable {
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 abstract 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 BlazeJavaAbstractTestCaseConfigurationProducerTest method testHandlesNonAbstractClassWithTestSubclass.
@Test
public void testHandlesNonAbstractClassWithTestSubclass() throws Throwable {
workspace.createPsiDirectory(new WorkspacePath("java/com/google/test"));
PsiFile superClassFile = createAndIndexFile(new WorkspacePath("java/com/google/test/NonAbstractSuperClassTestCase.java"), "package com.google.test;", "@org.junit.runner.RunWith(org.junit.runners.JUnit4.class)", "public class NonAbstractSuperClassTestCase {", " @org.junit.Test", " public void testMethod() {}", "}");
createAndIndexFile(new WorkspacePath("java/com/google/test/TestClass.java"), "package com.google.test;", "import com.google.test.NonAbstractSuperClassTestCase;", "@org.junit.runner.RunWith(org.junit.runners.JUnit4.class)", "public class TestClass extends NonAbstractSuperClassTestCase {", " @org.junit.Test", " public void anotherTestMethod() {}", "}");
PsiClass javaClass = ((PsiClassOwner) superClassFile).getClasses()[0];
assertThat(javaClass).isNotNull();
ConfigurationContext context = createContextFromPsi(superClassFile);
List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
assertThat(configurations).hasSize(1);
ConfigurationFromContext fromContext = configurations.get(0);
assertThat(fromContext.isProducedBy(BlazeJavaAbstractTestCaseConfigurationProducer.class)).isTrue();
assertThat(fromContext.getSourceElement()).isEqualTo(javaClass);
RunConfiguration config = fromContext.getConfiguration();
assertThat(config).isInstanceOf(BlazeCommandRunConfiguration.class);
BlazeCommandRunConfiguration blazeConfig = (BlazeCommandRunConfiguration) config;
assertThat(blazeConfig.getTargets()).isEmpty();
assertThat(blazeConfig.getName()).isEqualTo("Choose subclass for NonAbstractSuperClassTestCase");
}
Aggregations