为了账号安全,请及时绑定邮箱和手机立即绑定

跳过发送 Junit 中的方法参数之一

跳过发送 Junit 中的方法参数之一

波斯汪 2021-10-27 10:48:45
自己写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()调用另一个组件。


查看完整回答
反对 回复 2021-10-27
  • 1 回答
  • 0 关注
  • 113 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号