[英]Mock method for all instances of enum java
我想為枚舉的所有實例模擬方法shouldShow()。 有人可以幫忙嗎?
public enum MyButton implements ListButton {
Button1(
R.drawable.drawable1) {
// Some methods here
},
Button2(
R.drawable.drawable2) {
//Some methods here
};
@Override
public boolean shouldShow() {
//Some logic that decides whether to show the button or not
}
}
我想模擬它,以便如果我調用Button1.shouldShow或Button2.shouldShow或enum.shouldShow中的任何其他值,則我的存根應該返回true。
我認為shouldShow()
方法是ListButton
接口的一部分。 如果您的設計經過深思熟慮,那么您很可能應該嘲笑ListButton
,而不是對任何特定MyButton
會發生什么。
Java枚舉常量本質上是公共的靜態final字段,因此,在特定的MyButton
常量上shouldShow()
方法就等於在靜態final字段上shouldShow()
方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.