Arg0ToPagedIterable implements
      Function<IterableWithMarker<T>, PagedIterable<T>>, InvocationContext<I> { @Override public PagedIterable<T> apply(IterableWithMarker<T> input) { if (!input.nextMarker().isPresent()) return onlyPage(input); List<Object> args = getArgs(request); Optional<Object> arg0 = Optional.fromNullable(args.size() > 0 ? args.get(0) : null); return advance(input, markerToNextForArg0(arg0)); }  @Override PagedIterable<T> apply(IterableWithMarker<T> input); @SuppressWarnings("unchecked") @Override I setContext(HttpRequest request);  }
@Test public void testWhenNextMarkerAbsentDoesntAdvance() { GeneratedHttpRequest request = args(ImmutableList.of()); TestArg0 converter = new TestArg0(request) { @Override protected Function<Object, IterableWithMarker<String>> markerToNextForArg0(Optional<Object> arg0) { fail(); return null; } }; assertEquals(converter.apply(IterableWithMarkers.from(ImmutableSet.of("foo", "bar"))).concat().toSet(), ImmutableSet.of("foo", "bar")); }
@Test public void testWhenNextMarkerPresentButNoArgsMarkerToNextForArg0ParamIsAbsent() { GeneratedHttpRequest request = args(ImmutableList.of()); final IterableWithMarker<String> next = IterableWithMarkers.from(ImmutableSet.of("baz")); TestArg0 converter = new TestArg0(request) { @Override protected Function<Object, IterableWithMarker<String>> markerToNextForArg0(Optional<Object> arg0) { assertEquals(arg0, Optional.absent()); return Functions.constant(next); } }; assertEquals(converter.apply(IterableWithMarkers.from(ImmutableSet.of("foo", "bar"), "marker")).concat().toSet(), ImmutableSet.of("foo", "bar", "baz")); }
@Test public void testWhenNextMarkerPresentWithArgsMarkerToNextForArg0ParamIsPresent() { GeneratedHttpRequest request = args(ImmutableList.<Object> of("path")); final IterableWithMarker<String> next = IterableWithMarkers.from(ImmutableSet.of("baz")); TestArg0 converter = new TestArg0(request) { @Override protected Function<Object, IterableWithMarker<String>> markerToNextForArg0(Optional<Object> arg0) { assertEquals(arg0, Optional.of("path")); return Functions.constant(next); } }; assertEquals(converter.apply(IterableWithMarkers.from(ImmutableSet.of("foo", "bar"), "marker")).concat().toSet(), ImmutableSet.of("foo", "bar", "baz")); }
@Test public void testFromCallerWhenNextMarkerPresentButNoArgsMarkerToNextForArg0ParamIsAbsent() { GeneratedHttpRequest request = callerArgs(ImmutableList.of()); final IterableWithMarker<String> next = IterableWithMarkers.from(ImmutableSet.of("baz")); TestCallerArg0 converter = new TestCallerArg0(request) { @Override protected Function<Object, IterableWithMarker<String>> markerToNextForArg0(Optional<Object> arg0) { assertEquals(arg0, Optional.absent()); return Functions.constant(next); } }; assertEquals(converter.apply(IterableWithMarkers.from(ImmutableSet.of("foo", "bar"), "marker")).concat().toSet(), ImmutableSet.of("foo", "bar", "baz")); }
@Test public void testFromCallerWhenNextMarkerPresentWithArgsMarkerToNextForArg0ParamIsPresent() { GeneratedHttpRequest request = callerArgs(ImmutableList.<Object> of("path")); final IterableWithMarker<String> next = IterableWithMarkers.from(ImmutableSet.of("baz")); TestCallerArg0 converter = new TestCallerArg0(request) { @Override protected Function<Object, IterableWithMarker<String>> markerToNextForArg0(Optional<Object> arg0) { assertEquals(arg0, Optional.of("path")); return Functions.constant(next); } }; assertEquals(converter.apply(IterableWithMarkers.from(ImmutableSet.of("foo", "bar"), "marker")).concat().toSet(), ImmutableSet.of("foo", "bar", "baz")); }