/** * For every element, invoke the given callback. * Stops if {@link CallbackRefusedException} is thrown. */ @SafeVarargs public static <T> void stream(Callback<T> callback, T... items) throws Exception { stream(callback, Arrays.asList(items)); }
@Test public void testCallbackRefused() throws Exception { final List<Collection<String>> items = Lists.newArrayList(); Callback<Collection<String>> callback = new Callback<Collection<String>>() { @Override public void call(Collection<String> item) throws Exception { if (items.size() > 1) { throw new CallbackRefusedException(); } items.add(item); } }; try (BatchingCallback<String> batcher = BatchingCallback.<String>batchInto(2, callback)) { Callbacks.stream(batcher, "a", "b", "c", "d", "e", "f", "g"); } assertEquals(of( of("a", "b"), of("c", "d") ), items); } }