### Question:
QueryIndex { public List<T> findMatches(Id id) { List<T> result = new ArrayList<>(); forEachMatch(id, result::add); return result; } private  QueryIndex(Registry registry, String key); static QueryIndex<V> newInstance(Registry registry); QueryIndex<T> add(Query query, T value); boolean remove(T value); boolean isEmpty(); List<T> findMatches(Id id); void forEachMatch(Id id, Consumer<T> consumer); @Override String toString();  }### Answer:
@Test public void simpleMatches() { Id id1 = id("a", "key", "b"); Id id2 = id("a", "foo", "bar", "key", "b"); Assertions.assertEquals(list(SIMPLE_QUERY), simpleIdx().findMatches(id1)); Assertions.assertEquals(list(SIMPLE_QUERY), simpleIdx().findMatches(id2)); }
@Test public void hasKeyMatches() { Id id1 = id("a", "key", "b", "c", "12345"); Id id2 = id("a", "foo", "bar", "key", "b", "c", "foobar"); Assertions.assertEquals(list(HASKEY_QUERY), hasKeyIdx().findMatches(id1)); Assertions.assertEquals(list(HASKEY_QUERY), hasKeyIdx().findMatches(id2)); }
@Test public void hasKeyRepeat() { Id id1 = id("a", "key", "b", "c", "12345"); QueryIndex<Query> idx = hasKeyIdx(); for (int i = 0; i < 10; ++i) { Assertions.assertEquals(list(HASKEY_QUERY), idx.findMatches(id1)); } }
@Test public void inMatches() { Id id1 = id("a", "key", "b", "c", "12345"); Id id2 = id("a", "foo", "bar", "key", "c", "c", "foobar"); Assertions.assertEquals(list(IN_QUERY), inIdx().findMatches(id1)); Assertions.assertEquals(list(IN_QUERY), inIdx().findMatches(id2)); }