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

自己写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 ...;

    }

}


波斯汪
浏览 114回答 1
1回答

BIG阳

要回答您的直接问题 - 使用匹配器 - 例如:&nbsp;Mockito.doReturn("Hiii").when(sampleServiceSpy).sendRequestToAnotherComponent(eq(<ARG1>),any(UUID.class),&nbsp;eq(<ARG3>));但是不要尝试模拟正在测试的类的方法,而是注入另一个组件的模拟。这样,测试可以verify()调用另一个组件。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java