All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aventstack.extentreports.model.context.ExceptionTestContextStore Maven / Gradle / Ivy

There is a newer version: 5.1.1
Show newest version
package com.aventstack.extentreports.model.context;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import com.aventstack.extentreports.model.ExceptionInfo;
import com.aventstack.extentreports.model.Test;

/**
 * Provides and tracks the collection of tests segregated by the type of
 * {@link Exception}
 * 
 */
public class ExceptionTestContextStore {

	private List exceptionTestContext = new ArrayList<>();

	public void setExceptionContext(ExceptionInfo ei, Test test) {
		Optional exOptionalTestContext = exceptionTestContext.stream()
				.filter(x -> x.getExceptionInfo().getExceptionName().equals(ei.getExceptionName())).findFirst();

		if (exOptionalTestContext.isPresent()) {
			List testList = exOptionalTestContext.get().getTests();

			boolean b = testList.stream().anyMatch(t -> t.getId() == test.getId());

			if (!b) {
				exOptionalTestContext.get().setTest(test);
			}
		} else {
			ExceptionTestContext exTestContext = new ExceptionTestContext(ei);
			exTestContext.setTest(test);
			exceptionTestContext.add(exTestContext);
		}
	}

	public List getExceptionTestContext() {
		return exceptionTestContext;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy