public StubConnection awaitConnection() throws InterruptedException {
        lock.lock();
        try {
            while (list.isEmpty()) {
                notEmpty.await();
            }
            return list.remove(0);
        } finally {
            lock.unlock();
        }
    }