use of com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder in project intellij by bazelbuild.
the class BlazeKotlinRunConfigureProducerTest method testMainClassInterpretedCorrectly.
@Test
public void testMainClassInterpretedCorrectly() {
MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("kt_jvm_binary").setJavaInfo(JavaIdeInfo.builder().setMainClass("com.google.binary.Main")).setLabel("//com/google/binary:just_main").addSource(sourceRoot("com/google/binary/JustMain.kt")).build()).build());
registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
PsiFile justMainFile = createAndIndexFile(WorkspacePath.createIfValid("com/google/binary/JustMain.kt"), "@file:JvmName(\"Main\")", "package com.google.binary", "fun main(args: Array<String>) {}");
RunConfiguration justMainRunConfig = createConfigurationFromLocation(justMainFile);
assertThat(justMainRunConfig).isInstanceOf(BlazeRunConfiguration.class);
}
use of com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder in project intellij by bazelbuild.
the class BlazePyTestConfigurationProducerTest method testProducedFromTestCase.
@Test
public void testProducedFromTestCase() {
PsiFile pyFile = createAndIndexFile(new WorkspacePath("py/test/unittest.py"), "class UnitTest(googletest.TestCase):", " def testSomething():", " return");
MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("py_test").setLabel("//py/test:unittests").addSource(sourceRoot("py/test/unittest.py")).build()).build());
registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
PyFunction function = PsiUtils.findFirstChildOfClassRecursive(pyFile, PyFunction.class);
assertThat(function).isNotNull();
ConfigurationContext context = createContextFromPsi(function);
List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
assertThat(configurations).hasSize(1);
ConfigurationFromContext fromContext = configurations.get(0);
assertThat(fromContext.isProducedBy(BlazePyTestConfigurationProducer.class)).isTrue();
assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
assertThat(config.getTarget()).isEqualTo(TargetExpression.fromStringSafe("//py/test:unittests"));
assertThat(getTestFilterContents(config)).isEqualTo("--test_filter=UnitTest.testSomething");
assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
use of com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder in project intellij by bazelbuild.
the class BlazePyTestConfigurationProducerTest method testProducedFromPyClass.
@Test
public void testProducedFromPyClass() {
PsiFile pyFile = createAndIndexFile(new WorkspacePath("py/test/unittest.py"), "class UnitTest(googletest.TestCase):", " def testSomething():", " return");
MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("py_test").setLabel("//py/test:unittests").addSource(sourceRoot("py/test/unittest.py")).build()).build());
registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
PyClass pyClass = PsiUtils.findFirstChildOfClassRecursive(pyFile, PyClass.class);
assertThat(pyClass).isNotNull();
ConfigurationContext context = createContextFromPsi(pyClass);
List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
assertThat(configurations).hasSize(1);
ConfigurationFromContext fromContext = configurations.get(0);
assertThat(fromContext.isProducedBy(BlazePyTestConfigurationProducer.class)).isTrue();
assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
assertThat(config.getTarget()).isEqualTo(TargetExpression.fromStringSafe("//py/test:unittests"));
assertThat(getTestFilterContents(config)).isEqualTo("--test_filter=UnitTest");
assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
use of com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder 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$");
}
use of com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder 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();
}
Aggregations