### Question:
AMQPConsumer extends AMQPWorker { public GetResponse consume() { try { return this.channel.basicGet(this.queueName, true); } catch (IOException e) { logger.error("Failed to receive message from AMQP; " + this + ". Possible reasons: Queue '" + this.queueName + "' may not have been defined", e); throw new ProcessException(e); } } AMQPConsumer(Connection connection, String queueName); GetResponse consume(); @Override String toString();  }### Answer:
@Test(expected = ProcessException.class) public void failOnNonExistingQueue() throws Exception { Connection conn = new TestConnection(null, null); try (AMQPConsumer consumer = new AMQPConsumer(conn, "hello")) { consumer.consume(); } }
@Test public void validateSuccessfullConsumeWithEmptyQueueDefaultExchange() throws Exception { Map<String, List<String>> routingMap = new HashMap<>(); routingMap.put("queue1", Arrays.asList("queue1")); Map<String, String> exchangeToRoutingKeymap = new HashMap<>(); exchangeToRoutingKeymap.put("", "queue1"); Connection conn = new TestConnection(exchangeToRoutingKeymap, routingMap); try (AMQPConsumer consumer = new AMQPConsumer(conn, "queue1")) { GetResponse response = consumer.consume(); assertNull(response); } }
@Test public void validateSuccessfullConsumeWithEmptyQueue() throws Exception { Map<String, List<String>> routingMap = new HashMap<>(); routingMap.put("key1", Arrays.asList("queue1")); Map<String, String> exchangeToRoutingKeymap = new HashMap<>(); exchangeToRoutingKeymap.put("myExchange", "key1"); Connection conn = new TestConnection(exchangeToRoutingKeymap, routingMap); conn.createChannel().basicPublish("myExchange", "key1", null, "hello Joe".getBytes()); try (AMQPConsumer consumer = new AMQPConsumer(conn, "queue1")) { GetResponse response = consumer.consume(); assertNotNull(response); } }