### Question:
TopContenders implements SingleThreadSetQuery<TopContenders.Result<?, ?, ?>> { @Override public @Nonnull < SetType extends ThreadSet<SetType, RuntimeType, ThreadType>, RuntimeType extends ProcessRuntime<RuntimeType, SetType, ThreadType>, ThreadType extends ProcessThread<ThreadType, SetType, RuntimeType> > Result<SetType, RuntimeType, ThreadType> query(SetType threads) { return new Result<SetType, RuntimeType, ThreadType>(threads, showStackTraces); }  TopContenders showStackTraces(); @Override @Nonnull Result<SetType, RuntimeType, ThreadType> query(SetType threads);  }### Answer:
@Test public void trivial() throws Exception { ThreadDumpRuntime runtime = new ThreadDumpFactory().fromStream(Util.resource("jstack/producer-consumer.log")); TopContenders.Result<ThreadDumpThreadSet, ThreadDumpRuntime, ThreadDumpThread> contenders = new TopContenders().query(runtime.getThreads()); final ThreadDumpThread owning = runtime.getThreads().where(nameIs("owning_thread")).onlyThread(); assertThat(contenders.getBlockers().size(), equalTo(1)); assertThat(contenders.blockedBy(owning), equalTo(runtime.getThreads().where(nameIs("blocked_thread")))); }
@Test public void contenders() throws Exception { ThreadDumpRuntime runtime = new ThreadDumpFactory().fromStream(Util.resource("jstack/contention.log")); TopContenders.Result<ThreadDumpThreadSet, ThreadDumpRuntime, ThreadDumpThread> contenders = new TopContenders().query(runtime.getThreads()); ThreadDumpThreadSet ts = runtime.getThreads(); final ThreadDumpThread producerProcessThread = ts.where(nameIs("producer")).onlyThread(); assertThat(contenders.getBlockers().size(), equalTo(1)); assertThat(contenders.blockedBy(producerProcessThread).size(), equalTo(3)); }