Tests: ServiceTestRule does not (always) restart the service.

Thus, resetting it's status is not happening and then leading to failures in subsequent tests.

Fixes #1058.
This commit is contained in:
Dennis Guse
2021-12-27 23:33:02 +01:00
parent d6cc7a0321
commit 7d0d87e962
6 changed files with 54 additions and 84 deletions
@@ -55,6 +55,7 @@ import de.dennisguse.opentracks.content.sensor.SensorDataSet;
import de.dennisguse.opentracks.io.file.TrackFileFormat;
import de.dennisguse.opentracks.io.file.exporter.TrackExporter;
import de.dennisguse.opentracks.services.TrackRecordingService;
import de.dennisguse.opentracks.services.TrackRecordingServiceTest;
import de.dennisguse.opentracks.services.handlers.TrackPointCreator;
import de.dennisguse.opentracks.services.sensors.AltitudeSumManager;
import de.dennisguse.opentracks.services.sensors.BluetoothRemoteSensorManager;
@@ -98,21 +99,26 @@ public class ExportImportTest {
private TrackImporter trackImporter;
@Before
public void fileSetup() throws IOException {
public void fileSetup() throws IOException, TimeoutException {
TrackRecordingServiceTest.resetService(mServiceRule, context);
tmpFile = File.createTempFile("test", "test", context.getFilesDir());
tmpFileUri = Uri.fromFile(tmpFile);
trackImporter = new TrackImporter(context, contentProviderUtils, Distance.of(10), Distance.of(200), true);
TrackRecordingServiceTest.resetService(mServiceRule, context);
}
@After
public void FileTearDown() throws TimeoutException {
public void tearDown() throws TimeoutException {
tmpFile.deleteOnExit();
tmpFileUri = null;
TrackRecordingService service = ((TrackRecordingService.Binder) mServiceRule.bindService(new Intent(context, TrackRecordingService.class)))
.getService();
service.getTrackPointCreator().setClock(Clock.systemUTC());
// Ensure that the database is empty after every test
contentProviderUtils.deleteAllTracks(context);
TrackRecordingServiceTest.resetService(mServiceRule, context);
}
public void setUp() throws TimeoutException {
@@ -175,16 +181,6 @@ public class ExportImportTest {
assertEquals(2, markers.size());
}
@After
public void tearDown() {
if (trackId != null) {
contentProviderUtils.deleteTrack(context, trackId);
}
if (importTrackId != null) {
contentProviderUtils.deleteTrack(context, importTrackId);
}
}
//TODO Does not test images
@LargeTest
@Test