我想模拟MockWebServer的网络通信.不幸的改造回调永远不会被调用.我的代码:
MockWebServer server = new MockWebServer(); server.enqueue(new MockResponse().setResponseCode(200).setBody("{}")); server.play(); RestAdapter restAdapter = new RestAdapter.Builder().setConverter(new MyGsonConverter(new Gson())) .setEndpoint(server.getUrl("/").toString()).build(); restAdapter.create(SearchService.class).getCount(StringUtils.EMPTY,new Callback<CountContainer>() { @Override public void success(CountContainer countContainer,Response response) { System.out.println("success"); } @Override public void failure(RetrofitError error) { System.out.println("error"); } }); server.shutdown();
当我在没有回调的情况下使用改装时,它可以工作.