### Question:
ThresholdReQueuePolicy implements ReQueuePolicy { @Override public boolean canReQueue(Message message) { Map<String, Object> headers = message.getMessageProperties().getHeaders(); int requeueCount = 0; if (headers.containsKey(X_REQUEUE_COUNT)) { requeueCount = (int) headers.get(X_REQUEUE_COUNT); } if (threshold > requeueCount) { headers.put(X_REQUEUE_COUNT, ++requeueCount); return true; } return false; }  @Override boolean canReQueue(Message message);  }### Answer:
@Test public void shouldReQueueForAnyNewMessage() throws Exception { assertTrue(thresholdReQueuePolicy.canReQueue(message)); assertThat(message.getMessageProperties().getHeaders().get("x-requeue-count"), equalTo(1)); }
@Test public void shouldReQueueRequeueCountIsLessThanThreshold() throws Exception { message.getMessageProperties().getHeaders().put("x-requeue-count", 1); assertTrue(thresholdReQueuePolicy.canReQueue(message)); assertThat(message.getMessageProperties().getHeaders().get("x-requeue-count"), equalTo(2)); }
@Test public void shouldNotReQueueRequeueCountIsEqualToThreshold() throws Exception { message.getMessageProperties().getHeaders().put("x-requeue-count", 3); assertFalse(thresholdReQueuePolicy.canReQueue(message)); assertThat(message.getMessageProperties().getHeaders().get("x-requeue-count"), equalTo(3)); }
@Test public void shouldNotReQueueRequeueCountIsGreaterThanOrEqualToThreshold() throws Exception { message.getMessageProperties().getHeaders().put("x-requeue-count", 3); assertFalse(thresholdReQueuePolicy.canReQueue(message)); assertThat(message.getMessageProperties().getHeaders().get("x-requeue-count"), equalTo(3)); }