![](/img/trans.png)
[英]How to verify mocked method not called with any combination of parameters using Mockito
[英]Clever way for a method to accept any combination of unique objects as parameters?
我有一個可以用String
, Record
和Criteria
構造的類。 有什么方法允許方法簽名以任何順序接受這些參數(除了創建多個構造函數之外)? 這比什么都更是一個學術問題。
一種選擇是創建一個保存並表示這三個參數的類,但是我只建議如果這三個參數以某種方式相關聯,從而在對象模型中具有邏輯意義。
您可以執行以下操作:
public class MyClass ()
{
private String _str;
private Record _rec;
private Criteria _crit;
public MyClass ()
{
_rec = null;
_crit = null;
_str = null;
}
public MyClass string (String str)
{
this._str = str;
return this;
}
public MyClass record (Record rec)
{
this._rec = rec;
return this;
}
public MyClass criteria (Criteria crit)
{
this._crit = crit;
return this;
}
public static void getInstance ()
{
return new MyClass ();
}
public static void main (String[] args)
{
MyClass instance = MyClass.getInstance ().string("something").criteria(someCriteria).record(someRecord);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.