QueueFile implements Closeable, Iterable<byte[]> { @Override public Iterator<byte[]> iterator() { return new ElementIterator(); } QueueFile(File file, RandomAccessFile raf, boolean zero, boolean forceLegacy); void add(byte[] data); void add(byte[] data, int offset, int count); boolean isEmpty(); @Nullable byte[] peek(); @Override Iterator<byte[]> iterator(); int size(); void remove(); void remove(int n); void clear(); File file(); @Override void close(); @Override String toString();  }
@Test public void testIterator() throws IOException { byte[] data = values[10]; for (int i = 0; i < 10; i++) { QueueFile queueFile = newQueueFile(); for (int j = 0; j < i; j++) { queueFile.add(data); } int saw = 0; for (byte[] element : queueFile) { assertThat(element).isEqualTo(data); saw++; } assertThat(saw).isEqualTo(i); queueFile.close(); file.delete(); } }
@Test public void testIteratorNextThrowsWhenEmpty() throws IOException { QueueFile queueFile = newQueueFile(); Iterator<byte[]> iterator = queueFile.iterator(); try { iterator.next(); fail(); } catch (NoSuchElementException ignored) { } }