BaseChildActivity extends CollectionActivity { @Override protected void onStop() { super.onPause(); if (mediaPlayer != null) { mediaPlayer.release(); mediaPlayer = null; } if (mediaRecorder != null) { mediaRecorder.release(); mediaRecorder = null; } }  Child load(); Child save(); void view(); @Override void onCreate(Bundle savedInstanceState); void showAlertDialog(); static final int CLOSE_ACTIVITY; }
@Test public void shouldReleaseMediaRecorderAndPlayerOnStopIfPresent(){ MediaPlayer mediaPlayer = mock(MediaPlayer.class); MediaRecorder mediaRecorder = mock(MediaRecorder.class); activity.setMediaPlayer(mediaPlayer); activity.setMediaRecorder(mediaRecorder); activity.onStop(); verify(mediaPlayer).release(); verify(mediaRecorder).release(); assertNull(activity.getMediaPlayer()); assertNull(activity.getMediaRecorder()); }