ProducerImpl implements Producer { @Override public void produce(Message message) { try { String realQueueName = getRealQueueName(queueName, message.getCloudType()); LOG.trace("Putting message {} to queue \"{}\"", message, realQueueName); if (!storage.isAvailable()) { LOG.trace("Storage is not available. Will not put {} to queue {}.", message, realQueueName); return; } BlockingQueue<Object> queue = storage.getQueue(realQueueName); queue.put(message); } catch (Exception e) { LOG.error(String.format("Failed to put message to queue \"%s\"", queueName), e); } } ProducerImpl(String queueName, Storage storage); @Override void produce(Message message); String getQueueName();  }
@Test public void testProduce() throws Exception { Storage storage = new TestStorage(); Producer producer = new ProducerImpl(QUEUE_NAME, storage); Message msg = message(CloudType.MOCK, PAYLOAD); producer.produce(msg); BlockingQueue<Object> queue = storage.getQueue(getRealQueueName(QUEUE_NAME, CloudType.MOCK)); Object data = queue.poll(1, TimeUnit.SECONDS); assertThat(data, is(notNullValue())); assertThat(data, is(instanceOf(Message.class))); Message receivedMsg = (Message) data; assertThat(msg.getId(), equalTo(receivedMsg.getId())); assertThat(msg.getCloudType(), equalTo(receivedMsg.getCloudType())); assertThat(msg.getPayload(), equalTo(receivedMsg.getPayload())); }