Merge "Add test cases for utcToLocalTime in the ConvertUtils" into sc-dev

This commit is contained in:
YUKAI HUNG
2021-04-24 13:03:08 +00:00
committed by Android (Google) Code Review
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) {