### Question:
ArgsToPagedIterable implements
      Function<IterableWithMarker<T>, PagedIterable<T>>, InvocationContext<I> { @Override public PagedIterable<T> apply(IterableWithMarker<T> input) { return input.nextMarker().isPresent() ? advance(input, markerToNextForArgs(getArgs(request))) : onlyPage(input); }  @Override PagedIterable<T> apply(IterableWithMarker<T> input); @SuppressWarnings("unchecked") @Override I setContext(HttpRequest request);  }### Answer:
@Test public void testWhenNextMarkerAbsentDoesntAdvance() { GeneratedHttpRequest request = args(ImmutableList.of()); TestArgs converter = new TestArgs(request) { @Override protected Function<Object, IterableWithMarker<String>> markerToNextForArgs(List<Object> args) { fail("The Iterable should not advance"); return null; } }; assertEquals(converter.apply(IterableWithMarkers.from(ImmutableSet.of("foo", "bar"))).concat().toSet(), ImmutableSet.of("foo", "bar")); }
@Test public void testWhenNextMarkerPresentButNoArgsMarkerToNextForArgsParamIsAbsent() { GeneratedHttpRequest request = args(ImmutableList.of()); final IterableWithMarker<String> next = IterableWithMarkers.from(ImmutableSet.of("baz")); TestArgs converter = new TestArgs(request) { @Override protected Function<Object, IterableWithMarker<String>> markerToNextForArgs(List<Object> args) { assertTrue(args.isEmpty()); return Functions.constant(next); } }; assertEquals(converter.apply(IterableWithMarkers.from(ImmutableSet.of("foo", "bar"), "marker")).concat().toSet(), ImmutableSet.of("foo", "bar", "baz")); }
@Test public void testWhenNextMarkerPresentWithArgsMarkerToNextForArgsParamIsPresent() { GeneratedHttpRequest request = args(ImmutableList.<Object> of("path")); final IterableWithMarker<String> next = IterableWithMarkers.from(ImmutableSet.of("baz")); TestArgs converter = new TestArgs(request) { @Override protected Function<Object, IterableWithMarker<String>> markerToNextForArgs(List<Object> args) { assertEquals(args.get(0), "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 testFromCallerWhenNextMarkerPresentButNoArgsMarkerToNextForArgsParamIsAbsent() { GeneratedHttpRequest request = callerArgs(ImmutableList.of()); final IterableWithMarker<String> next = IterableWithMarkers.from(ImmutableSet.of("baz")); TestCallerArgs converter = new TestCallerArgs(request) { @Override protected Function<Object, IterableWithMarker<String>> markerToNextForArgs(List<Object> args) { assertTrue(args.isEmpty()); return Functions.constant(next); } }; assertEquals(converter.apply(IterableWithMarkers.from(ImmutableSet.of("foo", "bar"), "marker")).concat().toSet(), ImmutableSet.of("foo", "bar", "baz")); }
@Test public void testFromCallerWhenNextMarkerPresentWithArgsMarkerToNextForArgsParamIsPresent() { GeneratedHttpRequest request = callerArgs(ImmutableList.<Object> of("path")); final IterableWithMarker<String> next = IterableWithMarkers.from(ImmutableSet.of("baz")); TestCallerArgs converter = new TestCallerArgs(request) { @Override protected Function<Object, IterableWithMarker<String>> markerToNextForArgs(List<Object> args) { assertEquals(args.get(0), "path"); return Functions.constant(next); } }; assertEquals(converter.apply(IterableWithMarkers.from(ImmutableSet.of("foo", "bar"), "marker")).concat().toSet(), ImmutableSet.of("foo", "bar", "baz")); }