de.dagere.kopeme.junit.rule.BeforeAfterMethodFinderJUnit5 Maven / Gradle / Ivy
package de.dagere.kopeme.junit.rule;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import de.dagere.kopeme.junit.rule.annotations.AfterWithMeasurement;
import de.dagere.kopeme.junit.rule.annotations.BeforeWithMeasurement;
import de.dagere.kopeme.runnables.BeforeAfterMethodFinder;
public class BeforeAfterMethodFinderJUnit5 extends BeforeAfterMethodFinder {
public static List getBeforeWithMeasurements(final Class> testClazz) {
Map> beforePriorityMethods = new TreeMap<>();
for (final Method classMethod : testClazz.getDeclaredMethods()) {
BeforeWithMeasurement annotationValue = classMethod.getAnnotation(BeforeWithMeasurement.class);
if (annotationValue != null) {
classMethod.setAccessible(true);
int priority = annotationValue.priority();
addToPriority(beforePriorityMethods, classMethod, priority);
}
}
List orderedMethodsMethod = BeforeAfterMethodFinder.buildOrderedList(beforePriorityMethods);
return orderedMethodsMethod;
}
public static List getAfterWithMeasurements(final Class> testClazz) {
Map> beforePriorityMethods = new TreeMap<>();
for (final Method classMethod : testClazz.getDeclaredMethods()) {
AfterWithMeasurement annotationValue = classMethod.getAnnotation(AfterWithMeasurement.class);
if (annotationValue != null) {
classMethod.setAccessible(true);
int priority = annotationValue.priority();
addToPriority(beforePriorityMethods, classMethod, priority);
}
}
List orderedMethodsMethod = BeforeAfterMethodFinder.buildOrderedList(beforePriorityMethods);
return orderedMethodsMethod;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy