@Override
    public @Nonnull Mail take(int priority) throws InterruptedException, IllegalStateException {
        checkIsMailboxThread();
        checkTakeStateConditions();
        Mail head = takeOrNull(batch, priority);
        if (head != null) {
            return head;
        }
        final ReentrantLock lock = this.lock;
        lock.lockInterruptibly();
        try {
            Mail headMail;
            while ((headMail = takeOrNull(queue, priority)) == null) {
                // to ease debugging
                notEmpty.await(1, TimeUnit.SECONDS);
            }
            hasNewMail = !queue.isEmpty();
            return headMail;
        } finally {
            lock.unlock();
        }
    }
@Test
    void testConcurrentPutTakeBlocking() throws Exception {
        testPutTake(mailbox -> mailbox.take(DEFAULT_PRIORITY));
    }