use of com.google.idea.blaze.base.run.producers.TestContextRunConfigurationProducer in project intellij by bazelbuild.
the class BlazeJavaTestClassConfigurationProducerTest method testConfigWithDifferentLabelIgnored.
@Test
public void testConfigWithDifferentLabelIgnored() 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 class TestClass {", " @org.junit.Test", " public void testMethod() {}", "}");
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()));
ConfigurationContext context = createContextFromPsi(javaFile);
BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) context.getConfiguration().getConfiguration();
assertThat(config).isNotNull();
// modify the label, and check that is enough for the producer to class it as different.
config.setTarget(Label.create("//java/com/google/test:TestClass2"));
assertThat(new TestContextRunConfigurationProducer().doIsConfigFromContext(config, context)).isFalse();
}
use of com.google.idea.blaze.base.run.producers.TestContextRunConfigurationProducer in project intellij by bazelbuild.
the class BlazeJavaTestClassConfigurationProducerTest method testConfigWithDifferentFilterIgnored.
@Test
public void testConfigWithDifferentFilterIgnored() 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 class TestClass {", " @org.junit.Test", " public void testMethod() {}", "}");
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()));
ConfigurationContext context = createContextFromPsi(javaFile);
BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) context.getConfiguration().getConfiguration();
BlazeCommandRunConfigurationCommonState handlerState = config.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
// modify the test filter, and check that is enough for the producer to class it as different.
List<String> flags = new ArrayList<>(handlerState.getBlazeFlagsState().getRawFlags());
flags.removeIf((flag) -> flag.startsWith(BlazeFlags.TEST_FILTER));
flags.add(BlazeFlags.TEST_FILTER + "=com.google.test.OtherTestClass#");
handlerState.getBlazeFlagsState().setRawFlags(flags);
assertThat(new TestContextRunConfigurationProducer().doIsConfigFromContext(config, context)).isFalse();
}
use of com.google.idea.blaze.base.run.producers.TestContextRunConfigurationProducer in project intellij by bazelbuild.
the class MultipleJavaClassesTestContextProviderTest method testProducedFromTestFiles.
@Test
public void testProducedFromTestFiles() throws Throwable {
// GIVEN two test classes
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() {}", "}");
// WHEN generating a BlazeCommandRunConfiguration
ConfigurationContext context = createContextFromMultipleElements(new PsiElement[] { testClass1, testClass2 });
ConfigurationFromContext fromContext = new TestContextRunConfigurationProducer().createConfigurationFromContext(context);
assertThat(fromContext).isNotNull();
assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
// THEN expect config to be correct
assertThat(config.getTargets()).containsExactly(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("Bazel test TestClass1 and 1 others");
assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
use of com.google.idea.blaze.base.run.producers.TestContextRunConfigurationProducer in project intellij by bazelbuild.
the class MultipleJavaClassesTestContextProviderTest method testNotProducedFromTestFilesInDifferentTestTargets.
@Test
public void testNotProducedFromTestFilesInDifferentTestTargets() throws Throwable {
MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("java_test").setLabel("//java/com/google/test:TestClass1").addSource(sourceRoot("java/com/google/test/TestClass1.java")).build()).addTarget(TargetIdeInfo.builder().setKind("java_test").setLabel("//java/com/google/test:TestClass2").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"));
PsiJavaFile testClass1 = (PsiJavaFile) 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() {}", "}");
PsiJavaFile testClass2 = (PsiJavaFile) 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.getClasses()[0], testClass2.getClasses()[0] });
assertThat(new TestContextRunConfigurationProducer().createConfigurationFromContext(context)).isNull();
}
use of com.google.idea.blaze.base.run.producers.TestContextRunConfigurationProducer in project intellij by bazelbuild.
the class MultipleJavaClassesTestContextProviderTest method testNotProducedForDirectoryNotUnderTestRoots.
@Test
public void testNotProducedForDirectoryNotUnderTestRoots() throws Throwable {
MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("java_test").setLabel("//java/com/google/other:TestClass").addSource(sourceRoot("java/com/google/other/TestClass.java")).build()).build());
registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
PsiDirectory directory = workspace.createPsiDirectory(new WorkspacePath("java"));
createAndIndexFile(new WorkspacePath("java/com/google/other/TestClass.java"), "package com.google.other;", "@org.junit.runner.RunWith(org.junit.runners.JUnit4.class)", "public class TestClass {", " @org.junit.Test", " public void testMethod() {}", "}");
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/...:all"));
assertThat(getTestFilterContents(config)).isNull();
}
Aggregations