Skip to content

Commit

Permalink
Announcements: added current time.
Browse files Browse the repository at this point in the history
DateTimeFormatter behaves differently starting from SDK34 (produces NBSP).

Part of #1683.
  • Loading branch information
dennisguse committed Dec 29, 2024
1 parent 073b3d2 commit 43e1cbc
Showing 1 changed file with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package de.dennisguse.opentracks.services.announcement;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

import android.content.Context;
import android.icu.text.MessageFormat;
import android.os.Build;
import android.util.Pair;

import androidx.test.core.app.ApplicationProvider;
Expand Down Expand Up @@ -54,6 +56,11 @@ public void setUp() {
PreferencesUtils.setVoiceAnnounceLapSpeedPace(true);
}

@Test
public void sdkRequirement() {
assertFalse("Due to DateTimeFormatter using NBSP, these tests only work in SDK34+", Build.VERSION.SDK_INT < Build.VERSION_CODES.UPSIDE_DOWN_CAKE);
}

@Test
public void getAnnouncement_metric_speed() {
TrackStatistics stats = new TrackStatistics();
Expand All @@ -71,7 +78,7 @@ public void getAnnouncement_metric_speed() {
String announcement = VoiceAnnouncementUtils.createStatistics(context, track, UnitSystem.METRIC, true, null, null).toString();

// then
assertEquals("12:00 AM. Total distance 20.0 kilometers. 1 hour 5 minutes 10 seconds. Average moving speed 18.4 kilometers per hour.", announcement);
assertEquals("12:00AM. Total distance 20.0 kilometers. 1 hour 5 minutes 10 seconds. Average moving speed 18.4 kilometers per hour.", announcement);
}

@Test
Expand All @@ -91,7 +98,7 @@ public void getAnnouncement_metric_speed_rounding_check() {
String announcement = VoiceAnnouncementUtils.createStatistics(context, track, UnitSystem.METRIC, true, null, null).toString();

// then
assertEquals("12:00 AM. Total distance 20.0 kilometers. 1 hour 1 second. Average moving speed 20.0 kilometers per hour.", announcement);
assertEquals("12:00AM. Total distance 20.0 kilometers. 1 hour 1 second. Average moving speed 20.0 kilometers per hour.", announcement);
}

@Test
Expand All @@ -111,7 +118,7 @@ public void getAnnouncement_metric_distance_rounding_check() {
String announcement = VoiceAnnouncementUtils.createStatistics(context, track, UnitSystem.METRIC, true, null, null).toString();

// then
assertEquals("12:00 AM. Total distance 20.0 kilometers. 1 hour. Average moving speed 20.0 kilometers per hour.", announcement);
assertEquals("12:00AM. Total distance 20.0 kilometers. 1 hour. Average moving speed 20.0 kilometers per hour.", announcement);
}

@Test
Expand All @@ -131,7 +138,7 @@ public void getAnnouncement_metric_distance_rounding_check_two() {
String announcement = VoiceAnnouncementUtils.createStatistics(context, track, UnitSystem.METRIC, true, null, null).toString();

// then
assertEquals("12:00 AM. Total distance 19.9 kilometers. 1 hour. Average moving speed 19.9 kilometers per hour.", announcement);
assertEquals("12:00AM. Total distance 19.9 kilometers. 1 hour. Average moving speed 19.9 kilometers per hour.", announcement);
}

@Test
Expand All @@ -156,7 +163,7 @@ public void getAnnouncement_withInterval_metric_speed() {
String announcement = VoiceAnnouncementUtils.createStatistics(context, track, UnitSystem.METRIC, true, lastInterval, null).toString();

// then
assertEquals("12:16 AM. Total distance 14.2 kilometers. 16 minutes 39 seconds. Average moving speed 51.2 kilometers per hour. Lap speed 51.2 kilometers per hour.", announcement);
assertEquals("12:16AM. Total distance 14.2 kilometers. 16 minutes 39 seconds. Average moving speed 51.2 kilometers per hour. Lap speed 51.2 kilometers per hour.", announcement);
}

@Test
Expand All @@ -176,7 +183,7 @@ public void getAnnouncement_metric_pace() {
String announcement = VoiceAnnouncementUtils.createStatistics(context, track, UnitSystem.METRIC, false, null, null).toString();

// then
assertEquals("12:00 AM. Total distance 20.0 kilometers. 1 hour 5 minutes 10 seconds. Pace 3 minutes 15 seconds per kilometer.", announcement);
assertEquals("12:00AM. Total distance 20.0 kilometers. 1 hour 5 minutes 10 seconds. Pace 3 minutes 15 seconds per kilometer.", announcement);
}

@Test
Expand All @@ -201,7 +208,7 @@ public void getAnnouncement_withInterval_metric_pace() {
String announcement = VoiceAnnouncementUtils.createStatistics(context, track, UnitSystem.METRIC, false, lastInterval, null).toString();

// then
assertEquals("12:16 AM. Total distance 14.2 kilometers. 16 minutes 39 seconds. Pace 1 minute 10 seconds per kilometer. Lap time 1 minute 10 seconds per kilometer.", announcement);
assertEquals("12:16AM. Total distance 14.2 kilometers. 16 minutes 39 seconds. Pace 1 minute 10 seconds per kilometer. Lap time 1 minute 10 seconds per kilometer.", announcement);
}

@Test
Expand All @@ -221,7 +228,7 @@ public void getAnnouncement_imperial_speed() {
String announcement = VoiceAnnouncementUtils.createStatistics(context, track, UnitSystem.IMPERIAL_FEET, true, null, null).toString();

// then
assertEquals("12:00 AM. Total distance 12.4 miles. 1 hour 5 minutes 10 seconds. Average moving speed 11.4 miles per hour.", announcement);
assertEquals("12:00AM. Total distance 12.4 miles. 1 hour 5 minutes 10 seconds. Average moving speed 11.4 miles per hour.", announcement);
}

@Test
Expand All @@ -239,7 +246,7 @@ public void getAnnouncement_imperial_speed_1() {
String announcement = VoiceAnnouncementUtils.createStatistics(context, track, UnitSystem.IMPERIAL_FEET, true, null, null).toString();

// then
assertEquals("12:00 AM. Total distance 1.1 miles. 1 hour. Average moving speed 1.1 miles per hour.", announcement);
assertEquals("12:00AM. Total distance 1.1 miles. 1 hour. Average moving speed 1.1 miles per hour.", announcement);
}

@Test
Expand All @@ -257,7 +264,7 @@ public void getAnnouncement_imperial_meter_speed_1() {
String announcement = VoiceAnnouncementUtils.createStatistics(context, track, UnitSystem.IMPERIAL_METER, true, null, null).toString();

// then
assertEquals("12:00 AM. Total distance 1.1 miles. 1 hour. Average moving speed 1.1 miles per hour.", announcement);
assertEquals("12:00AM. Total distance 1.1 miles. 1 hour. Average moving speed 1.1 miles per hour.", announcement);
}

@Test
Expand All @@ -275,7 +282,7 @@ public void getAnnouncement_metric_speed_1() {
String announcement = VoiceAnnouncementUtils.createStatistics(context, track, UnitSystem.METRIC, true, null, null).toString();

// then
assertEquals("12:00 AM. Total distance 1.1 kilometers. 1 hour. Average moving speed 1.1 kilometers per hour.", announcement);
assertEquals("12:00AM. Total distance 1.1 kilometers. 1 hour. Average moving speed 1.1 kilometers per hour.", announcement);
}

@Test
Expand All @@ -300,7 +307,7 @@ public void getAnnouncement_withInterval_imperial_speed() {
String announcement = VoiceAnnouncementUtils.createStatistics(context, track, UnitSystem.IMPERIAL_FEET, true, lastInterval, null).toString();

// then
assertEquals("12:16 AM. Total distance 8.8 miles. 16 minutes 39 seconds. Average moving speed 31.8 miles per hour. Lap speed 31.8 miles per hour.", announcement);
assertEquals("12:16AM. Total distance 8.8 miles. 16 minutes 39 seconds. Average moving speed 31.8 miles per hour. Lap speed 31.8 miles per hour.", announcement);
}

@Test
Expand All @@ -320,7 +327,7 @@ public void getAnnouncement_imperial_pace() {
String announcement = VoiceAnnouncementUtils.createStatistics(context, track, UnitSystem.IMPERIAL_FEET, false, null, null).toString();

// then
assertEquals("12:00 AM. Total distance 12.4 miles. 1 hour 5 minutes 10 seconds. Pace 5 minutes 15 seconds per mile.", announcement);
assertEquals("12:00AM. Total distance 12.4 miles. 1 hour 5 minutes 10 seconds. Pace 5 minutes 15 seconds per mile.", announcement);
}

@Test
Expand All @@ -345,7 +352,7 @@ public void getAnnouncement_withInterval_imperial_pace() {
String announcement = VoiceAnnouncementUtils.createStatistics(context, track, UnitSystem.IMPERIAL_FEET, false, lastInterval, null).toString();

// then
assertEquals("12:16 AM. Total distance 8.8 miles. 16 minutes 39 seconds. Pace 1 minute 53 seconds per mile. Lap time 1 minute 53 seconds per mile.", announcement);
assertEquals("12:16AM. Total distance 8.8 miles. 16 minutes 39 seconds. Pace 1 minute 53 seconds per mile. Lap time 1 minute 53 seconds per mile.", announcement);
}

@Test
Expand Down Expand Up @@ -374,7 +381,7 @@ public void getAnnouncement_heart_rate_and_sensor_statistics() {
String announcement = VoiceAnnouncementUtils.createStatistics(context, track, UnitSystem.METRIC, true, lastInterval, sensorStatistics).toString();

// then
assertEquals("12:16 AM. Total distance 14.2 kilometers. 16 minutes 39 seconds. Average moving speed 51.2 kilometers per hour. Lap speed 51.2 kilometers per hour. Average heart rate 180 bpm. Current heart rate 133 bpm.", announcement);
assertEquals("12:16AM. Total distance 14.2 kilometers. 16 minutes 39 seconds. Average moving speed 51.2 kilometers per hour. Lap speed 51.2 kilometers per hour. Average heart rate 180 bpm. Current heart rate 133 bpm.", announcement);
}

@Test
Expand Down Expand Up @@ -407,7 +414,7 @@ public void getAnnouncement_only_lap_heart_rate() {
String announcement = VoiceAnnouncementUtils.createStatistics(context, track, UnitSystem.METRIC, true, lastInterval, sensorStatistics).toString();

// then
assertEquals("12:16 AM. Current heart rate 133 bpm.", announcement);
assertEquals("12:16AM. Current heart rate 133 bpm.", announcement);
}

@Test
Expand Down

0 comments on commit 43e1cbc

Please sign in to comment.