Open main menu

Wikibooks β

Android/Testing/Unit Testing/Delegate Finals

< Android‎ | Testing‎ | Unit Testing

Methods such as 'showDialog()' are final, and cannot be overridden. Although Robolectric provides a means for you to change their implementation, it's sometimes convenient to use a simpler pattern - extending the class under test and overriding the new non-final method:

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);