use of com.google.idea.blaze.base.model.MockBlazeProjectDataManager in project intellij by bazelbuild.
the class BlazeJavaMainClassConfigurationProducerTest method testJavaBinaryWithMatchingNameChosen.
@Test
public void testJavaBinaryWithMatchingNameChosen() {
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()).addTarget(TargetIdeInfo.builder().setKind("java_binary").setLabel("//com/google/binary:MainClass").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:MainClass"));
}
use of com.google.idea.blaze.base.model.MockBlazeProjectDataManager in project intellij by bazelbuild.
the class BlazeJavaTestClassConfigurationProducerTest method testConfigFromContextRecognizesItsOwnConfig.
@Test
public void testConfigFromContextRecognizesItsOwnConfig() {
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 BlazeJavaTestClassConfigurationProducer().doIsConfigFromContext(config, context)).isTrue();
}
use of com.google.idea.blaze.base.model.MockBlazeProjectDataManager in project intellij by bazelbuild.
the class BlazeJavaTestClassConfigurationProducerTest method testProducedFromPsiFile.
@Test
public void testProducedFromPsiFile() {
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 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:TestClass").addSource(sourceRoot("java/com/google/test/TestClass.java")).build()).build());
registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
ConfigurationContext context = createContextFromPsi(javaFile);
List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
assertThat(configurations).hasSize(1);
ConfigurationFromContext fromContext = configurations.get(0);
assertThat(fromContext.isProducedBy(BlazeJavaTestClassConfigurationProducer.class)).isTrue();
assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
assertThat(config.getTarget()).isEqualTo(TargetExpression.fromStringSafe("//java/com/google/test:TestClass"));
assertThat(getTestFilterContents(config)).isEqualTo("--test_filter=com.google.test.TestClass#");
assertThat(config.getName()).isEqualTo("Blaze test TestClass");
assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
use of com.google.idea.blaze.base.model.MockBlazeProjectDataManager in project intellij by bazelbuild.
the class BlazeJavaTestClassConfigurationProducerTest method testProducedFromPsiClass.
@Test
public void testProducedFromPsiClass() {
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 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:TestClass").addSource(sourceRoot("java/com/google/test/TestClass.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(BlazeJavaTestClassConfigurationProducer.class)).isTrue();
assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
assertThat(config.getTarget()).isEqualTo(TargetExpression.fromStringSafe("//java/com/google/test:TestClass"));
assertThat(getTestFilterContents(config)).isEqualTo("--test_filter=com.google.test.TestClass#");
assertThat(config.getName()).isEqualTo("Blaze test TestClass");
assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
use of com.google.idea.blaze.base.model.MockBlazeProjectDataManager in project intellij by bazelbuild.
the class BlazeJavaTestMethodConfigurationProducerTest method setupGenericJunitTestClassAndBlazeTarget.
/**
* Creates a JUnit test class and associated blaze target, and returns a PsiMethod from that
* class. Used when the implementation details (class name, target string, etc.) aren't relevant
* to the test.
*/
private PsiMethod setupGenericJunitTestClassAndBlazeTarget() {
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 testMethod1() {}", "}");
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()));
return PsiUtils.findFirstChildOfClassRecursive(javaFile, PsiMethod.class);
}
Aggregations