Example usage for java.util Collections emptyIterator

List of usage examples for java.util Collections emptyIterator

Introduction

In this page you can find the example usage for java.util Collections emptyIterator.

Prototype

@SuppressWarnings("unchecked")
public static <T> Iterator<T> emptyIterator() 

Source Link

Document

Returns an iterator that has no elements.

Usage

From source file:org.sonar.server.issue.index.IssueIndexerTest.java

@Test
public void index_nothing() {
    underTest.index(Collections.emptyIterator());

    assertThat(esTester.countDocuments(IssueIndexDefinition.INDEX_TYPE_ISSUE)).isEqualTo(0L);
}

From source file:org.springframework.ws.transport.http.AbstractHttpSenderConnectionTest.java

/**
 * Tests that {@link AbstractHttpSenderConnection} doesn't consume the response stream before
 * passing it to the message factory. This is a regression test for SWS-707.
 *
 * @param chunking//from   w  w  w .j  ava2  s .c o m
 *            Specifies whether the test should simulate a response with chunking enabled.
 * @throws Exception
 */
private void testSupportsStreaming(boolean chunking) throws Exception {
    byte[] content = new byte[16 * 1024];
    new Random().nextBytes(content);
    CountingInputStream rawInputStream = new CountingInputStream(new ByteArrayInputStream(content));

    AbstractHttpSenderConnection connection = createNiceMock(AbstractHttpSenderConnection.class);
    expect(connection.getResponseCode()).andReturn(200);
    // Simulate response with chunking enabled
    expect(connection.getResponseContentLength()).andReturn(chunking ? -1L : content.length);
    expect(connection.getRawResponseInputStream()).andReturn(rawInputStream);
    expect(connection.getResponseHeaders(anyObject())).andReturn(Collections.emptyIterator());

    // Create a mock message factory to capture the InputStream passed to it
    WebServiceMessageFactory messageFactory = createNiceMock(WebServiceMessageFactory.class);
    WebServiceMessage message = createNiceMock(WebServiceMessage.class);
    Capture<InputStream> inputStreamCapture = new Capture<>();
    expect(messageFactory.createWebServiceMessage(capture(inputStreamCapture))).andReturn(message);

    replay(connection, messageFactory, message);

    connection.receive(messageFactory);

    assertTrue("The raw input stream has been completely consumed", rawInputStream.getCount() < content.length);
    assertArrayEquals("Unexpected content received by the message factory", content,
            IOUtils.toByteArray(inputStreamCapture.getValue()));
}

From source file:org.wso2.carbon.analytics.datasource.hbase.HBaseRecordIterator.java

@Override
public boolean hasNext() {
    boolean hasMore = this.subIterator.hasNext();
    if (!hasMore) {
        try {/*from  w  ww . j  av  a2 s . c o  m*/
            this.fetch();
        } catch (AnalyticsTableNotAvailableException e) {
            this.subIterator = Collections.emptyIterator();
        }
    }
    return this.subIterator.hasNext();
}

From source file:org.wso2.carbon.analytics.datasource.hbase.HBaseTimestampIterator.java

@Override
public boolean hasNext() {
    boolean hasMore = this.subIterator.hasNext();
    if (!hasMore) {
        try {/*  www.  j av a2 s . c  o m*/
            this.fetchRecords();
        } catch (AnalyticsTableNotAvailableException e) {
            this.subIterator = Collections.emptyIterator();
        }
    }
    return this.subIterator.hasNext();
}