我正在为有一行的活动创建测试:
Logger.i("Response", new Gson().toJson(response));
它与消息一起崩溃:
java.lang.UnsupportedOperationException: Attempted to serialize java.lang.Class: web.services.Response. Forgot to register a type adapter?
我尝试将以下行添加到测试中,但没有帮助:
Gson gson = new GsonBuilder().registerTypeAdapter(mock(Response.class).getClass(), new ClassTypeAdapter()).create();
PS 我不能使用 powerMock 来模拟 Gson 的最后一堂课。如何解决这个问题呢?