SQS { public static FluentIterable<Message> receiveAllAtRate(MessageApi api, int messagesPerPage, ReceiveMessageOptions options) { return AdvanceUntilEmptyIterable.create(new MoreMessages(api, messagesPerPage, options)).concat(); }  static FluentIterable<Message> receiveAllAtRate(MessageApi api, int messagesPerPage,
         ReceiveMessageOptions options);  }
@Test public void testSinglePageResult() throws Exception { MessageApi messageClient = createMock(MessageApi.class); ReceiveMessageOptions options = new ReceiveMessageOptions(); FluentIterable<Message> aMessage = FluentIterable.from(ImmutableSet.of(createMock(Message.class))); FluentIterable<Message> noMessages = FluentIterable.from(ImmutableSet.<Message>of()); expect(messageClient.receive(1, options)) .andReturn(aMessage) .once(); expect(messageClient.receive(1, options)) .andReturn(noMessages) .once(); EasyMock.replay(messageClient); Assert.assertEquals(1, Iterables.size(SQS.receiveAllAtRate(messageClient, 1, options))); }
@Test public void testMultiPageResult() throws Exception { MessageApi messageClient = createMock(MessageApi.class); ReceiveMessageOptions options = new ReceiveMessageOptions(); FluentIterable<Message> aMessage = FluentIterable.from(ImmutableSet.of(createMock(Message.class))); FluentIterable<Message> noMessages = FluentIterable.from(ImmutableSet.<Message>of()); expect(messageClient.receive(1, options)) .andReturn(aMessage) .times(2); expect(messageClient.receive(1, options)) .andReturn(noMessages) .once(); EasyMock.replay(messageClient); Assert.assertEquals(2, Iterables.size(SQS.receiveAllAtRate(messageClient, 1, options))); }