Add test cases for utcToLocalTime in the ConvertUtils

Bug: 177406865
Bug: 185187729
Test: make SettingsRoboTests
Test: make SettingsGoogleRoboTests
Change-Id: I22bda2db821e69c40202db692ada52e96af25e16
This commit is contained in:
ykhung
2021-04-24 01:04:30 +08:00
parent 81399d6fec
commit ef6cea8c84
3 changed files with 47 additions and 16 deletions

View File

@@ -39,10 +39,12 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
@@ -254,6 +256,32 @@ public final class ConvertUtilsTest {
assertBatteryDiffEntry(entryList.get(0), 68, 40L, 50L);
}
@Test
public void testUtcToLocalTime_returnExpectedResult() {
final long timestamp = 1619196786769L;
ConvertUtils.sSimpleDateFormat = null;
// Invokes the method first to create the SimpleDateFormat.
ConvertUtils.utcToLocalTime(/*timestamp=*/ 0);
ConvertUtils.sSimpleDateFormat
.setTimeZone(TimeZone.getTimeZone("GMT"));
assertThat(ConvertUtils.utcToLocalTime(timestamp))
.isEqualTo("Apr 23,2021 16:53:06");
}
@Test
public void testUtcToLocalTmeHour_returnExpectedResult() {
final long timestamp = 1619196786769L;
ConvertUtils.sSimpleDateFormatForHour = null;
// Invokes the method first to create the SimpleDateFormat.
ConvertUtils.utcToLocalTimeHour(/*timestamp=*/ 0);
ConvertUtils.sSimpleDateFormatForHour
.setTimeZone(TimeZone.getTimeZone("GMT"));
assertThat(ConvertUtils.utcToLocalTimeHour(timestamp))
.isEqualTo("4 pm");
}
private static BatteryHistEntry createBatteryHistEntry(
String packageName, String appLabel, double consumePower,
long uid, long foregroundUsageTimeInMs, long backgroundUsageTimeInMs) {