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

tech.grasshopper.combiner.search.SearchTest Maven / Gradle / Ivy

The newest version!
package tech.grasshopper.combiner.search;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import com.aventstack.extentreports.Status;

import tech.grasshopper.combiner.pojo.Test;

public class SearchTest {

	public static Optional findTestByName(Test[] tests, String name) {
		return findTestByName(Arrays.asList(tests), name);
	}

	public static Optional findTestByNameAndType(Test[] tests, Test test) {
		return findTestByNameAndType(Arrays.asList(tests), test);
	}

	public static Optional findTestByName(List tests, String name) {
		return tests.stream().filter(t -> t.getName().equals(name)).findFirst();
	}

	public static Optional findTestByNameAndType(List tests, Test test) {
		return tests.stream()
				.filter(t -> t.getBddType().equals(test.getBddType()) && t.getName().equals(test.getName()))
				.findFirst();
	}

	public static List findScenarioInFeature(Test featureTest) {
		return featureTest.getChildren().stream().filter(t -> t.getBddType().endsWith(".Scenario"))
				.collect(Collectors.toList());
	}

	public static List findScenarioOutlineInFeature(Test featureTest) {
		return featureTest.getChildren().stream().filter(t -> t.getBddType().endsWith(".ScenarioOutline"))
				.collect(Collectors.toList());
	}

	public static List findScenarioInScenarioOutline(Test scenarioOutlineTest) {
		return scenarioOutlineTest.getChildren().stream().filter(t -> t.getBddType().endsWith(".Scenario"))
				.collect(Collectors.toList());
	}

	public static long failFeatureTestStatusCount(List tests) {
		return tests.stream().filter(t -> t.getStatus() == Status.FAIL).count();
	}

	public static long passScenarioTestStatusCount(List tests) {
		List childTest = tests.stream().flatMap(t -> t.getChildren().stream()).collect(Collectors.toList());

		return childTest.stream().filter(t -> t.getBddType().endsWith(".Scenario") && t.getStatus() == Status.PASS)
				.count()
				+ childTest.stream().filter(t -> t.getBddType().endsWith(".ScenarioOutline"))
						.flatMap(t -> t.getChildren().stream()).filter(t -> t.getStatus() == Status.PASS).count();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy