public static void main(String... args) throws IOException {
// Create our Service instance with a SuperVolley pointing at the local web server and Gson.
SuperVolley volley = new SuperVolley.Builder()
.baseUrl(Constants.API_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
// Create a MockSuperVolley object with a NetworkBehavior which manages the fake behavior of calls.
NetworkBehavior behavior = NetworkBehavior.create();
MockSuperVolley mockSuperVolley = new MockSuperVolley.Builder(volley)
.networkBehavior(behavior)
.build();
BehaviorDelegate<Service> delegate = mockSuperVolley.create(Service.class);
MockService service = new MockService(delegate);
Call<Void> call = service.getUser();
Response<Void> response = call.execute();
// Normally you would check response.isSuccess() here before doing the following, but we know
// this call will always fail. You could also use response.code() to determine whether to
// convert the error body and/or which type to use for conversion.
// Look up a converter for the Error type on the SuperVolley instance.
Converter<ResponseBody, Error> errorConverter =
volley.responseBodyConverter(Error.class, new Annotation[0]);
// Convert the error body into our Error type.
Error error = errorConverter.convert(response.errorBody());
System.out.println("ERROR: " + error.message);
}
DeserializeErrorBody.java 文件源码
java
阅读 35
收藏 0
点赞 0
评论 0
项目:super-volley
作者:
评论列表
文章目录