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

ext.test4j.hamcrest.collection.IsIn Maven / Gradle / Ivy

There is a newer version: 2.5.0
Show newest version
package ext.test4j.hamcrest.collection;

import ext.test4j.hamcrest.BaseMatcher;
import ext.test4j.hamcrest.Description;
import ext.test4j.hamcrest.Factory;
import ext.test4j.hamcrest.Matcher;

import java.util.Arrays;
import java.util.Collection;

public class IsIn extends BaseMatcher {
	private final Collection collection;

	public IsIn(Collection collection) {
		this.collection = collection;
	}

	public IsIn(T[] elements) {
		collection = Arrays.asList(elements);
	}

	public boolean matches(Object o) {
		return collection.contains(o);
	}

	public void describeTo(Description buffer) {
		buffer.appendText("one of ");
		buffer.appendValueList("{", ", ", "}", collection);
	}

	@Factory
	public static  Matcher isIn(Collection collection) {
		return new IsIn(collection);
	}

	@Factory
	public static  Matcher isIn(T[] elements) {
		return new IsIn(elements);
	}

	@Factory
	public static  Matcher isOneOf(T... elements) {
		return isIn(elements);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy