@Test public void syncGetForSuccess() throws Exception { MockResponse response = new MockResponse() .addHeader("Content-Type", "application/json; charset=utf-8") .setBody("{\n" + " \"no\": 123,\n" + " \"name\": \"Hello\"\n" + "}"); server.enqueue(response); MyApiSync myApi = new Wasp.Builder(context) .setEndpoint(server.url("/v1").toString()) .setNetworkStack(VolleyNetworkStack.newInstance(requestQueue)) .build() .create(MyApiSync.class); User user = myApi.getUser(); assertThat(user).isNotNull(); assertThat(user.name).isEqualTo("Hello"); RecordedRequest request = server.takeRequest(); assertThat(request.getPath()).isEqualTo("/v1/user"); verify(executor).execute(any(Runnable.class)); verifyNoMoreInteractions(executor); }
@SuppressWarnings("unchecked") public <T> T create(Class<T> service) { if (service == null) { throw new NullPointerException("service param may not be null"); } if (!service.isInterface()) { throw new IllegalArgumentException("Only interface type is supported"); } NetworkHandler handler = NetworkHandler.newInstance(service, builder); return (T) handler.getProxyClass(); }
Wasp { @SuppressWarnings("unchecked") public <T> T create(Class<T> service) { if (service == null) { throw new NullPointerException("service param may not be null"); } if (!service.isInterface()) { throw new IllegalArgumentException("Only interface type is supported"); } NetworkHandler handler = NetworkHandler.newInstance(service, builder); return (T) handler.getProxyClass(); } }
Wasp { @SuppressWarnings("unchecked") public <T> T create(Class<T> service) { if (service == null) { throw new NullPointerException("service param may not be null"); } if (!service.isInterface()) { throw new IllegalArgumentException("Only interface type is supported"); } NetworkHandler handler = NetworkHandler.newInstance(service, builder); return (T) handler.getProxyClass(); } private  Wasp(Builder builder); }
Wasp { @SuppressWarnings("unchecked") public <T> T create(Class<T> service) { if (service == null) { throw new NullPointerException("service param may not be null"); } if (!service.isInterface()) { throw new IllegalArgumentException("Only interface type is supported"); } NetworkHandler handler = NetworkHandler.newInstance(service, builder); return (T) handler.getProxyClass(); } private  Wasp(Builder builder); static Parser getParser(); @SuppressWarnings("unchecked") T create(Class<T> service); }
Wasp { @SuppressWarnings("unchecked") public <T> T create(Class<T> service) { if (service == null) { throw new NullPointerException("service param may not be null"); } if (!service.isInterface()) { throw new IllegalArgumentException("Only interface type is supported"); } NetworkHandler handler = NetworkHandler.newInstance(service, builder); return (T) handler.getProxyClass(); } private  Wasp(Builder builder); static Parser getParser(); @SuppressWarnings("unchecked") T create(Class<T> service);  }