### Question:
ThreadMatcher { public <S1, S2> void forEachThread(NonCapturingPredicate<Thread, S1> predicate, S1 state1, NonCapturingConsumer<Thread, S2> consumer, S2 state2) { int count = systemThreadGroup.activeCount(); do { int expectedArrayLength = count + (count / 2) + 1; if (threads.length < expectedArrayLength) { threads = new Thread[expectedArrayLength]; } count = systemThreadGroup.enumerate(threads, true); } while (count >= threads.length); for (int i = 0; i < count; i++) { Thread thread = threads[i]; if (predicate.test(thread, state1)) { consumer.accept(thread, state2); } threads[i] = null; } } ThreadMatcher(); void forEachThread(NonCapturingPredicate<Thread, S1> predicate, S1 state1, NonCapturingConsumer<Thread, S2> consumer, S2 state2);  }### Answer:
@Test void testLookup() { ArrayList<Thread> threads = new ArrayList<>(); threadMatcher.forEachThread(new ThreadMatcher.NonCapturingPredicate<Thread, Void>() { @Override public boolean test(Thread thread, Void state) { return thread.getId() == Thread.currentThread().getId(); } }, null, new ThreadMatcher.NonCapturingConsumer<Thread, List<Thread>>() { @Override public void accept(Thread thread, List<Thread> state) { state.add(thread); } }, threads); assertThat(threads).isEqualTo(List.of(Thread.currentThread())); }