Skip to content

Commit

Permalink
commented out category code
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcus Kaufmann committed Apr 10, 2018
1 parent f474d1f commit ea2fb38
Showing 1 changed file with 93 additions and 96 deletions.
189 changes: 93 additions & 96 deletions src/main/java/com/xceptance/neodymium/NeodymiumRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
Expand All @@ -39,7 +35,6 @@
import org.slf4j.LoggerFactory;

import com.xceptance.neodymium.NeodymiumDataRunner.NeodymiumDataRunnerRunner;
import com.xceptance.neodymium.groups.DefaultGroup;
import com.xceptance.neodymium.multibrowser.Browser;
import com.xceptance.neodymium.multibrowser.BrowserRunner;

Expand Down Expand Up @@ -175,97 +170,99 @@ public NeodymiumRunner(Class<?> testKlass, RunnerBuilder rb) throws Throwable
testDescription = createTestDescription();
}

private List<List<Runner>> regroupTests(List<List<Runner>> testRunner, List<Class<?>> groupsToExecute, boolean matchAny)
{
Map<FrameworkMethod, Set<Class<?>>> testMethodsWithTestGroups = getTestMethodsWithCategories();

List<List<Runner>> groupedRunner = new LinkedList<>();

for (List<Runner> runners : testRunner)
{
FrameworkMethod method = null;
// the last runner in the list should always be an NeodymiumMethodRunner
// get this method
Runner runner = runners.get(runners.size() - 1);
if (runner instanceof NeodymiumMethodRunner)
{
method = ((NeodymiumMethodRunner) runner).getMethod();
}
else
{
throw new RuntimeException("This shouldn't happen");
}

if (testCategoryMatch(testMethodsWithTestGroups.get(method), groupsToExecute, matchAny))
{
groupedRunner.add(runners);
}
}

return groupedRunner;
}

private boolean testCategoryMatch(Set<Class<?>> annotatedGroups, List<Class<?>> groupsToExecute, boolean matchAny)
{
// if not matchAny then it's matchAll
boolean match;
if (matchAny)
{
match = false;
}
else
{
match = true;
}
for (Class<?> annotatedGroup : annotatedGroups)
{
boolean executionGroupsContainsAnnotatedGroup = groupsToExecute.contains(annotatedGroup);
if (matchAny)
{
match |= executionGroupsContainsAnnotatedGroup;
}
else
{
match &= executionGroupsContainsAnnotatedGroup;
}
}

return match;
}

private Map<FrameworkMethod, Set<Class<?>>> getTestMethodsWithCategories()
{
Map<FrameworkMethod, Set<Class<?>>> testMethods = new HashMap<>();

Category classCategory = testClass.getAnnotation(Category.class);
List<Class<?>> classCategories = new ArrayList<>();
if (classCategory != null)
{
classCategories = Arrays.asList(classCategory.value());
}

// method grouping belongs only to test methods so check that first
for (FrameworkMethod annotatedMethod : testClass.getAnnotatedMethods(Test.class))
{
Category categoryAnnotation = annotatedMethod.getAnnotation(Category.class);

Set<Class<?>> categories = new HashSet<>();
if (categoryAnnotation != null)
{
categories.addAll(Arrays.asList(categoryAnnotation.value()));
}

// add categories from class to every method
categories.addAll(classCategories);
// ensure that DefaultGroup is set for all methods that makes it easier afterwards
categories.add(DefaultGroup.class);
categories.remove(null);

testMethods.put(annotatedMethod, categories);
}

return testMethods;
}
// private List<List<Runner>> regroupTests(List<List<Runner>> testRunner, List<Class<?>> groupsToExecute, boolean
// matchAny)
// {
// Map<FrameworkMethod, Set<Class<?>>> testMethodsWithTestGroups = getTestMethodsWithCategories();
//
// List<List<Runner>> groupedRunner = new LinkedList<>();
//
// for (List<Runner> runners : testRunner)
// {
// FrameworkMethod method = null;
// // the last runner in the list should always be an NeodymiumMethodRunner
// // get this method
// Runner runner = runners.get(runners.size() - 1);
// if (runner instanceof NeodymiumMethodRunner)
// {
// method = ((NeodymiumMethodRunner) runner).getMethod();
// }
// else
// {
// throw new RuntimeException("This shouldn't happen");
// }
//
// if (testCategoryMatch(testMethodsWithTestGroups.get(method), groupsToExecute, matchAny))
// {
// groupedRunner.add(runners);
// }
// }
//
// return groupedRunner;
// }
//
// private boolean testCategoryMatch(Set<Class<?>> annotatedGroups, List<Class<?>> groupsToExecute, boolean
// matchAny)
// {
// // if not matchAny then it's matchAll
// boolean match;
// if (matchAny)
// {
// match = false;
// }
// else
// {
// match = true;
// }
// for (Class<?> annotatedGroup : annotatedGroups)
// {
// boolean executionGroupsContainsAnnotatedGroup = groupsToExecute.contains(annotatedGroup);
// if (matchAny)
// {
// match |= executionGroupsContainsAnnotatedGroup;
// }
// else
// {
// match &= executionGroupsContainsAnnotatedGroup;
// }
// }
//
// return match;
// }
//
// private Map<FrameworkMethod, Set<Class<?>>> getTestMethodsWithCategories()
// {
// Map<FrameworkMethod, Set<Class<?>>> testMethods = new HashMap<>();
//
// Category classCategory = testClass.getAnnotation(Category.class);
// List<Class<?>> classCategories = new ArrayList<>();
// if (classCategory != null)
// {
// classCategories = Arrays.asList(classCategory.value());
// }
//
// // method grouping belongs only to test methods so check that first
// for (FrameworkMethod annotatedMethod : testClass.getAnnotatedMethods(Test.class))
// {
// Category categoryAnnotation = annotatedMethod.getAnnotation(Category.class);
//
// Set<Class<?>> categories = new HashSet<>();
// if (categoryAnnotation != null)
// {
// categories.addAll(Arrays.asList(categoryAnnotation.value()));
// }
//
// // add categories from class to every method
// categories.addAll(classCategories);
// // ensure that DefaultGroup is set for all methods that makes it easier afterwards
// categories.add(DefaultGroup.class);
// categories.remove(null);
//
// testMethods.put(annotatedMethod, categories);
// }
//
// return testMethods;
// }

private void setFinalStatic(Field field, Object newValue) throws Exception
{
Expand Down

0 comments on commit ea2fb38

Please sign in to comment.