com.aventstack.extentreports.TestRemover Maven / Gradle / Ivy
package com.aventstack.extentreports;
import java.util.List;
import java.util.stream.Collectors;
import com.aventstack.extentreports.model.Test;
class TestRemover {
/**
* Helper for removing test recursively. This flag determines when to break
* out of recursion
*/
private static boolean removed = false;
private TestRemover() { }
/**
* Remove a test using its unique ID from a list
*
* @param list a list of {@link Test}
* @param test {@link Test} to be removed
*/
public static void remove(List testList, Test test) {
removed = false;
findAndRemoveTest(testList, test);
}
/**
* Recursively traverses all tests, nodes upto the last leaf to find and remove
* the specified test
*
* @param list a list of {@link Test}
* @param test {@link Test} to be removed
*/
private static void findAndRemoveTest(List list, Test test) {
List filteredTestList = list
.stream()
.filter(x -> x.getID() == test.getID())
.collect(Collectors.toList());
if (filteredTestList.size() == 1) {
removeTest(list, filteredTestList.get(0));
removed = true;
return;
}
for (Test t : list) {
if (removed) {
return;
}
findAndRemoveTest(t.getNodeContext().getAll(), test);
}
}
/**
* Removes the test from a given list of tests
*
* @param list a list of {@link Test}
* @param test {@link Test} to be removed
*/
private static void removeTest(List list, Test test) {
list.remove(test);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy