Search in sources :

Example 6 with TestContextRunConfigurationProducer

use of com.google.idea.blaze.base.run.producers.TestContextRunConfigurationProducer 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();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) PsiDirectory(com.intellij.psi.PsiDirectory) TestContextRunConfigurationProducer(com.google.idea.blaze.base.run.producers.TestContextRunConfigurationProducer) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Example 7 with TestContextRunConfigurationProducer

use of com.google.idea.blaze.base.run.producers.TestContextRunConfigurationProducer in project intellij by bazelbuild.

the class BlazeJavaTestClassConfigurationProducerTest method testConfigFromContextRecognizesItsOwnConfig.

@Test
public void testConfigFromContextRecognizesItsOwnConfig() 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();
    assertThat(new TestContextRunConfigurationProducer().doIsConfigFromContext(config, context)).isTrue();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) TestContextRunConfigurationProducer(com.google.idea.blaze.base.run.producers.TestContextRunConfigurationProducer) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) PsiFile(com.intellij.psi.PsiFile) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Example 8 with TestContextRunConfigurationProducer

use of com.google.idea.blaze.base.run.producers.TestContextRunConfigurationProducer in project intellij by bazelbuild.

the class BlazeJavaTestMethodConfigurationProducerTest method testConfigFromContextRecognizesItsOwnConfig.

@Test
public void testConfigFromContextRecognizesItsOwnConfig() throws Throwable {
    PsiMethod method = setupGenericJunitTestClassAndBlazeTarget();
    ConfigurationContext context = createContextFromPsi(method);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) context.getConfiguration().getConfiguration();
    boolean isConfigFromContext = new TestContextRunConfigurationProducer().doIsConfigFromContext(config, context);
    assertThat(isConfigFromContext).isTrue();
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) PsiMethod(com.intellij.psi.PsiMethod) TestContextRunConfigurationProducer(com.google.idea.blaze.base.run.producers.TestContextRunConfigurationProducer) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Example 9 with TestContextRunConfigurationProducer

use of com.google.idea.blaze.base.run.producers.TestContextRunConfigurationProducer in project intellij by bazelbuild.

the class BlazeJavaTestMethodConfigurationProducerTest method testConfigWithDifferentFilterIgnored.

@Test
public void testConfigWithDifferentFilterIgnored() throws Throwable {
    // Arrange
    PsiMethod method = setupGenericJunitTestClassAndBlazeTarget();
    ConfigurationContext context = createContextFromPsi(method);
    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.DifferentTestClass#");
    handlerState.getBlazeFlagsState().setRawFlags(flags);
    // Act
    boolean isConfigFromContext = new TestContextRunConfigurationProducer().doIsConfigFromContext(config, context);
    // Assert
    assertThat(isConfigFromContext).isFalse();
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) PsiMethod(com.intellij.psi.PsiMethod) TestContextRunConfigurationProducer(com.google.idea.blaze.base.run.producers.TestContextRunConfigurationProducer) ArrayList(java.util.ArrayList) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Example 10 with TestContextRunConfigurationProducer

use of com.google.idea.blaze.base.run.producers.TestContextRunConfigurationProducer in project intellij by bazelbuild.

the class BlazeJavaTestMethodConfigurationProducerTest method testConfigWithDifferentLabelIsIgnored.

@Test
public void testConfigWithDifferentLabelIsIgnored() throws Throwable {
    // Arrange
    PsiMethod method = setupGenericJunitTestClassAndBlazeTarget();
    ConfigurationContext context = createContextFromPsi(method);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) context.getConfiguration().getConfiguration();
    // modify the label, and check that is enough for the producer to class it as different.
    config.setTarget(Label.create("//java/com/google/test:DifferentTestTarget"));
    // Act
    boolean isConfigFromContext = new TestContextRunConfigurationProducer().doIsConfigFromContext(config, context);
    // Assert
    assertThat(isConfigFromContext).isFalse();
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) PsiMethod(com.intellij.psi.PsiMethod) TestContextRunConfigurationProducer(com.google.idea.blaze.base.run.producers.TestContextRunConfigurationProducer) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Aggregations

TestContextRunConfigurationProducer (com.google.idea.blaze.base.run.producers.TestContextRunConfigurationProducer)11 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)11 Test (org.junit.Test)11 BlazeCommandRunConfiguration (com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)9 MockBlazeProjectDataBuilder (com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder)8 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)8 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)8 PsiFile (com.intellij.psi.PsiFile)5 ConfigurationFromContext (com.intellij.execution.actions.ConfigurationFromContext)4 PsiMethod (com.intellij.psi.PsiMethod)3 BlazeCommandRunConfigurationCommonState (com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState)2 PsiDirectory (com.intellij.psi.PsiDirectory)2 ArrayList (java.util.ArrayList)2 PsiJavaFile (com.intellij.psi.PsiJavaFile)1