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

info.novatec.testit.webtester.conditions.syntax.Either Maven / Gradle / Ivy

package info.novatec.testit.webtester.conditions.syntax;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import info.novatec.testit.webtester.conditions.Condition;


/**
 * {@link Condition} which returns the result of any number of OR evaluated conditions.
 * The first positively evaluated condition will lead to true being
 * returned. This is intended to be used to enhance code readability.
 * 

* Example: * Waits.waitUntil(textfield, has(either(text("foo"), text("bar")))); * * @param type of the object to test against the conditions * @since 2.0 */ public class Either implements Condition { private final List> conditions = new ArrayList<>(); public Either(Condition condition) { this.conditions.add(condition); } public Either(Condition condition1, Condition condition2) { this.conditions.add(condition1); this.conditions.add(condition2); } @SafeVarargs public Either(Condition... conditions) { this.conditions.addAll(Arrays.asList(conditions)); } @Override public boolean test(T value) { return conditions.stream().anyMatch(condition -> condition.test(value)); } @Override public String toString() { return "either(" + StringUtils.join(conditions, ", ") + ')'; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy