Add test for potion durations

This commit is contained in:
Jonathan Coates
2025-12-24 08:51:15 +00:00
parent 90e7307fb4
commit 24fd27d2a3
4 changed files with 98 additions and 2 deletions
@@ -5,11 +5,14 @@
package dan200.computercraft.test.core;
import org.hamcrest.Matcher;
import org.hamcrest.StringDescription;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.is;
public class CustomMatchers {
/**
@@ -25,4 +28,32 @@ public class CustomMatchers {
public static <T> Matcher<Iterable<? extends T>> containsWith(List<T> items, Function<T, Matcher<? super T>> matcher) {
return contains(items.stream().map(matcher).toList());
}
/**
* An alternative to {@link org.hamcrest.Matchers#hasEntry(Object, Object)}, that acts as a projection, rather than
* searching the map.
*
* @param key The key to extract.
* @param value The expected value.
* @param <K> The type of keys in the map.
* @param <V> The type of values in the map.
* @return A matcher that projects out of a map.
*/
public static <K, V> Matcher<Map<? extends K, ? extends V>> containsEntry(K key, V value) {
return containsEntryWith(key, is(value));
}
/**
* An alternative to {@link org.hamcrest.Matchers#hasEntry(Matcher, Matcher)}, that acts as a projection, rather
* than searching the map.
*
* @param key The key to extract.
* @param value The expected value.
* @param <K> The type of keys in the map.
* @param <V> The type of values in the map.
* @return A matcher that projects out of a map.
*/
public static <K, V> Matcher<Map<? extends K, ? extends V>> containsEntryWith(K key, Matcher<? super V> value) {
return ContramapMatcher.contramap(value, new StringDescription().appendValue(key).toString(), x -> x.get(key));
}
}