在我的项目中,我尝试设置一个测试,在该测试中应该验证是否使用特定参数调用了一个方法。为此,我使用 Mockito 和 Kotlin。
在测试中,我使用的是模拟课程。( publisher) 此类是 rosjava 的一部分,包含一个方法publish;
public interface Publisher<T> extends TopicParticipant { //(java)
void setLatchMode(boolean var1);
boolean getLatchMode();
T newMessage();
void publish(T var1);
boolean hasSubscribers();
int getNumberOfSubscribers();
void shutdown(long var1, TimeUnit var3);
void shutdown();
void addListener(PublisherListener<T> var1);
}
当我尝试设定我的期望时:
val publisherMock = mock(Publisher::class.java)
verify(publisherMock, atLeastOnce()).publish(message) // message is underlined with a red color
这不会编译并表示 for 的参数publish应该属于 class Nothing!。为什么是这样?