自己写TypeAdapter。例如,参见 javadoc。用@JsonAdapter注解指定它,或者用 注册它GsonBuilder。@JsonAdapter(MyClassAdapter.class)public class MyClass { public Long timestamp; public String id; public HashMap<String, SomeOtherClass> myMap = new HashMap<>();}public class MyClassAdapter extends TypeAdapter<MyClass> { @Override public void write(JsonWriter out, MyClass myClass) throws IOException { // implement the write method } @Override public MyClass read(JsonReader in) throws IOException { // implement the read method return ...; }}
1 回答

BIG阳
TA贡献1859条经验 获得超6个赞
要回答您的直接问题 - 使用匹配器 - 例如:
Mockito.doReturn("Hiii").when(sampleServiceSpy).sendRequestToAnotherComponent(eq(<ARG1>),any(UUID.class), eq(<ARG3>));
但是不要尝试模拟正在测试的类的方法,而是注入另一个组件的模拟。这样,测试可以verify()
调用另一个组件。
添加回答
举报
0/150
提交
取消