@Test public void testSend() throws Exception { final MqPublishPoint publishPoint = mock(MqPublishPoint.class); final Producer producer = new Producer("producer", publishPoint); verifyZeroInteractions(publishPoint); producer.send("Hello!"); final ArgumentCaptor<Message> messageCaptor = ArgumentCaptor.forClass(Message.class); verify(publishPoint).put(messageCaptor.capture()); final Message message = messageCaptor.getValue(); assertNotNull(message); assertEquals("producer", message.getHeader(Message.Headers.SENDER)); assertNotNull(message.getHeader(Message.Headers.DATE)); assertEquals("Hello!", message.getBody()); verifyNoMoreInteractions(publishPoint); }
public void send(String body) { if (isStopped) { throw new IllegalStateException(String.format( "Producer %s was stopped and fail to deliver requested message [%s].", body, name)); } Message msg = new SimpleMessage(); msg.addHeader(Headers.DATE, new Date().toString()); msg.addHeader(Headers.SENDER, name); msg.setBody(body); try { queue.put(msg); } catch (InterruptedException e) { LOGGER.error("Exception caught.", e); } }
Producer { public void send(String body) { if (isStopped) { throw new IllegalStateException(String.format( "Producer %s was stopped and fail to deliver requested message [%s].", body, name)); } Message msg = new SimpleMessage(); msg.addHeader(Headers.DATE, new Date().toString()); msg.addHeader(Headers.SENDER, name); msg.setBody(body); try { queue.put(msg); } catch (InterruptedException e) { LOGGER.error("Exception caught.", e); } } }
Producer { public void send(String body) { if (isStopped) { throw new IllegalStateException(String.format( "Producer %s was stopped and fail to deliver requested message [%s].", body, name)); } Message msg = new SimpleMessage(); msg.addHeader(Headers.DATE, new Date().toString()); msg.addHeader(Headers.SENDER, name); msg.setBody(body); try { queue.put(msg); } catch (InterruptedException e) { LOGGER.error("Exception caught.", e); } } Producer(String name, MqPublishPoint queue); }
Producer { public void send(String body) { if (isStopped) { throw new IllegalStateException(String.format( "Producer %s was stopped and fail to deliver requested message [%s].", body, name)); } Message msg = new SimpleMessage(); msg.addHeader(Headers.DATE, new Date().toString()); msg.addHeader(Headers.SENDER, name); msg.setBody(body); try { queue.put(msg); } catch (InterruptedException e) { LOGGER.error("Exception caught.", e); } } Producer(String name, MqPublishPoint queue); void send(String body); void stop(); }
Producer { public void send(String body) { if (isStopped) { throw new IllegalStateException(String.format( "Producer %s was stopped and fail to deliver requested message [%s].", body, name)); } Message msg = new SimpleMessage(); msg.addHeader(Headers.DATE, new Date().toString()); msg.addHeader(Headers.SENDER, name); msg.setBody(body); try { queue.put(msg); } catch (InterruptedException e) { LOGGER.error("Exception caught.", e); } } Producer(String name, MqPublishPoint queue); void send(String body); void stop();  }