### Question:
SqsQueueResource { public List<Message> receiveMessages() throws AmazonClientException { return doReceiveRequest(new ReceiveMessageRequest(queueUrl)); } SqsQueueResource(final String queueName, final String queueUrl, final AmazonSQS amazonSqsClient); void sendMessage(final String messageBody); void sendDelayedMessage(final String messageBody, final int delaySeconds); List<Message> receiveMessages(); List<Message> receiveMessages(final int waitTimeSeconds, final int maxMessages); void deleteMessage(final String receiptHandle); void setPolicy(final Policy policy); String queueArn(); String getQueueName();  }### Answer:
@Test public void shouldReceiveMessages() { final List<Message> mockReceivedMessages = mock(List.class); final ReceiveMessageResult mockReceiveMessageResponse = mock(ReceiveMessageResult.class); when(mockReceiveMessageResponse.getMessages()).thenReturn(mockReceivedMessages); final ArgumentCaptor<ReceiveMessageRequest> captor = ArgumentCaptor.forClass(ReceiveMessageRequest.class); when(amazonSqsClient.receiveMessage(captor.capture())).thenReturn(mockReceiveMessageResponse); final List<Message> actualReceivedMessages = sqsQueueResource.receiveMessages(); assertSame(mockReceivedMessages, actualReceivedMessages); final ReceiveMessageRequest receiveMessageRequest = captor.getValue(); assertEquals(queueUrl, receiveMessageRequest.getQueueUrl()); assertNull(receiveMessageRequest.getWaitTimeSeconds()); assertNull(receiveMessageRequest.getMaxNumberOfMessages()); }
@Test public void shouldThrowException_onExceptionForReceiveMessages() { doThrow(AmazonClientException.class).when(amazonSqsClient).receiveMessage(any(ReceiveMessageRequest.class)); AmazonClientException thrownException = null; try { sqsQueueResource.receiveMessages(); } catch (final AmazonClientException e) { thrownException = e; } assertNotNull(thrownException); }
@Test public void shouldReceiveMessages_withWaitTimeAndMaxMessagesParameters() { final int waitTimeSeconds = randomInt(20); final int maxMessages = 1 + randomInt(10); final List<Message> mockReceivedMessages = mock(List.class); final ReceiveMessageResult mockReceiveMessageResponse = mock(ReceiveMessageResult.class); when(mockReceiveMessageResponse.getMessages()).thenReturn(mockReceivedMessages); final ArgumentCaptor<ReceiveMessageRequest> captor = ArgumentCaptor.forClass(ReceiveMessageRequest.class); when(amazonSqsClient.receiveMessage(captor.capture())).thenReturn(mockReceiveMessageResponse); final List<Message> actualReceivedMessages = sqsQueueResource.receiveMessages(waitTimeSeconds, maxMessages); assertSame(mockReceivedMessages, actualReceivedMessages); final ReceiveMessageRequest receiveMessageRequest = captor.getValue(); assertEquals(queueUrl, receiveMessageRequest.getQueueUrl()); assertEquals(new Integer(waitTimeSeconds), receiveMessageRequest.getWaitTimeSeconds()); assertEquals(new Integer(maxMessages), receiveMessageRequest.getMaxNumberOfMessages()); }
@Test public void shouldThrowException_onExceptionForReceiveMessagesWithParameters() { doThrow(AmazonClientException.class).when(amazonSqsClient).receiveMessage(any(ReceiveMessageRequest.class)); final int waitTimeSeconds = randomInt(20); final int maxMessages = 1 + randomInt(10); AmazonClientException thrownException = null; try { sqsQueueResource.receiveMessages(waitTimeSeconds, maxMessages); } catch (final AmazonClientException e) { thrownException = e; } assertNotNull(thrownException); }