BindIdsToQueryParams implements Binder { @SuppressWarnings("unchecked") @Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { if (checkNotNull(input, "input is null") instanceof Long[]) { Long[] names = (Long[]) input; return (R) request.toBuilder() .replaceQueryParam(ID_KEY, transform(ImmutableList.copyOf(names), toStringFunction())).build(); } else if (input instanceof long[]) { long[] names = (long[]) input; return (R) request.toBuilder().replaceQueryParam(ID_KEY, transform(Longs.asList(names), toStringFunction())) .build(); } else { throw new IllegalArgumentException("this binder is only valid for Long[] arguments: " + input.getClass()); } }  @SuppressWarnings("unchecked") @Override R bindToRequest(R request, Object input);  }
@Test public void testWithView() throws SecurityException, NoSuchMethodException { HttpRequest request = HttpRequest.builder().method("GET").endpoint("http: BindIdsToQueryParams binder = new BindIdsToQueryParams(); request = binder.bindToRequest(request, new Long[] { 123L, 456L }); assertEquals(request.getRequestLine(), "GET http: }
@Test public void testWithPrimitive() { HttpRequest request = HttpRequest.builder().method("GET").endpoint("http: BindIdsToQueryParams binder = new BindIdsToQueryParams(); request = binder.bindToRequest(request, new long[] { 123L, 456L }); assertEquals(request.getRequestLine(), "GET http: }