com.aventstack.extentreports.TestAttributeTestContextProvider Maven / Gradle / Ivy
package com.aventstack.extentreports;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import com.aventstack.extentreports.model.Test;
import com.aventstack.extentreports.model.TestAttribute;
import com.aventstack.extentreports.model.TestAttributeTestContext;
/**
* Uses an attribute context for {@link TestAttribute} (Category, Device, Author etc.)
* and tracks the collection of tests segregated by the type {@link TestAttribute}
*
* @param A {@link TestAttribute} type
*/
public class TestAttributeTestContextProvider {
private List> testAttrCollection;
public TestAttributeTestContextProvider() {
testAttrCollection = new ArrayList<>();
}
public void setAttributeContext(T attr, Test test) {
Optional> testOptionalTestContext = testAttrCollection
.stream()
.filter(x -> x.getName().equals(attr.getName()))
.findFirst();
if (testOptionalTestContext.isPresent()) {
List testList = testOptionalTestContext.get().getTestList();
boolean b = testList
.stream()
.anyMatch(t -> t.getID() == test.getID());
if (!b) {
testOptionalTestContext.get().setTest(test);
}
testOptionalTestContext.get().refreshTestStatusCounts();
}
else {
TestAttributeTestContext testAttrContext = new TestAttributeTestContext<>(attr);
testAttrContext.setTest(test);
testAttrCollection.add(testAttrContext);
}
}
public void removeTest(Test test) {
Iterator> iter = testAttrCollection.iterator();
while (iter.hasNext()) {
TestAttributeTestContext context = iter.next();
TestRemover.remove(context.getTestList(), test);
if (context.isEmpty()) {
iter.remove();
}
}
}
public List> getTestAttributeTestContextList() {
return testAttrCollection;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy