mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
show suite with the containing class name instead of given name
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.junit4;
|
||||
|
||||
import org.junit.internal.runners.SuiteMethod;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
* Date: 2/22/12
|
||||
*/
|
||||
class ClassAwareSuiteMethod extends SuiteMethod {
|
||||
private final Class myKlass;
|
||||
|
||||
public ClassAwareSuiteMethod(Class klass) throws Throwable {
|
||||
super(klass);
|
||||
myKlass = klass;
|
||||
}
|
||||
|
||||
public Class getKlass() {
|
||||
return myKlass;
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,11 @@ import java.util.*;
|
||||
class IdeaSuite extends Suite {
|
||||
private final String myName;
|
||||
|
||||
public IdeaSuite(List runners, String name) throws InitializationError {
|
||||
super(null, runners);
|
||||
myName = name;
|
||||
}
|
||||
|
||||
public IdeaSuite(final RunnerBuilder builder, Class[] classes, String name) throws InitializationError {
|
||||
super(builder, classes);
|
||||
myName = name;
|
||||
@@ -59,12 +64,25 @@ class IdeaSuite extends Suite {
|
||||
return description;
|
||||
}
|
||||
|
||||
protected Description describeChild(Runner child) {
|
||||
final Description superDescription = super.describeChild(child);
|
||||
if (child instanceof ClassAwareSuiteMethod) {
|
||||
final Description description = Description.createSuiteDescription(((ClassAwareSuiteMethod)child).getKlass());
|
||||
ArrayList children = superDescription.getChildren();
|
||||
for (int i = 0, size = children.size(); i < size; i++) {
|
||||
description.addChild((Description)children.get(i));
|
||||
}
|
||||
return description;
|
||||
}
|
||||
return superDescription;
|
||||
}
|
||||
|
||||
protected List getChildren() {
|
||||
final List children = super.getChildren();
|
||||
final Set allNames = new HashSet();
|
||||
for (Iterator iterator = children.iterator(); iterator.hasNext();) {
|
||||
final Object child = iterator.next();
|
||||
allNames.add(((Runner)child).getDescription().getDisplayName());
|
||||
allNames.add(describeChild((Runner)child).getDisplayName());
|
||||
}
|
||||
for (Iterator iterator = children.iterator(); iterator.hasNext();) {
|
||||
final Object child = iterator.next();
|
||||
@@ -75,7 +93,7 @@ class IdeaSuite extends Suite {
|
||||
|
||||
for (Iterator iterator = children.iterator(); iterator.hasNext(); ) {
|
||||
Object child = iterator.next();
|
||||
if (!allNames.contains(((Runner)child).getDescription().getDisplayName())) {
|
||||
if (!allNames.contains(describeChild((Runner)child).getDisplayName())) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
@@ -83,14 +101,14 @@ class IdeaSuite extends Suite {
|
||||
return children;
|
||||
}
|
||||
|
||||
private static void skipSuiteComponents(Set allNames, Object child) {
|
||||
private void skipSuiteComponents(Set allNames, Object child) {
|
||||
try {
|
||||
if (child instanceof Suite) {
|
||||
final Method getChildrenMethod = Suite.class.getDeclaredMethod("getChildren", new Class[0]);
|
||||
getChildrenMethod.setAccessible(true);
|
||||
final List tests = (List)getChildrenMethod.invoke(child, new Object[0]);
|
||||
for (Iterator suiteIterator = tests.iterator(); suiteIterator.hasNext();) {
|
||||
final String displayName = ((Runner)suiteIterator.next()).getDescription().getDisplayName();
|
||||
final String displayName = describeChild((Runner)suiteIterator.next()).getDisplayName();
|
||||
if (allNames.contains(displayName)) {
|
||||
allNames.remove(displayName);
|
||||
}
|
||||
|
||||
@@ -21,13 +21,13 @@
|
||||
package com.intellij.junit4;
|
||||
|
||||
import org.junit.internal.builders.AllDefaultPossibilitiesBuilder;
|
||||
import org.junit.internal.builders.SuiteMethodBuilder;
|
||||
import org.junit.internal.runners.ErrorReportingRunner;
|
||||
import org.junit.runner.Request;
|
||||
import org.junit.runner.Runner;
|
||||
import org.junit.runners.model.InitializationError;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
public class JUnit46ClassesRequestBuilder {
|
||||
private JUnit46ClassesRequestBuilder() {}
|
||||
@@ -35,8 +35,13 @@ public class JUnit46ClassesRequestBuilder {
|
||||
public static Request getClassesRequest(final String suiteName, Class[] classes, Map classMethods) {
|
||||
boolean canUseSuiteMethod = canUseSuiteMethod(classMethods);
|
||||
try {
|
||||
final AllDefaultPossibilitiesBuilder builder = new AllDefaultPossibilitiesBuilder(canUseSuiteMethod);
|
||||
final Runner suite = new IdeaSuite(builder, classes, suiteName);
|
||||
final Runner suite;
|
||||
if (canUseSuiteMethod) {
|
||||
suite = new IdeaSuite(collectWrappedRunners(classes), suiteName);
|
||||
} else {
|
||||
final AllDefaultPossibilitiesBuilder builder = new AllDefaultPossibilitiesBuilder(canUseSuiteMethod);
|
||||
suite = new IdeaSuite(builder, classes, suiteName);
|
||||
}
|
||||
return Request.runner(suite);
|
||||
}
|
||||
catch (InitializationError e) {
|
||||
@@ -44,6 +49,27 @@ public class JUnit46ClassesRequestBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
private static List collectWrappedRunners(Class[] classes) throws InitializationError {
|
||||
final List runners = new ArrayList();
|
||||
final List nonSuiteClasses = new ArrayList();
|
||||
final SuiteMethodBuilder suiteMethodBuilder = new SuiteMethodBuilder();
|
||||
for (int i = 0, length = classes.length; i < length; i++) {
|
||||
Class aClass = classes[i];
|
||||
if (suiteMethodBuilder.hasSuiteMethod(aClass)) {
|
||||
try {
|
||||
runners.add(new ClassAwareSuiteMethod(aClass));
|
||||
}
|
||||
catch (Throwable throwable) {
|
||||
runners.add(new ErrorReportingRunner(aClass, throwable));
|
||||
}
|
||||
} else {
|
||||
nonSuiteClasses.add(aClass);
|
||||
}
|
||||
}
|
||||
runners.addAll(new AllDefaultPossibilitiesBuilder(false).runners(null, (Class[])nonSuiteClasses.toArray(new Class[nonSuiteClasses.size()])));
|
||||
return runners;
|
||||
}
|
||||
|
||||
private static boolean canUseSuiteMethod(Map classMethods) {
|
||||
for (Iterator iterator = classMethods.keySet().iterator(); iterator.hasNext(); ) {
|
||||
Object className = iterator.next();
|
||||
|
||||
Reference in New Issue
Block a user