Fixed (some) AnnoucementPeriodicTask[Factory] tests.

This commit is contained in:
Dennis Guse
2019-09-05 07:29:48 +02:00
parent 8a56c262cb
commit cc770d8bb4
3 changed files with 33 additions and 10 deletions
@@ -351,8 +351,7 @@ public class TrackRecordingServiceTest {
Assert.assertFalse(service.isRecording()); Assert.assertFalse(service.isRecording());
/* /*
* Ending the current track when there is no recording should not result in * Ending the current track when there is no recording should not result in any error.
* any error.
*/ */
service.endCurrentTrack(); service.endCurrentTrack();
@@ -381,12 +380,12 @@ public class TrackRecordingServiceTest {
@MediumTest @MediumTest
@Test @Test
public void testInsertStatisticsMarker_validLocation() throws Exception { public void testInsertStatisticsMarker_validLocation() throws Exception {
Track track = createDummyTrack(trackId, -1L, true); createDummyTrack(trackId, -1L, true);
ITrackRecordingService service = ((ITrackRecordingService) mServiceRule.bindService(createStartIntent())); ITrackRecordingService service = ((ITrackRecordingService) mServiceRule.bindService(createStartIntent()));
Assert.assertTrue(service.isRecording()); Assert.assertTrue(service.isRecording());
Assert.assertFalse(service.isPaused()); Assert.assertFalse(service.isPaused());
insertLocation(track, service); insertLocation(service);
long waypointId1 = service.insertWaypoint(WaypointCreationRequest.DEFAULT_STATISTICS); long waypointId1 = service.insertWaypoint(WaypointCreationRequest.DEFAULT_STATISTICS);
Assert.assertNotEquals(-1L, waypointId1); Assert.assertNotEquals(-1L, waypointId1);
@@ -419,11 +418,11 @@ public class TrackRecordingServiceTest {
@MediumTest @MediumTest
@Test @Test
public void testInsertWaypointMarker_validWaypoint() throws Exception { public void testInsertWaypointMarker_validWaypoint() throws Exception {
Track track = createDummyTrack(trackId, -1L, true); createDummyTrack(trackId, -1L, true);
ITrackRecordingService service = ((ITrackRecordingService) mServiceRule.bindService(createStartIntent())); ITrackRecordingService service = ((ITrackRecordingService) mServiceRule.bindService(createStartIntent()));
Assert.assertTrue(service.isRecording()); Assert.assertTrue(service.isRecording());
insertLocation(track, service); insertLocation(service);
long waypointId = service.insertWaypoint(WaypointCreationRequest.DEFAULT_WAYPOINT); long waypointId = service.insertWaypoint(WaypointCreationRequest.DEFAULT_WAYPOINT);
Assert.assertNotEquals(-1L, waypointId); Assert.assertNotEquals(-1L, waypointId);
@@ -628,7 +627,7 @@ public class TrackRecordingServiceTest {
/** /**
* Inserts a location and waits for 100ms. * Inserts a location and waits for 100ms.
*/ */
private void insertLocation(Track track, ITrackRecordingService trackRecordingService) throws InterruptedException { private void insertLocation(ITrackRecordingService trackRecordingService) throws InterruptedException {
Location location = new Location("gps"); Location location = new Location("gps");
location.setLongitude(35.0f); location.setLongitude(35.0f);
location.setLatitude(45.0f); location.setLatitude(45.0f);
@@ -17,11 +17,14 @@
package de.dennisguse.opentracks.services.tasks; package de.dennisguse.opentracks.services.tasks;
import android.content.Context; import android.content.Context;
import android.os.Looper;
import androidx.test.core.app.ApplicationProvider; import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.AfterClass;
import org.junit.Assert; import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@@ -36,6 +39,17 @@ public class AnnouncementPeriodicTaskFactoryTest {
private Context context = ApplicationProvider.getApplicationContext(); private Context context = ApplicationProvider.getApplicationContext();
@BeforeClass
public static void preSetUp() {
// Prepare looper for Android's message queue
Looper.prepare();
}
@AfterClass
public static void finalTearDown() {
if (Looper.myLooper() != null) Looper.myLooper().quit();
}
@Test @Test
public void testCreate() { public void testCreate() {
PeriodicTaskFactory factory = new AnnouncementPeriodicTaskFactory(); PeriodicTaskFactory factory = new AnnouncementPeriodicTaskFactory();
@@ -16,6 +16,7 @@
package de.dennisguse.opentracks.services.tasks; package de.dennisguse.opentracks.services.tasks;
import android.content.Context; import android.content.Context;
import android.os.Looper;
import android.speech.tts.TextToSpeech; import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener; import android.speech.tts.TextToSpeech.OnInitListener;
import android.speech.tts.TextToSpeech.OnUtteranceCompletedListener; import android.speech.tts.TextToSpeech.OnUtteranceCompletedListener;
@@ -25,8 +26,10 @@ import android.telephony.TelephonyManager;
import androidx.test.core.app.ApplicationProvider; import androidx.test.core.app.ApplicationProvider;
import org.junit.After; import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
@@ -73,9 +76,16 @@ public class AnnouncementPeriodicTaskTest {
@Mock @Mock
private TextToSpeechInterface tts; private TextToSpeechInterface tts;
// @UsesMocks({ @BeforeClass
// StringUtils.class, public static void preSetUp() {
// }) // Prepare looper for Android's message queue
Looper.prepare();
}
@AfterClass
public static void finalTearDown() {
if (Looper.myLooper() != null) Looper.myLooper().quit();
}
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {