SplitHandler implements SampleVisitor<T> { @Override public List<? extends T> visit(T input) { checkInit(); List<? extends T> split = splitter.split(input); if (split.size() != segments) throw new IllegalStateException("required " + segments + ", found " + split.size() + ": " + split); recycleBin.clear(); for (int i = 0; i < segments; ++i) { T segment = split.get(i); SegmentBuffer<T> buffer = buffers.get(i); T prev = buffer.last(); int count = buffer.put(segment, recycleBin); if (count > 0) { handle(i, prev, count); } } return recycleBin; } SplitHandler(Splitter<T> splitter); @Override void init(); @Override void finish(); @Override List<? extends T> visit(T input);  }
@Test(expected = IllegalStateException.class) public void visitBeforeInit() { ToArraySplitHandler handler = new ToArraySplitHandler(new BucketTestUtils.SingletonSplitter<String>()); handler.visit("foo"); }