Bug fixing and refactoring:

1) Make sure no one but service changes recordingTrackId (which is owned by it)
2) Cache sharedPreferences
3) Clear recordingTrackId if it doesn't correspond to a valid track or the service is not recording
4) More unit tests
This commit is contained in:
Bartlomiej Niechwiej
2010-10-28 22:49:01 -07:00
parent dc8ee5943c
commit a0f090a83a
4 changed files with 49 additions and 69 deletions
@@ -257,6 +257,18 @@ public class TrackRecordingServiceTest
assertEquals(-1, service.getRecordingTrackId());
}
@MediumTest
public void testRecording_orphanedRecordingTrack() throws Exception {
// Just set recording track to a bogus value.
setRecordingTrack(256);
// Make sure that the service will not start recording and will clear
// the bogus track.
ITrackRecordingService service = bindAndGetService(createStartIntent());
assertFalse(service.isRecording());
assertEquals(-1, service.getRecordingTrackId());
}
@MediumTest
public void testStartNewTrack_noRecording() throws Exception {
List<Track> tracks = providerUtils.getAllTracks();
@@ -538,9 +550,12 @@ public class TrackRecordingServiceTest
assertTrue(track.getId() >= 0);
providerUtils.insertTrack(track);
assertEquals(track.getId(), providerUtils.getTrack(track.getId()).getId());
setRecordingTrack(isRecording ? track.getId() : -1);
}
private void setRecordingTrack(long id) {
Editor editor = sharedPreferences.edit();
editor.putLong(context.getString(R.string.recording_track_key),
isRecording ? track.getId() : -1);
editor.putLong(context.getString(R.string.recording_track_key), id);
editor.commit();
}
}