本文介紹了Mockito:使用泛型參數(shù)進(jìn)行驗(yàn)證的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
使用 Mockito,我可以做到以下幾點(diǎn):
With Mockito I can do the following:
verify(someService).process(any(Person.class));
但是,如果 process
采用 Collection
代替,我該怎么寫呢?無法弄清楚如何正確編寫它.只是遇到語法錯(cuò)誤...
But how do I write this if process
takes a Collection<Person>
instead? Can't figure out how to write it correctly. Just getting syntax errors...
推薦答案
試試:
verify(someService).process(Matchers.<Collection<Person>>any());
實(shí)際上,當(dāng)我鍵入 any()
時(shí),IntelliJ 會(huì)自動(dòng)建議此修復(fù)程序...不幸的是,在這種情況下您不能使用靜態(tài)導(dǎo)入.
Actually, IntelliJ automatically suggested this fix when I typed any()
... Unfortunately you cannot use static import in this case.
這篇關(guān)于Mockito:使用泛型參數(shù)進(jìn)行驗(yàn)證的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!