Android/Testing/Unit Testing/委派 Finals
外觀
'showDialog()' 等方法是 final 的,且無法覆蓋。雖然 Robolectric 提供了一種可讓你更改其實現的方法,但有時使用一個更簡單的模式更方便 - 擴充套件受測類並覆蓋新的非 final 方法
public class MyActivity extends Activity {
public void onResume(Bundle bundle) {
Intent intent = getIntent();
int id = selectDialog(intent);
boolean result = nonFinalShowDialog(id, bundle);
}
public boolean nonFinalShowDialog(int id, Bundle bundle) {
return showDialog(id, bundle);
}
}