### Question:
Producer { public void produce() throws InterruptedException { Item item = new Item(name, itemId++); queue.put(item); Random random = new Random(); Thread.sleep(random.nextInt(2000)); } Producer(String name, ItemQueue queue); void produce();  }### Answer:
@Test public void testProduce() { assertTimeout(ofMillis(6000), () -> { final ItemQueue queue = mock(ItemQueue.class); final Producer producer = new Producer("producer", queue); producer.produce(); verify(queue).put(any(Item.class)); verifyNoMoreInteractions(queue); }); }
@Test public void testProduce() throws Exception { assertTimeout(ofMillis(6000), () -> { final ItemQueue queue = mock(ItemQueue.class); final Producer producer = new Producer("producer", queue); producer.produce(); verify(queue).put(any(Item.class)); verifyNoMoreInteractions(queue); }); }