@Test public void rxGetForSuccess() 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); MyApiRx myApi = new Wasp.Builder(context) .setEndpoint(server.url("/v1").toString()) .setNetworkStack(VolleyNetworkStack.newInstance(requestQueue)) .build() .create(MyApiRx.class); Observable<User> observable = myApi.getUser(); assertThat(observable).isNotNull(); final CountDownLatch latch = new CountDownLatch(1); observable .subscribeOn(Schedulers.io()) .observeOn(Schedulers.from(executor)) .subscribe(new Observer<User>() { @Override public void onCompleted() { latch.countDown(); } @Override public void onError(Throwable e) { fail("should fail"); } @Override public void onNext(User user) { assertThat(user).isNotNull(); assertThat(user.name).isEqualTo("Hello"); } }); RecordedRequest request = server.takeRequest(); assertThat(request.getPath()).isEqualTo("/v1/user"); assertTrue(latch.await(TIMEOUT, TimeUnit.SECONDS)); }
@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);  }