### Question:
Producer { public void stop() { isStopped = true; try { queue.put(Message.POISON_PILL); } catch (InterruptedException e) { LOGGER.error("Exception caught.", e); } } Producer(String name, MqPublishPoint queue); void send(String body); void stop();  }### Answer:
@Test public void testStop() throws Exception { final var publishPoint = mock(MqPublishPoint.class); final var producer = new Producer("producer", publishPoint); verifyZeroInteractions(publishPoint); producer.stop(); verify(publishPoint).put(eq(Message.POISON_PILL)); try { producer.send("Hello!"); fail("Expected 'IllegalStateException' at this point, since the producer has stopped!"); } catch (IllegalStateException e) { assertNotNull(e); assertNotNull(e.getMessage()); assertEquals("Producer Hello! was stopped and fail to deliver requested message [producer].", e.getMessage()); } verifyNoMoreInteractions(publishPoint); }
@Test public void testStop() throws Exception { final MqPublishPoint publishPoint = mock(MqPublishPoint.class); final Producer producer = new Producer("producer", publishPoint); verifyZeroInteractions(publishPoint); producer.stop(); verify(publishPoint).put(eq(Message.POISON_PILL)); try { producer.send("Hello!"); fail("Expected 'IllegalStateException' at this point, since the producer has stopped!"); } catch (IllegalStateException e) { assertNotNull(e); assertNotNull(e.getMessage()); assertEquals("Producer Hello! was stopped and fail to deliver requested message [producer].", e.getMessage()); } verifyNoMoreInteractions(publishPoint); }