我想檢查時,模擬是帶一個realtimeUpdate
其currentTime
字段等於一些LocalDateTime
:我怎樣稱呼自定義的Hamcrest匹配器?
我想運行這樣的代碼使用自定義匹配:
verify(mockServerApi).sendUpdate(new TimeMatcher().isTimeEqual(update, localDateTime2));
,但我有一個編譯錯誤時我嘗試運行這個自定義匹配器。
我該如何解決這個問題?
public class TimeMatcher {
public Matcher<RealtimeUpdate> isTimeEqual(RealtimeUpdate realtimeUpdate, final LocalDateTime localDateTime) {
return new BaseMatcher<RealtimeUpdate>() {
@Override
public boolean matches(final Object item) {
final RealtimeUpdate realtimeUpdate = (RealtimeUpdate) item;
return realtimeUpdate.currentTime.equalTo(localDateTime);
}
這是方法簽名
void sendRealTimeUpdate(RealtimeUpdate realtimeUpdate);
,這是編譯錯誤:
http://www.planetgeek.ch/2012/03/07/create-your-own-match er/ –