本文整理汇总了Java中com.intellij.execution.junit.JUnitUtil类的典型用法代码示例。如果您正苦于以下问题:Java JUnitUtil类的具体用法?Java JUnitUtil怎么用?Java JUnitUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JUnitUtil类属于com.intellij.execution.junit包,在下文中一共展示了JUnitUtil类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getParameterizedLocation
import com.intellij.execution.junit.JUnitUtil; //导入依赖的package包/类
public static Location getParameterizedLocation(PsiClass psiClass,
String paramSetName,
String parameterizedClassName) {
final PsiAnnotation annotation = AnnotationUtil.findAnnotationInHierarchy(psiClass, Collections.singleton(JUnitUtil.RUN_WITH));
if (annotation != null) {
final PsiAnnotationMemberValue attributeValue = annotation.findAttributeValue("value");
if (attributeValue instanceof PsiClassObjectAccessExpression) {
final PsiTypeElement operand = ((PsiClassObjectAccessExpression)attributeValue).getOperand();
if (InheritanceUtil.isInheritor(operand.getType(), parameterizedClassName)) {
return new PsiMemberParameterizedLocation(psiClass.getProject(),
psiClass,
null,
paramSetName);
}
}
}
return null;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:PsiMemberParameterizedLocation.java
示例2: showDialog
import com.intellij.execution.junit.JUnitUtil; //导入依赖的package包/类
@Override
protected String showDialog() {
final String className = myClassComponent.getComponent().getText();
if (className.trim().length() == 0) {
Messages.showMessageDialog(getField(), ExecutionBundle.message("set.class.name.message"),
ExecutionBundle.message("cannot.browse.method.dialog.title"), Messages.getInformationIcon());
return null;
}
final PsiClass testClass = myModuleSelector.findClass(className);
if (testClass == null) {
Messages.showMessageDialog(getField(), ExecutionBundle.message("class.does.not.exists.error.message", className),
ExecutionBundle.message("cannot.browse.method.dialog.title"), Messages.getInformationIcon());
return null;
}
final MethodListDlg dialog = new MethodListDlg(testClass, new JUnitUtil.TestMethodFilter(testClass), getField());
if (dialog.showAndGet()) {
final PsiMethod method = dialog.getSelected();
if (method != null) {
return method.getName();
}
}
return null;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:TestRunParameters.java
示例3: setupClassConfiguration
import com.intellij.execution.junit.JUnitUtil; //导入依赖的package包/类
private boolean setupClassConfiguration(AndroidTestRunConfiguration configuration,
PsiElement element,
ConfigurationContext context,
Ref<PsiElement> sourceElement) {
PsiClass elementClass = PsiTreeUtil.getParentOfType(element, PsiClass.class, false);
while (elementClass != null) {
if (JUnitUtil.isTestClass(elementClass)) {
setupConfiguration(configuration, elementClass, context, sourceElement);
configuration.TESTING_TYPE = AndroidTestRunConfiguration.TEST_CLASS;
configuration.CLASS_NAME = elementClass.getQualifiedName();
configuration.setGeneratedName();
return true;
}
elementClass = PsiTreeUtil.getParentOfType(elementClass, PsiClass.class);
}
return false;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:AndroidTestConfigurationProducer.java
示例4: getFilter
import com.intellij.execution.junit.JUnitUtil; //导入依赖的package包/类
protected ClassFilter.ClassFilterWithScope getFilter() throws NoFilterException {
final ConfigurationModuleSelector moduleSelector = getModuleSelector();
final Module module = moduleSelector.getModule();
if (module == null) {
throw NoFilterException.moduleDoesntExist(moduleSelector);
}
final ClassFilter.ClassFilterWithScope classFilter;
try {
final JUnitConfiguration configurationCopy =
new JUnitConfiguration(ExecutionBundle.message("default.junit.configuration.name"), getProject(),
JUnitConfigurationType.getInstance().getConfigurationFactories()[0]);
applyEditorTo(configurationCopy);
classFilter = TestClassFilter
.create(configurationCopy.getTestObject().getSourceScope(), configurationCopy.getConfigurationModule().getModule());
}
catch (JUnitUtil.NoJUnitException e) {
throw NoFilterException.noJUnitInModule(module);
}
return classFilter;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:JUnitConfigurable.java
示例5: getDirectlySelectedMethods
import com.intellij.execution.junit.JUnitUtil; //导入依赖的package包/类
/**
* Get all test methods directly selected in the given context. This includes, for example,
* methods selected from the Structure panel. It does not include methods the context location is
* inside of. Note that methods may belong to different classes (possible if methods are selected
* from the Project panel with "Show Members" checked), and methods in abstract classes are not
* returned.
*
* @param context The context to get selected test methods from.
* @param allMustMatch If true, will return null if any selected elements are not test methods.
* @return A list of test methods (possibly empty), or null if:
* <ul>
* <li>There is no selection
* <li>{@code allMustMatch} is true, but elements other than test methods are selected
* </ul>
*/
@Nullable
public static List<PsiMethod> getDirectlySelectedMethods(
@NotNull ConfigurationContext context, boolean allMustMatch) {
final DataContext dataContext = context.getDataContext();
PsiElement[] elements = LangDataKeys.PSI_ELEMENT_ARRAY.getData(dataContext);
if (elements == null) {
return null;
}
List<PsiMethod> methods = new ArrayList<>();
for (PsiElement element : elements) {
if (element instanceof PsiMethod) {
PsiMethod method = (PsiMethod) element;
if (JUnitUtil.isTestMethod(PsiLocation.fromPsiElement(method))) {
methods.add(method);
} else if (allMustMatch) {
return null;
}
} else if (allMustMatch) {
return null;
}
}
return methods;
}
开发者ID:bazelbuild,项目名称:intellij,代码行数:39,代码来源:TestMethodSelectionUtil.java
示例6: getIndirectlySelectedMethod
import com.intellij.execution.junit.JUnitUtil; //导入依赖的package包/类
/**
* Get a test method which is considered selected in the given context, belonging to a
* non-abstract class. The context location may be the method itself, or anywhere inside the
* method.
*
* @param context The context to search for a test method in.
* @return A test method, or null if none are found.
*/
@Nullable
public static PsiMethod getIndirectlySelectedMethod(@NotNull ConfigurationContext context) {
final Location<?> contextLocation = context.getLocation();
if (contextLocation == null) {
return null;
}
Iterator<Location<PsiMethod>> locationIterator =
contextLocation.getAncestors(PsiMethod.class, false);
while (locationIterator.hasNext()) {
Location<PsiMethod> methodLocation = locationIterator.next();
if (JUnitUtil.isTestMethod(methodLocation)) {
return methodLocation.getPsiElement();
}
}
return null;
}
开发者ID:bazelbuild,项目名称:intellij,代码行数:25,代码来源:TestMethodSelectionUtil.java
示例7: collectTestMembers
import com.intellij.execution.junit.JUnitUtil; //导入依赖的package包/类
static Set<PsiMember> collectTestMembers(PsiElement[] psiElements) {
final Set<PsiMember> foundMembers = new LinkedHashSet<PsiMember>();
for (PsiElement psiElement : psiElements) {
if (psiElement instanceof PsiClassOwner) {
final PsiClass[] classes = ((PsiClassOwner)psiElement).getClasses();
for (PsiClass aClass : classes) {
if (JUnitUtil.isTestClass(aClass)) {
foundMembers.add(aClass);
}
}
} else if (psiElement instanceof PsiClass) {
if (TestNGUtil.hasTest((PsiClass)psiElement)) {
foundMembers.add((PsiClass)psiElement);
}
} else if (psiElement instanceof PsiMethod) {
if (TestNGUtil.hasTest((PsiModifierListOwner)psiElement)) {
foundMembers.add((PsiMember)psiElement);
}
}
}
return foundMembers;
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:23,代码来源:TestNGPatternConfigurationProducer.java
示例8: showDialog
import com.intellij.execution.junit.JUnitUtil; //导入依赖的package包/类
protected String showDialog() {
final String className = getClassName();
if (className.trim().length() == 0) {
Messages.showMessageDialog(getField(), ExecutionBundle.message("set.class.name.message"),
ExecutionBundle.message("cannot.browse.method.dialog.title"), Messages.getInformationIcon());
return null;
}
final PsiClass testClass = getModuleSelector().findClass(className);
if (testClass == null) {
Messages.showMessageDialog(getField(), ExecutionBundle.message("class.does.not.exists.error.message", className),
ExecutionBundle.message("cannot.browse.method.dialog.title"),
Messages.getInformationIcon());
return null;
}
final MethodListDlg dlg = new MethodListDlg(testClass, new JUnitUtil.TestMethodFilter(testClass), getField());
dlg.show();
if (dlg.isOK()) {
final PsiMethod method = dlg.getSelected();
if (method != null) {
return method.getName();
}
}
return null;
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:25,代码来源:JUnitConfigurable.java
示例9: getParameterizedLocation
import com.intellij.execution.junit.JUnitUtil; //导入依赖的package包/类
public static Location getParameterizedLocation(PsiClass psiClass, String paramSetName, String parameterizedClassName)
{
final PsiAnnotation annotation = AnnotationUtil.findAnnotationInHierarchy(psiClass, Collections.singleton(JUnitUtil.RUN_WITH));
if(annotation != null)
{
final PsiAnnotationMemberValue attributeValue = annotation.findAttributeValue("value");
if(attributeValue instanceof PsiClassObjectAccessExpression)
{
final PsiTypeElement operand = ((PsiClassObjectAccessExpression) attributeValue).getOperand();
if(InheritanceUtil.isInheritor(operand.getType(), parameterizedClassName))
{
return new PsiMemberParameterizedLocation(psiClass.getProject(), psiClass, null, paramSetName);
}
}
}
return null;
}
开发者ID:consulo,项目名称:consulo-java,代码行数:18,代码来源:PsiMemberParameterizedLocation.java
示例10: checkConfiguration
import com.intellij.execution.junit.JUnitUtil; //导入依赖的package包/类
@Override
public void checkConfiguration(@NotNull AndroidFacet facet) throws RuntimeConfigurationException {
if (getTargetSelectionMode() == TargetSelectionMode.CLOUD_MATRIX_TEST && !IS_VALID_CLOUD_MATRIX_SELECTION) {
throw new RuntimeConfigurationError(INVALID_CLOUD_MATRIX_SELECTION_ERROR);
}
if (getTargetSelectionMode() == TargetSelectionMode.CLOUD_DEVICE_LAUNCH && !IS_VALID_CLOUD_DEVICE_SELECTION) {
throw new RuntimeConfigurationError(INVALID_CLOUD_DEVICE_SELECTION_ERROR);
}
Module module = facet.getModule();
JavaPsiFacade facade = JavaPsiFacade.getInstance(module.getProject());
switch (TESTING_TYPE) {
case TEST_ALL_IN_PACKAGE:
final PsiPackage testPackage = facade.findPackage(PACKAGE_NAME);
if (testPackage == null) {
throw new RuntimeConfigurationWarning(ExecutionBundle.message("package.does.not.exist.error.message", PACKAGE_NAME));
}
break;
case TEST_CLASS:
final PsiClass testClass =
getConfigurationModule().checkModuleAndClassName(CLASS_NAME, ExecutionBundle.message("no.test.class.specified.error.text"));
if (!JUnitUtil.isTestClass(testClass)) {
throw new RuntimeConfigurationWarning(ExecutionBundle.message("class.isnt.test.class.error.message", CLASS_NAME));
}
break;
case TEST_METHOD:
checkTestMethod();
break;
}
if (INSTRUMENTATION_RUNNER_CLASS.length() > 0) {
if (facade.findClass(INSTRUMENTATION_RUNNER_CLASS, module.getModuleWithDependenciesAndLibrariesScope(true)) == null) {
throw new RuntimeConfigurationError(AndroidBundle.message("instrumentation.runner.class.not.specified.error"));
}
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:36,代码来源:AndroidTestRunConfiguration.java
示例11: checkTestMethod
import com.intellij.execution.junit.JUnitUtil; //导入依赖的package包/类
private void checkTestMethod() throws RuntimeConfigurationException {
JavaRunConfigurationModule configurationModule = getConfigurationModule();
final PsiClass testClass =
configurationModule.checkModuleAndClassName(CLASS_NAME, ExecutionBundle.message("no.test.class.specified.error.text"));
if (!JUnitUtil.isTestClass(testClass)) {
throw new RuntimeConfigurationWarning(ExecutionBundle.message("class.isnt.test.class.error.message", CLASS_NAME));
}
if (METHOD_NAME == null || METHOD_NAME.trim().length() == 0) {
throw new RuntimeConfigurationError(ExecutionBundle.message("method.name.not.specified.error.message"));
}
final JUnitUtil.TestMethodFilter filter = new JUnitUtil.TestMethodFilter(testClass);
boolean found = false;
boolean testAnnotated = false;
for (final PsiMethod method : testClass.findMethodsByName(METHOD_NAME, true)) {
if (filter.value(method)) found = true;
if (JUnitUtil.isTestAnnotated(method)) testAnnotated = true;
}
if (!found) {
throw new RuntimeConfigurationWarning(ExecutionBundle.message("test.method.doesnt.exist.error.message", METHOD_NAME));
}
if (!AnnotationUtil.isAnnotated(testClass, JUnitUtil.RUN_WITH, true) && !testAnnotated) {
try {
final PsiClass testCaseClass = JUnitUtil.getTestCaseClass(configurationModule.getModule());
if (!testClass.isInheritor(testCaseClass, true)) {
throw new RuntimeConfigurationError(ExecutionBundle.message("class.isnt.inheritor.of.testcase.error.message", CLASS_NAME));
}
}
catch (JUnitUtil.NoJUnitException e) {
throw new RuntimeConfigurationWarning(ExecutionBundle.message(AndroidBundle.message("cannot.find.testcase.error")));
}
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:34,代码来源:AndroidTestRunConfiguration.java
示例12: createTreeClassChooser
import com.intellij.execution.junit.JUnitUtil; //导入依赖的package包/类
@Nullable
@Override
protected TreeClassChooser createTreeClassChooser(@NotNull Project project,
@NotNull GlobalSearchScope scope,
@Nullable PsiClass initialSelection, @NotNull final ClassFilter classFilter) {
return TreeClassChooserFactory.getInstance(project).createNoInnerClassesScopeChooser(myDialogTitle, scope, new ClassFilter() {
@Override
public boolean isAccepted(PsiClass aClass) {
return classFilter.isAccepted(aClass) && JUnitUtil.isTestClass(aClass);
}
}, initialSelection);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:AndroidTestClassBrowser.java
示例13: isTestMethod
import com.intellij.execution.junit.JUnitUtil; //导入依赖的package包/类
private static boolean isTestMethod(PsiMethod method) {
PsiClass testClass = method.getContainingClass();
if (testClass != null && JUnitUtil.isTestClass(testClass)) {
return new JUnitUtil.TestMethodFilter(testClass).value(method);
}
return false;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:AndroidTestConfigurationProducer.java
示例14: getTestMethod
import com.intellij.execution.junit.JUnitUtil; //导入依赖的package包/类
@Nullable
static Location<PsiMethod> getTestMethod(final Location<?> location) {
for (Iterator<Location<PsiMethod>> iterator = location.getAncestors(PsiMethod.class, false); iterator.hasNext(); ) {
final Location<PsiMethod> methodLocation = iterator.next();
if (JUnitUtil.isTestMethod(methodLocation, false)) return methodLocation;
}
return null;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:TestRunnerUtils.java
示例15: isEntryPoint
import com.intellij.execution.junit.JUnitUtil; //导入依赖的package包/类
@Override
public boolean isEntryPoint(@NotNull PsiElement psiElement) {
if (ADD_JUNIT_TO_ENTRIES) {
if (psiElement instanceof PsiClass) {
final PsiClass aClass = (PsiClass)psiElement;
if (JUnitUtil.isTestClass(aClass, false, true)) {
if (!PsiClassUtil.isRunnableClass(aClass, true, true)) {
final PsiClass topLevelClass = PsiTreeUtil.getTopmostParentOfType(aClass, PsiClass.class);
if (topLevelClass != null && PsiClassUtil.isRunnableClass(topLevelClass, true, true)) {
return true;
}
final CommonProcessors.FindProcessor<PsiClass> findProcessor = new CommonProcessors.FindProcessor<PsiClass>() {
@Override
protected boolean accept(PsiClass psiClass) {
return !psiClass.hasModifierProperty(PsiModifier.ABSTRACT);
}
};
return !ClassInheritorsSearch.search(aClass).forEach(findProcessor) && findProcessor.isFound();
}
return true;
}
}
else if (psiElement instanceof PsiMethod) {
final PsiMethod method = (PsiMethod)psiElement;
if (method.isConstructor() && method.getParameterList().getParametersCount() == 0) {
return JUnitUtil.isTestClass(method.getContainingClass());
}
if (JUnitUtil.isTestMethodOrConfig(method)) return true;
}
}
return false;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:33,代码来源:JUnitEntryPoint.java
示例16: value
import com.intellij.execution.junit.JUnitUtil; //导入依赖的package包/类
public boolean value(PsiElement member) {
if (member instanceof PsiMethod) {
PsiMethod method = (PsiMethod)member;
if (JUnitUtil.isTestMethodOrConfig(method)){
return true;
}
}
return false;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:JUnitCantBeStaticExtension.java
示例17: createNodeForMethod
import com.intellij.execution.junit.JUnitUtil; //导入依赖的package包/类
@Nullable
@Override
protected MethodNode createNodeForMethod(final Module module, final GrMethod method, final String parentLocationRootMark) {
if (method == null) return null;
final boolean isTestMethod = JUnitUtil.isTestMethod(new PsiLocation<PsiMethod>(getProject(), method));
if (isTestMethod) {
return new TestMethodNode(module, method, NodeId.TEST_CLASS_IN_TESTS_SUBTREE, getSettings(), myMethodIcon);
}
return new MethodNode(module, method, NodeId.TEST_CLASS_IN_TESTS_SUBTREE, getSettings());
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:TestClassNode.java
示例18: isTestMethod
import com.intellij.execution.junit.JUnitUtil; //导入依赖的package包/类
@Override
public boolean isTestMethod(PsiElement element) {
if (!(element instanceof GrMethod)) return false;
return GroovyPsiManager.isInheritorCached(((GrMethod)element).getContainingClass(), SpockUtils.SPEC_CLASS_NAME)
&& JUnitUtil.getTestMethod(element) != null;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:SpockTestFramework.java
示例19: findOrCreateSetUpMethod
import com.intellij.execution.junit.JUnitUtil; //导入依赖的package包/类
@Override
protected PsiMethod findOrCreateSetUpMethod(PsiClass clazz) throws IncorrectOperationException {
LOG.assertTrue(clazz.getLanguage() == GroovyLanguage.INSTANCE);
final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(clazz.getProject());
final PsiMethod patternMethod = createSetUpPatternMethod(factory);
final PsiClass baseClass = clazz.getSuperClass();
if (baseClass != null) {
final PsiMethod baseMethod = baseClass.findMethodBySignature(patternMethod, false);
if (baseMethod != null && baseMethod.hasModifierProperty(PsiModifier.PUBLIC)) {
PsiUtil.setModifierProperty(patternMethod, PsiModifier.PROTECTED, false);
PsiUtil.setModifierProperty(patternMethod, PsiModifier.PUBLIC, true);
}
}
PsiMethod inClass = clazz.findMethodBySignature(patternMethod, false);
if (inClass == null) {
PsiMethod testMethod = JUnitUtil.findFirstTestMethod(clazz);
if (testMethod != null) {
return (PsiMethod)clazz.addBefore(patternMethod, testMethod);
}
return (PsiMethod)clazz.add(patternMethod);
}
else if (inClass.getBody() == null) {
return (PsiMethod)inClass.replace(patternMethod);
}
return inClass;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:30,代码来源:GroovyTestFramework.java
示例20: findClasses
import com.intellij.execution.junit.JUnitUtil; //导入依赖的package包/类
private static List<PsiClass> findClasses(
Project project, GlobalSearchScope scope, String className) {
PsiClass psiClass = JavaPsiFacade.getInstance(project).findClass(className, scope);
if (psiClass != null) {
return ImmutableList.of(psiClass);
}
// handle unqualified class names
return Arrays.stream(PsiShortNamesCache.getInstance(project).getClassesByName(className, scope))
.filter(JUnitUtil::isTestClass)
.collect(Collectors.toList());
}
开发者ID:bazelbuild,项目名称:intellij,代码行数:12,代码来源:BlazeAndroidTestLocator.java
注:本文中的com.intellij.execution.junit.JUnitUtil类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论