Search in sources :

Example 36 with MockBlazeProjectDataManager

use of com.google.idea.blaze.base.model.MockBlazeProjectDataManager in project intellij by bazelbuild.

the class BuildFileIntegrationTestCase method doSetup.

@Before
public final void doSetup() {
    BlazeProjectDataManager mockProjectDataManager = new MockBlazeProjectDataManager(MockBlazeProjectDataBuilder.builder(workspaceRoot).setOutputBase(fileSystem.getRootDir() + "/output_base").build());
    registerProjectService(BlazeProjectDataManager.class, mockProjectDataManager);
    editorTest = new EditorTestHelper(getProject(), testFixture);
}
Also used : EditorTestHelper(com.google.idea.blaze.base.EditorTestHelper) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) Before(org.junit.Before)

Example 37 with MockBlazeProjectDataManager

use of com.google.idea.blaze.base.model.MockBlazeProjectDataManager in project intellij by bazelbuild.

the class BlazeJavaAbstractTestCaseConfigurationProducerTest method testConfigurationCreatedFromMethodInAbstractClass.

@Test
public void testConfigurationCreatedFromMethodInAbstractClass() {
    PsiFile abstractClassFile = createAndIndexFile(new WorkspacePath("java/com/google/test/AbstractTestCase.java"), "package com.google.test;", "public abstract class AbstractTestCase {", "  @org.junit.Test", "  public void testMethod() {}", "}");
    createAndIndexFile(new WorkspacePath("java/com/google/test/TestClass.java"), "package com.google.test;", "import com.google.test.AbstractTestCase;", "import org.junit.runner.RunWith;", "import org.junit.runners.JUnit4;", "@org.junit.runner.RunWith(org.junit.runners.JUnit4.class)", "public class TestClass extends AbstractTestCase {}");
    PsiClass javaClass = ((PsiClassOwner) abstractClassFile).getClasses()[0];
    PsiMethod method = PsiUtils.findFirstChildOfClassRecursive(javaClass, PsiMethod.class);
    assertThat(method).isNotNull();
    ConfigurationContext context = createContextFromPsi(method);
    List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
    assertThat(configurations).hasSize(1);
    ConfigurationFromContext fromContext = configurations.get(0);
    assertThat(fromContext.isProducedBy(BlazeJavaAbstractTestCaseConfigurationProducer.class)).isTrue();
    assertThat(fromContext.getSourceElement()).isEqualTo(method);
    RunConfiguration config = fromContext.getConfiguration();
    assertThat(config).isInstanceOf(BlazeCommandRunConfiguration.class);
    BlazeCommandRunConfiguration blazeConfig = (BlazeCommandRunConfiguration) config;
    assertThat(blazeConfig.getTarget()).isNull();
    assertThat(blazeConfig.getName()).isEqualTo("Choose subclass for AbstractTestCase.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()));
    BlazeJavaAbstractTestCaseConfigurationProducer.chooseSubclass(fromContext, context, EmptyRunnable.INSTANCE);
    assertThat(blazeConfig.getTarget()).isEqualTo(TargetExpression.fromStringSafe("//java/com/google/test:TestClass"));
    assertThat(getTestFilterContents(blazeConfig)).isEqualTo(BlazeFlags.TEST_FILTER + "=com.google.test.TestClass#testMethod$");
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) PsiMethod(com.intellij.psi.PsiMethod) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) PsiClass(com.intellij.psi.PsiClass) PsiFile(com.intellij.psi.PsiFile) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) Test(org.junit.Test)

Example 38 with MockBlazeProjectDataManager

use of com.google.idea.blaze.base.model.MockBlazeProjectDataManager in project intellij by bazelbuild.

the class BlazeJavaMainClassConfigurationProducerTest method testNoResultForClassWithoutMainMethod.

@Test
public void testNoResultForClassWithoutMainMethod() {
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
    builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("java_binary").setLabel("//com/google/binary:MainClass").addSource(sourceRoot("com/google/binary/MainClass.java")).setJavaInfo(JavaIdeInfo.builder().setMainClass("com.google.binary.MainClass")).build()).build());
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
    PsiFile javaClass = createAndIndexFile(WorkspacePath.createIfValid("com/google/binary/MainClass.java"), "package com.google.binary;", "public class MainClass {}");
    assertThat(createConfigurationFromLocation(javaClass)).isNull();
}
Also used : MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) PsiFile(com.intellij.psi.PsiFile) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) Test(org.junit.Test)

Example 39 with MockBlazeProjectDataManager

use of com.google.idea.blaze.base.model.MockBlazeProjectDataManager in project intellij by bazelbuild.

the class BlazeJavaMainClassConfigurationProducerTest method testUniqueJavaBinaryChosen.

@Test
public void testUniqueJavaBinaryChosen() {
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
    builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("java_binary").setLabel("//com/google/binary:UnrelatedName").addSource(sourceRoot("com/google/binary/MainClass.java")).build()).build());
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
    PsiFile javaClass = createAndIndexFile(WorkspacePath.createIfValid("com/google/binary/MainClass.java"), "package com.google.binary;", "import java.lang.String;", "public class MainClass {", "  public static void main(java.lang.String[] args) {}", "}");
    RunConfiguration config = createConfigurationFromLocation(javaClass);
    assertThat(config).isInstanceOf(BlazeRunConfiguration.class);
    BlazeRunConfiguration blazeConfig = (BlazeRunConfiguration) config;
    assertThat(blazeConfig.getTarget()).isEqualTo(TargetExpression.fromStringSafe("//com/google/binary:UnrelatedName"));
}
Also used : BlazeRunConfiguration(com.google.idea.blaze.base.run.BlazeRunConfiguration) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) BlazeRunConfiguration(com.google.idea.blaze.base.run.BlazeRunConfiguration) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) PsiFile(com.intellij.psi.PsiFile) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) Test(org.junit.Test)

Example 40 with MockBlazeProjectDataManager

use of com.google.idea.blaze.base.model.MockBlazeProjectDataManager in project intellij by bazelbuild.

the class BlazeJavaMainClassConfigurationProducerTest method testNoJavaBinaryChosenIfNotInRDeps.

@Test
public void testNoJavaBinaryChosenIfNotInRDeps() {
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
    builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("java_binary").setLabel("//com/google/binary:MainClass").addSource(sourceRoot("com/google/binary/OtherClass.java")).build()).build());
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
    PsiFile javaClass = createAndIndexFile(WorkspacePath.createIfValid("com/google/binary/MainClass.java"), "package com.google.binary;", "import java.lang.String;", "public class MainClass {", "  public static void main(java.lang.String[] args) {}", "}");
    assertThat(createConfigurationFromLocation(javaClass)).isNotInstanceOf(BlazeRunConfiguration.class);
}
Also used : MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) PsiFile(com.intellij.psi.PsiFile) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) Test(org.junit.Test)

Aggregations

MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)68 Test (org.junit.Test)48 MockBlazeProjectDataBuilder (com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder)43 PsiFile (com.intellij.psi.PsiFile)37 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)34 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)27 BlazeCommandRunConfiguration (com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)23 ConfigurationFromContext (com.intellij.execution.actions.ConfigurationFromContext)21 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)14 Before (org.junit.Before)14 BlazeProjectDataManager (com.google.idea.blaze.base.sync.data.BlazeProjectDataManager)13 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)10 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)9 BlazeRunConfiguration (com.google.idea.blaze.base.run.BlazeRunConfiguration)8 PsiClass (com.intellij.psi.PsiClass)7 WorkspaceLanguageSettings (com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings)6 WorkspacePathResolverImpl (com.google.idea.blaze.base.sync.workspace.WorkspacePathResolverImpl)5 PsiDirectory (com.intellij.psi.PsiDirectory)5 GoFile (com.goide.psi.GoFile)4 EditorTestHelper (com.google.idea.blaze.base.EditorTestHelper)4