use of org.junit.runner.RunWith in project intellij by bazelbuild.
the class BlazeScalaTestRunLineMarkerContributorTest method testGetSpecs2TestInfo.
@Test
public void testGetSpecs2TestInfo() {
createAndIndexFile(WorkspacePath.createIfValid("scala/org/junit/runner/RunWith.scala"), "package org.junit.runner", "class RunWith");
createAndIndexFile(WorkspacePath.createIfValid("src/test/scala/org/specs2/runner/JUnitRunner.scala"), "package org.specs2.runner", "class JUnitRunner");
createAndIndexFile(WorkspacePath.createIfValid("src/test/scala/org/specs2/mutable/SpecificationWithJUnit.scala"), "package org.specs2.mutable", "@org.junit.runner.RunWith(classOf[org.specs2.runner.JUnitRunner])", "abstract class SpecificationWithJUnit extends org.specs2.mutable.Specification");
createAndIndexFile(WorkspacePath.createIfValid("src/test/scala/org/specs2/mutable/Specification.scala"), "package org.specs2.mutable", "abstract class Specification extends org.specs2.mutable.SpecificationLike");
createAndIndexFile(WorkspacePath.createIfValid("src/test/scala/org/specs2/mutable/SpecificationLike.scala"), "package org.specs2.mutable", "trait SpecificationLike extends", "org.specs2.specification.core.mutable.SpecificationStructure");
createAndIndexFile(WorkspacePath.createIfValid("src/test/scala/org/specs2/specification/core/mutable/SpecificationStructure.scala"), "package org.specs2.specification.core.mutable", "trait SpecificationStructure extends", "org.specs2.specification.core.SpecificationStructure");
createAndIndexFile(WorkspacePath.createIfValid("src/test/scala/org/specs2/specification/core/SpecificationStructure.scala"), "package org.specs2.specification.core", "trait SpecificationStructure");
PsiFile specs2TestFile = createAndIndexFile(WorkspacePath.createIfValid("src/test/scala/com/google/test/Specs2Test.scala"), "package com.google.test", "class Specs2Test extends org.specs2.mutable.SpecificationWithJUnit");
List<LeafPsiElement> elements = PsiUtils.findAllChildrenOfClassRecursive(specs2TestFile, LeafPsiElement.class);
LeafPsiElement classIdentifier = elements.stream().filter(e -> Objects.equal(e.getText(), "Specs2Test")).findFirst().orElse(null);
assertThat(classIdentifier).isNotNull();
Info info = markerContributor.getInfo(classIdentifier);
assertThat(info).isNotNull();
assertThat(info.icon).isEqualTo(AllIcons.RunConfigurations.TestState.Run_run);
assertThat(info.actions).hasLength(2);
assertThat(info.actions[0].getTemplatePresentation().getText()).startsWith("Run ");
assertThat(info.actions[1].getTemplatePresentation().getText()).startsWith("Debug ");
elements.stream().filter(e -> !Objects.equal(e, classIdentifier)).forEach(e -> assertThat(markerContributor.getInfo(e)).isNull());
}
use of org.junit.runner.RunWith in project hbase by apache.
the class HBaseClassTestRule method getNumParameters.
/**
* @param clazz Test class that is running.
* @return the number of parameters for this given test class. If the test is not parameterized or
* if there is any issue determining the number of parameters, returns 1.
*/
static int getNumParameters(Class<?> clazz) {
RunWith[] runWiths = clazz.getAnnotationsByType(RunWith.class);
boolean testParameterized = runWiths != null && Arrays.stream(runWiths).anyMatch((r) -> r.value().equals(Parameterized.class));
if (!testParameterized) {
return 1;
}
for (Method method : clazz.getMethods()) {
if (!isParametersMethod(method)) {
continue;
}
// Found the parameters method. Figure out the number of parameters.
Object parameters;
try {
parameters = method.invoke(clazz);
} catch (IllegalAccessException | InvocationTargetException e) {
LOG.warn("Error invoking parameters method {} in test class {}", method.getName(), clazz, e);
continue;
}
if (parameters instanceof List) {
return ((List) parameters).size();
} else if (parameters instanceof Collection) {
return ((Collection) parameters).size();
} else if (parameters instanceof Iterable) {
return Iterables.size((Iterable) parameters);
} else if (parameters instanceof Object[]) {
return ((Object[]) parameters).length;
}
}
LOG.warn("Unable to determine parameters size. Returning the default of 1.");
return 1;
}
Aggregations