aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/src/com/android/tv/util
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/src/com/android/tv/util')
-rw-r--r--tests/unit/src/com/android/tv/util/ImageCacheTest.java14
-rw-r--r--tests/unit/src/com/android/tv/util/MockApplicationSingletons.java154
-rw-r--r--tests/unit/src/com/android/tv/util/MultiLongSparseArrayTest.java14
-rw-r--r--tests/unit/src/com/android/tv/util/ScaledBitmapInfoTest.java10
-rw-r--r--tests/unit/src/com/android/tv/util/TestUtils.java27
-rw-r--r--tests/unit/src/com/android/tv/util/TvInputManagerHelperTest.java141
-rw-r--r--tests/unit/src/com/android/tv/util/TvTrackInfoUtilsTest.java15
-rw-r--r--tests/unit/src/com/android/tv/util/UtilsTest_GetDurationString.java36
-rw-r--r--tests/unit/src/com/android/tv/util/UtilsTest_GetMultiAudioString.java21
-rw-r--r--tests/unit/src/com/android/tv/util/UtilsTest_IsInGivenDay.java11
10 files changed, 386 insertions, 57 deletions
diff --git a/tests/unit/src/com/android/tv/util/ImageCacheTest.java b/tests/unit/src/com/android/tv/util/ImageCacheTest.java
index e185d5f1..a76194b8 100644
--- a/tests/unit/src/com/android/tv/util/ImageCacheTest.java
+++ b/tests/unit/src/com/android/tv/util/ImageCacheTest.java
@@ -17,19 +17,21 @@
package com.android.tv.util;
import static com.android.tv.util.BitmapUtils.createScaledBitmapInfo;
+import static org.junit.Assert.assertSame;
import android.graphics.Bitmap;
import android.support.test.filters.MediumTest;
import com.android.tv.util.BitmapUtils.ScaledBitmapInfo;
-import junit.framework.TestCase;
+import org.junit.Before;
+import org.junit.Test;
/**
* Tests for {@link ImageCache}.
*/
@MediumTest
-public class ImageCacheTest extends TestCase {
+public class ImageCacheTest {
private static final Bitmap ORIG = Bitmap.createBitmap(100, 100, Bitmap.Config.RGB_565);
private static final String KEY = "same";
@@ -40,14 +42,14 @@ public class ImageCacheTest extends TestCase {
private ImageCache mImageCache;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
mImageCache = ImageCache.newInstance(0.1f);
}
//TODO: Empty the cache in the setup. Try using @VisibleForTesting
+ @Test
public void testPutIfLarger_smaller() throws Exception {
mImageCache.putIfNeeded( INFO_50);
@@ -57,6 +59,7 @@ public class ImageCacheTest extends TestCase {
assertSame("after", INFO_50, mImageCache.get(KEY));
}
+ @Test
public void testPutIfLarger_larger() throws Exception {
mImageCache.putIfNeeded( INFO_50);
assertSame("before", INFO_50, mImageCache.get(KEY));
@@ -65,6 +68,7 @@ public class ImageCacheTest extends TestCase {
assertSame("after", INFO_100, mImageCache.get(KEY));
}
+ @Test
public void testPutIfLarger_alreadyMax() throws Exception {
mImageCache.putIfNeeded( INFO_100);
diff --git a/tests/unit/src/com/android/tv/util/MockApplicationSingletons.java b/tests/unit/src/com/android/tv/util/MockApplicationSingletons.java
new file mode 100644
index 00000000..4cfc7f8a
--- /dev/null
+++ b/tests/unit/src/com/android/tv/util/MockApplicationSingletons.java
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.tv.util;
+
+import android.content.Context;
+
+import com.android.tv.ApplicationSingletons;
+import com.android.tv.InputSessionManager;
+import com.android.tv.MainActivityWrapper;
+import com.android.tv.TvApplication;
+import com.android.tv.analytics.Analytics;
+import com.android.tv.analytics.Tracker;
+import com.android.tv.config.RemoteConfig;
+import com.android.tv.data.ChannelDataManager;
+import com.android.tv.data.PreviewDataManager;
+import com.android.tv.data.ProgramDataManager;
+import com.android.tv.dvr.DvrDataManager;
+import com.android.tv.dvr.DvrManager;
+import com.android.tv.dvr.DvrScheduleManager;
+import com.android.tv.dvr.DvrStorageStatusManager;
+import com.android.tv.dvr.DvrWatchedPositionManager;
+import com.android.tv.dvr.recorder.RecordingScheduler;
+import com.android.tv.perf.PerformanceMonitor;
+
+/**
+ * Mock {@link ApplicationSingletons} class.
+ */
+public class MockApplicationSingletons implements ApplicationSingletons {
+ private final TvApplication mApp;
+
+ private PerformanceMonitor mPerformanceMonitor;
+
+ public MockApplicationSingletons(Context context) {
+ mApp = (TvApplication) context.getApplicationContext();
+ }
+
+ @Override
+ public Analytics getAnalytics() {
+ return mApp.getAnalytics();
+ }
+
+ @Override
+ public ChannelDataManager getChannelDataManager() {
+ return mApp.getChannelDataManager();
+ }
+
+ @Override
+ public boolean isChannelDataManagerLoadFinished() {
+ return mApp.isChannelDataManagerLoadFinished();
+ }
+
+ @Override
+ public ProgramDataManager getProgramDataManager() {
+ return mApp.getProgramDataManager();
+ }
+
+ @Override
+ public boolean isProgramDataManagerCurrentProgramsLoadFinished() {
+ return mApp.isProgramDataManagerCurrentProgramsLoadFinished();
+ }
+
+ @Override
+ public PreviewDataManager getPreviewDataManager() {
+ return mApp.getPreviewDataManager();
+ }
+
+ @Override
+ public DvrDataManager getDvrDataManager() {
+ return mApp.getDvrDataManager();
+ }
+
+ @Override
+ public DvrStorageStatusManager getDvrStorageStatusManager() {
+ return mApp.getDvrStorageStatusManager();
+ }
+
+ @Override
+ public DvrScheduleManager getDvrScheduleManager() {
+ return mApp.getDvrScheduleManager();
+ }
+
+ @Override
+ public DvrManager getDvrManager() {
+ return mApp.getDvrManager();
+ }
+
+ @Override
+ public RecordingScheduler getRecordingScheduler() {
+ return mApp.getRecordingScheduler();
+ }
+
+ @Override
+ public DvrWatchedPositionManager getDvrWatchedPositionManager() {
+ return mApp.getDvrWatchedPositionManager();
+ }
+
+ @Override
+ public InputSessionManager getInputSessionManager() {
+ return mApp.getInputSessionManager();
+ }
+
+ @Override
+ public Tracker getTracker() {
+ return mApp.getTracker();
+ }
+
+ @Override
+ public TvInputManagerHelper getTvInputManagerHelper() {
+ return mApp.getTvInputManagerHelper();
+ }
+
+ @Override
+ public MainActivityWrapper getMainActivityWrapper() {
+ return mApp.getMainActivityWrapper();
+ }
+
+ @Override
+ public AccountHelper getAccountHelper() {
+ return mApp.getAccountHelper();
+ }
+
+ @Override
+ public RemoteConfig getRemoteConfig() {
+ return mApp.getRemoteConfig();
+ }
+
+ @Override
+ public boolean isRunningInMainProcess() {
+ return mApp.isRunningInMainProcess();
+ }
+
+ @Override
+ public PerformanceMonitor getPerformanceMonitor() {
+ return mPerformanceMonitor != null ? mPerformanceMonitor : mApp.getPerformanceMonitor();
+ }
+
+ public void setPerformanceMonitor(PerformanceMonitor performanceMonitor) {
+ mPerformanceMonitor = performanceMonitor;
+ }
+}
diff --git a/tests/unit/src/com/android/tv/util/MultiLongSparseArrayTest.java b/tests/unit/src/com/android/tv/util/MultiLongSparseArrayTest.java
index fe094fb3..7335f207 100644
--- a/tests/unit/src/com/android/tv/util/MultiLongSparseArrayTest.java
+++ b/tests/unit/src/com/android/tv/util/MultiLongSparseArrayTest.java
@@ -16,10 +16,13 @@
package com.android.tv.util;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+
import android.support.test.filters.SmallTest;
import android.test.MoreAsserts;
-import junit.framework.TestCase;
+import org.junit.Test;
import java.util.Collections;
@@ -27,19 +30,21 @@ import java.util.Collections;
* Tests for {@link MultiLongSparseArray}.
*/
@SmallTest
-public class MultiLongSparseArrayTest extends TestCase {
-
+public class MultiLongSparseArrayTest {
+ @Test
public void testEmpty() {
MultiLongSparseArray<String> sparseArray = new MultiLongSparseArray<>();
assertSame(Collections.EMPTY_SET, sparseArray.get(0));
}
+ @Test
public void testOneElement() {
MultiLongSparseArray<String> sparseArray = new MultiLongSparseArray<>();
sparseArray.put(0, "foo");
MoreAsserts.assertContentsInAnyOrder(sparseArray.get(0), "foo");
}
+ @Test
public void testTwoElements() {
MultiLongSparseArray<String> sparseArray = new MultiLongSparseArray<>();
sparseArray.put(0, "foo");
@@ -48,6 +53,7 @@ public class MultiLongSparseArrayTest extends TestCase {
}
+ @Test
public void testClearEmptyCache() {
MultiLongSparseArray<String> sparseArray = new MultiLongSparseArray<>();
sparseArray.clearEmptyCache();
@@ -59,6 +65,7 @@ public class MultiLongSparseArrayTest extends TestCase {
assertEquals(0, sparseArray.getEmptyCacheSize());
}
+ @Test
public void testMaxEmptyCacheSize() {
MultiLongSparseArray<String> sparseArray = new MultiLongSparseArray<>();
sparseArray.clearEmptyCache();
@@ -75,6 +82,7 @@ public class MultiLongSparseArrayTest extends TestCase {
assertEquals(0, sparseArray.getEmptyCacheSize());
}
+ @Test
public void testReuseEmptySets() {
MultiLongSparseArray<String> sparseArray = new MultiLongSparseArray<>();
sparseArray.clearEmptyCache();
diff --git a/tests/unit/src/com/android/tv/util/ScaledBitmapInfoTest.java b/tests/unit/src/com/android/tv/util/ScaledBitmapInfoTest.java
index 36d25a10..2714e2e9 100644
--- a/tests/unit/src/com/android/tv/util/ScaledBitmapInfoTest.java
+++ b/tests/unit/src/com/android/tv/util/ScaledBitmapInfoTest.java
@@ -1,24 +1,29 @@
package com.android.tv.util;
+import static org.junit.Assert.assertEquals;
+
import android.graphics.Bitmap;
import android.support.test.filters.SmallTest;
-import android.test.AndroidTestCase;
import com.android.tv.util.BitmapUtils.ScaledBitmapInfo;
+import org.junit.Test;
+
/**
* Tests for {@link ScaledBitmapInfo}.
*/
@SmallTest
-public class ScaledBitmapInfoTest extends AndroidTestCase {
+public class ScaledBitmapInfoTest {
private static final Bitmap B80x100 = Bitmap.createBitmap(80, 100, Bitmap.Config.RGB_565);
private static final Bitmap B960x1440 = Bitmap.createBitmap(960, 1440, Bitmap.Config.RGB_565);
+ @Test
public void testSize_B100x100to50x50() {
ScaledBitmapInfo actual = BitmapUtils.createScaledBitmapInfo("B80x100", B80x100, 50, 50);
assertScaledBitmapSize(2, 40, 50, actual);
}
+ @Test
public void testNeedsToReload_B100x100to50x50() {
ScaledBitmapInfo actual = BitmapUtils.createScaledBitmapInfo("B80x100", B80x100, 50, 50);
assertNeedsToReload(false, actual, 25, 25);
@@ -31,6 +36,7 @@ public class ScaledBitmapInfoTest extends AndroidTestCase {
/**
* Reproduces <a href="http://b/20488453">b/20488453</a>.
*/
+ @Test
public void testBug20488453() {
ScaledBitmapInfo actual = BitmapUtils
.createScaledBitmapInfo("B960x1440", B960x1440, 284, 160);
diff --git a/tests/unit/src/com/android/tv/util/TestUtils.java b/tests/unit/src/com/android/tv/util/TestUtils.java
index e3bda138..d200733d 100644
--- a/tests/unit/src/com/android/tv/util/TestUtils.java
+++ b/tests/unit/src/com/android/tv/util/TestUtils.java
@@ -21,8 +21,8 @@ import android.content.pm.ServiceInfo;
import android.graphics.drawable.Icon;
import android.hardware.hdmi.HdmiDeviceInfo;
import android.media.tv.TvInputInfo;
+import android.os.Build;
import android.os.Bundle;
-import android.support.v4.os.BuildCompat;
import java.lang.reflect.Constructor;
@@ -47,7 +47,11 @@ public class TestUtils {
int type, boolean isHardwareInput, boolean canRecord, int tunerCount) throws Exception {
// Create a mock TvInputInfo by using private constructor
// Note that mockito doesn't support mock/spy on final object.
- if (BuildCompat.isAtLeastN()) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ return createTvInputInfoForO(service, id, parentId, type, isHardwareInput, canRecord,
+ tunerCount);
+
+ } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return createTvInputInfoForNyc(service, id, parentId, type, isHardwareInput, canRecord,
tunerCount);
}
@@ -57,6 +61,24 @@ public class TestUtils {
/**
* private TvInputInfo(ResolveInfo service, String id, int type, boolean isHardwareInput,
* CharSequence label, int labelResId, Icon icon, Icon iconStandby, Icon iconDisconnected,
+ * String setupActivity, boolean canRecord, int tunerCount, HdmiDeviceInfo hdmiDeviceInfo,
+ * boolean isConnectedToHdmiSwitch, String parentId, Bundle extras) {
+ */
+ private static TvInputInfo createTvInputInfoForO(ResolveInfo service, String id,
+ String parentId, int type, boolean isHardwareInput, boolean canRecord, int tunerCount)
+ throws Exception {
+ Constructor<TvInputInfo> constructor = TvInputInfo.class.getDeclaredConstructor(
+ ResolveInfo.class, String.class, int.class, boolean.class, CharSequence.class,
+ int.class, Icon.class, Icon.class, Icon.class, String.class, boolean.class,
+ int.class, HdmiDeviceInfo.class, boolean.class, String.class, Bundle.class);
+ constructor.setAccessible(true);
+ return constructor.newInstance(service, id, type, isHardwareInput, null, 0, null, null,
+ null, null, canRecord, tunerCount, null, false, parentId, null);
+ }
+
+ /**
+ * private TvInputInfo(ResolveInfo service, String id, int type, boolean isHardwareInput,
+ * CharSequence label, int labelResId, Icon icon, Icon iconStandby, Icon iconDisconnected,
* String setupActivity, String settingsActivity, boolean canRecord, int tunerCount,
* HdmiDeviceInfo hdmiDeviceInfo, boolean isConnectedToHdmiSwitch, String parentId,
* Bundle extras) {
@@ -87,6 +109,7 @@ public class TestUtils {
resolveInfo.serviceInfo = new ServiceInfo();
resolveInfo.serviceInfo.packageName = packageName;
resolveInfo.serviceInfo.name = name;
+ resolveInfo.serviceInfo.metaData = new Bundle();
return resolveInfo;
}
}
diff --git a/tests/unit/src/com/android/tv/util/TvInputManagerHelperTest.java b/tests/unit/src/com/android/tv/util/TvInputManagerHelperTest.java
index ba1e0b0b..404ee5d3 100644
--- a/tests/unit/src/com/android/tv/util/TvInputManagerHelperTest.java
+++ b/tests/unit/src/com/android/tv/util/TvInputManagerHelperTest.java
@@ -16,58 +16,155 @@
package com.android.tv.util;
+import static android.support.test.InstrumentationRegistry.getContext;
+
import android.content.pm.ResolveInfo;
import android.media.tv.TvInputInfo;
import android.support.test.filters.SmallTest;
-import android.support.test.filters.Suppress;
-import android.test.AndroidTestCase;
import com.android.tv.testing.ComparatorTester;
+import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
-import java.util.LinkedHashMap;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
/**
* Test for {@link TvInputManagerHelper}
*/
@SmallTest
-public class TvInputManagerHelperTest extends AndroidTestCase {
- public void testComparator() throws Exception {
- final LinkedHashMap<String, Boolean> INPUT_ID_TO_PARTNER_INPUT = new LinkedHashMap<>();
- INPUT_ID_TO_PARTNER_INPUT.put("2_partner_input", true);
- INPUT_ID_TO_PARTNER_INPUT.put("3_partner_input", true);
- INPUT_ID_TO_PARTNER_INPUT.put("1_3rd_party_input", false);
- INPUT_ID_TO_PARTNER_INPUT.put("4_3rd_party_input", false);
+public class TvInputManagerHelperTest {
+ final HashMap<String, TvInputInfoWrapper> TEST_INPUT_MAP = new HashMap<>();
+
+ @Test
+ public void testComparatorInternal() {
+ ResolveInfo resolveInfo = TestUtils.createResolveInfo("test", "test");
+
+ List<TvInputInfo> inputs = new ArrayList<>();
+ inputs.add(createTvInputInfo(resolveInfo, "2_partner_input", null, 0, false,
+ "2_partner_input", null, true));
+ inputs.add(createTvInputInfo(resolveInfo, "3_partner_input", null, 0, false,
+ "3_partner_input", null, true));
+ inputs.add(createTvInputInfo(resolveInfo, "1_3rd_party_input", null, 0, false,
+ "1_3rd_party_input", null, false));
+ inputs.add(createTvInputInfo(resolveInfo, "4_3rd_party_input", null, 0, false,
+ "4_3rd_party_input", null, false));
+
+ TvInputManagerHelper manager = createMockTvInputManager();
+
+ ComparatorTester<TvInputInfo> comparatorTester = ComparatorTester.withoutEqualsTest(
+ new TvInputManagerHelper.InputComparatorInternal(manager));
+ for (TvInputInfo input : inputs) {
+ comparatorTester.addComparableGroup(input);
+ }
+ comparatorTester.test();
+ }
+
+ @Test
+ public void testHardwareInputComparatorHdmi() {
+ ResolveInfo resolveInfo = TestUtils.createResolveInfo("test", "test");
+
+ TvInputInfo hdmi1 = createTvInputInfo(resolveInfo, "HDMI1", null, TvInputInfo.TYPE_HDMI,
+ true, "HDMI1", null, false);
+ TvInputInfo hdmi2 = createTvInputInfo(resolveInfo, "HDMI2", null, TvInputInfo.TYPE_HDMI,
+ true, "HDMI2", "DVD", false);
+ TvInputInfo hdmi3 = createTvInputInfo(resolveInfo, "HDMI3", null, TvInputInfo.TYPE_HDMI,
+ true, "HDMI3", "Cable", false);
+ TvInputInfo hdmi4 = createTvInputInfo(resolveInfo, "HDMI4", null, TvInputInfo.TYPE_HDMI,
+ true, "HDMI4", null, false);
+
+ TvInputManagerHelper manager = createMockTvInputManager();
+
+ ComparatorTester<TvInputInfo> comparatorTester = ComparatorTester.withoutEqualsTest(
+ new TvInputManagerHelper.HardwareInputComparator(getContext(), manager));
+ comparatorTester.addComparableGroup(hdmi3)
+ .addComparableGroup(hdmi2)
+ .addComparableGroup(hdmi1)
+ .addComparableGroup(hdmi4)
+ .test();
+ }
+
+ @Test
+ public void testHardwareInputComparatorCec() {
+ ResolveInfo resolveInfo = TestUtils.createResolveInfo("test", "test");
+
+ TvInputInfo hdmi1 = createTvInputInfo(resolveInfo, "HDMI1", null, TvInputInfo.TYPE_HDMI,
+ true, "HDMI1", null, false);
+ TvInputInfo hdmi2 = createTvInputInfo(resolveInfo, "HDMI2", null, TvInputInfo.TYPE_HDMI,
+ true, "HDMI2", null, false);
+ TvInputInfo cec1 = createTvInputInfo(resolveInfo, "2_cec", "HDMI1", TvInputInfo.TYPE_HDMI,
+ true, "2_cec", null, false);
+ TvInputInfo cec2 = createTvInputInfo(resolveInfo, "1_cec", "HDMI2", TvInputInfo.TYPE_HDMI,
+ true, "1_cec", null, false);
+
+ TvInputManagerHelper manager = createMockTvInputManager();
+
+ ComparatorTester<TvInputInfo> comparatorTester = ComparatorTester.withoutEqualsTest(
+ new TvInputManagerHelper.HardwareInputComparator(getContext(), manager));
+ comparatorTester.addComparableGroup(cec1)
+ .addComparableGroup(cec2)
+ .test();
+ }
+
+ private TvInputManagerHelper createMockTvInputManager() {
TvInputManagerHelper manager = Mockito.mock(TvInputManagerHelper.class);
Mockito.doAnswer(new Answer<Boolean>() {
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
TvInputInfo info = (TvInputInfo) invocation.getArguments()[0];
- return INPUT_ID_TO_PARTNER_INPUT.get(info.getId());
+ return TEST_INPUT_MAP.get(info.getId()).mIsPartnerInput;
}
}).when(manager).isPartnerInput(Mockito.<TvInputInfo>any());
Mockito.doAnswer(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
TvInputInfo info = (TvInputInfo) invocation.getArguments()[0];
- return info.getId();
+ return TEST_INPUT_MAP.get(info.getId()).mLabel;
}
}).when(manager).loadLabel(Mockito.<TvInputInfo>any());
+ Mockito.doAnswer(new Answer<String>() {
+ @Override
+ public String answer(InvocationOnMock invocation) throws Throwable {
+ TvInputInfo info = (TvInputInfo) invocation.getArguments()[0];
+ return TEST_INPUT_MAP.get(info.getId()).mCustomLabel;
+ }
+ }).when(manager).loadCustomLabel(Mockito.<TvInputInfo>any());
+ Mockito.doAnswer(new Answer<TvInputInfo>() {
+ @Override
+ public TvInputInfo answer(InvocationOnMock invocation) throws Throwable {
+ String inputId = (String) invocation.getArguments()[0];
+ TvInputInfoWrapper inputWrapper = TEST_INPUT_MAP.get(inputId);
+ return inputWrapper == null ? null : inputWrapper.mInput;
+ }
+ }).when(manager).getTvInputInfo(Mockito.<String>any());
+ return manager;
+ }
- ComparatorTester<TvInputInfo> comparatorTester =
- ComparatorTester.withoutEqualsTest(
- new TvInputManagerHelper.TvInputInfoComparator(manager));
- ResolveInfo resolveInfo1 = TestUtils.createResolveInfo("1_test", "1_test");
- ResolveInfo resolveInfo2 = TestUtils.createResolveInfo("2_test", "2_test");
- for (String inputId : INPUT_ID_TO_PARTNER_INPUT.keySet()) {
- TvInputInfo info1 = TestUtils.createTvInputInfo(resolveInfo1, inputId, null, 0, false);
- TvInputInfo info2 = TestUtils.createTvInputInfo(resolveInfo2, inputId, null, 0, false);
- comparatorTester.addComparableGroup(info1, info2);
+ private TvInputInfo createTvInputInfo(ResolveInfo service, String id,
+ String parentId, int type, boolean isHardwareInput, String label, String customLabel,
+ boolean isPartnerInput) {
+ TvInputInfoWrapper inputWrapper = new TvInputInfoWrapper();
+ try {
+ inputWrapper.mInput =
+ TestUtils.createTvInputInfo(service, id, parentId, type, isHardwareInput);
+ } catch (Exception e) {
}
- comparatorTester.test();
+ inputWrapper.mLabel = label;
+ inputWrapper.mIsPartnerInput = isPartnerInput;
+ inputWrapper.mCustomLabel = customLabel;
+ TEST_INPUT_MAP.put(id, inputWrapper);
+ return inputWrapper.mInput;
+ }
+
+ private static class TvInputInfoWrapper {
+ TvInputInfo mInput;
+ String mLabel;
+ String mCustomLabel;
+ boolean mIsPartnerInput;
}
}
diff --git a/tests/unit/src/com/android/tv/util/TvTrackInfoUtilsTest.java b/tests/unit/src/com/android/tv/util/TvTrackInfoUtilsTest.java
index 9600fc0b..4512bb7d 100644
--- a/tests/unit/src/com/android/tv/util/TvTrackInfoUtilsTest.java
+++ b/tests/unit/src/com/android/tv/util/TvTrackInfoUtilsTest.java
@@ -16,13 +16,14 @@
package com.android.tv.util;
import static com.android.tv.util.TvTrackInfoUtils.getBestTrackInfo;
+import static org.junit.Assert.assertEquals;
import android.media.tv.TvTrackInfo;
import android.support.test.filters.SmallTest;
import com.android.tv.testing.ComparatorTester;
-import junit.framework.TestCase;
+import org.junit.Test;
import java.util.Arrays;
import java.util.Collections;
@@ -33,8 +34,7 @@ import java.util.List;
* Tests for {@link com.android.tv.util.TvTrackInfoUtils}.
*/
@SmallTest
-public class TvTrackInfoUtilsTest extends TestCase {
-
+public class TvTrackInfoUtilsTest {
private static final String UN_MATCHED_ID = "no matching ID";
private static final TvTrackInfo INFO_1_EN_1 = create("1", "en", 1);
@@ -59,46 +59,55 @@ public class TvTrackInfoUtilsTest extends TestCase {
private static final List<TvTrackInfo> NULL_LANGUAGE_TRACKS = Arrays.asList(INFO_4_NULL_2,
INFO_5_NULL_6);
+ @Test
public void testGetBestTrackInfo_empty() {
TvTrackInfo result = getBestTrackInfo(Collections.emptyList(), UN_MATCHED_ID, "en", 1);
assertEquals("best track ", null, result);
}
+ @Test
public void testGetBestTrackInfo_exactMatch() {
TvTrackInfo result = getBestTrackInfo(ALL, "1", "en", 1);
assertEquals("best track ", INFO_1_EN_1, result);
}
+ @Test
public void testGetBestTrackInfo_langAndChannelCountMatch() {
TvTrackInfo result = getBestTrackInfo(ALL, UN_MATCHED_ID, "en", 5);
assertEquals("best track ", INFO_2_EN_5, result);
}
+ @Test
public void testGetBestTrackInfo_languageOnlyMatch() {
TvTrackInfo result = getBestTrackInfo(ALL, UN_MATCHED_ID, "fr", 1);
assertEquals("best track ", INFO_3_FR_8, result);
}
+ @Test
public void testGetBestTrackInfo_channelCountOnlyMatchWithNullLanguage() {
TvTrackInfo result = getBestTrackInfo(ALL, UN_MATCHED_ID, null, 8);
assertEquals("best track ", INFO_3_FR_8, result);
}
+ @Test
public void testGetBestTrackInfo_noMatches() {
TvTrackInfo result = getBestTrackInfo(ALL, UN_MATCHED_ID, "kr", 1);
assertEquals("best track ", INFO_1_EN_1, result);
}
+ @Test
public void testGetBestTrackInfo_noMatchesWithNullLanguage() {
TvTrackInfo result = getBestTrackInfo(ALL, UN_MATCHED_ID, null, 0);
assertEquals("best track ", INFO_1_EN_1, result);
}
+ @Test
public void testGetBestTrackInfo_channelCountAndIdMatch() {
TvTrackInfo result = getBestTrackInfo(NULL_LANGUAGE_TRACKS, "5", null, 6);
assertEquals("best track ", INFO_5_NULL_6, result);
}
+ @Test
public void testComparator() {
Comparator<TvTrackInfo> comparator = TvTrackInfoUtils.createComparator("1", "en", 1);
ComparatorTester.withoutEqualsTest(comparator)
diff --git a/tests/unit/src/com/android/tv/util/UtilsTest_GetDurationString.java b/tests/unit/src/com/android/tv/util/UtilsTest_GetDurationString.java
index 9dfb992e..e61802f5 100644
--- a/tests/unit/src/com/android/tv/util/UtilsTest_GetDurationString.java
+++ b/tests/unit/src/com/android/tv/util/UtilsTest_GetDurationString.java
@@ -15,10 +15,16 @@
*/
package com.android.tv.util;
+import static android.support.test.InstrumentationRegistry.getContext;
+import static org.junit.Assert.assertEquals;
+
import android.support.test.filters.SmallTest;
-import android.test.AndroidTestCase;
import android.text.format.DateUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;
@@ -32,7 +38,7 @@ import java.util.Locale;
* and it should be defined in TV app, not this test.
*/
@SmallTest
-public class UtilsTest_GetDurationString extends AndroidTestCase {
+public class UtilsTest_GetDurationString {
// TODO: Mock Context so we can specify current time and locale for test.
private Locale mLocale;
private static final long DATE_THIS_YEAR_2_1_MS = getFebOfThisYearInMillis(1, 0, 0);
@@ -40,14 +46,19 @@ public class UtilsTest_GetDurationString extends AndroidTestCase {
// All possible list for a parameter to test parameter independent result.
private static final boolean[] PARAM_USE_SHORT_FORMAT = {false, true};
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() {
// Set locale to US
mLocale = Locale.getDefault();
Locale.setDefault(Locale.US);
}
+ @After
+ public void tearDown() {
+ // Revive system locale.
+ Locale.setDefault(mLocale);
+ }
+
/**
* Return time in millis assuming that whose year is this year and month is Jan.
*/
@@ -76,6 +87,7 @@ public class UtilsTest_GetDurationString extends AndroidTestCase {
return new GregorianCalendar().get(GregorianCalendar.YEAR);
}
+ @Test
public void testSameDateAndTime() {
assertEquals("3:00 AM", Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS,
getFebOfThisYearInMillis(1, 3), getFebOfThisYearInMillis(1, 3), false,
@@ -85,6 +97,7 @@ public class UtilsTest_GetDurationString extends AndroidTestCase {
DateUtils.FORMAT_24HOUR));
}
+ @Test
public void testDurationWithinToday() {
assertEquals("12:00 – 3:00 AM",
Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, DATE_THIS_YEAR_2_1_MS,
@@ -96,6 +109,7 @@ public class UtilsTest_GetDurationString extends AndroidTestCase {
DateUtils.FORMAT_24HOUR));
}
+ @Test
public void testDurationFromYesterdayToToday() {
assertEquals("Jan 31, 3:00 AM – Feb 1, 4:00 AM",
Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS,
@@ -115,6 +129,7 @@ public class UtilsTest_GetDurationString extends AndroidTestCase {
true, DateUtils.FORMAT_24HOUR));
}
+ @Test
public void testDurationFromTodayToTomorrow() {
assertEquals("Feb 1, 3:00 AM – Feb 2, 4:00 AM",
Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS,
@@ -154,6 +169,7 @@ public class UtilsTest_GetDurationString extends AndroidTestCase {
DateUtils.FORMAT_24HOUR));
}
+ @Test
public void testDurationWithinTomorrow() {
assertEquals("Feb 2, 2:00 – 4:00 AM",
Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS,
@@ -173,6 +189,7 @@ public class UtilsTest_GetDurationString extends AndroidTestCase {
DateUtils.FORMAT_24HOUR));
}
+ @Test
public void testStartOfDay() {
assertEquals("12:00 – 1:00 AM",
Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, DATE_THIS_YEAR_2_1_MS,
@@ -201,6 +218,7 @@ public class UtilsTest_GetDurationString extends AndroidTestCase {
DateUtils.FORMAT_24HOUR));
}
+ @Test
public void testEndOfDay() {
for (boolean useShortFormat : PARAM_USE_SHORT_FORMAT) {
assertEquals("11:00 PM – 12:00 AM",
@@ -241,6 +259,7 @@ public class UtilsTest_GetDurationString extends AndroidTestCase {
DateUtils.FORMAT_24HOUR));
}
+ @Test
public void testMidnight() {
for (boolean useShortFormat : PARAM_USE_SHORT_FORMAT) {
assertEquals("12:00 AM", Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS,
@@ -251,11 +270,4 @@ public class UtilsTest_GetDurationString extends AndroidTestCase {
DateUtils.FORMAT_24HOUR));
}
}
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- // Revive system locale.
- Locale.setDefault(mLocale);
- }
}
diff --git a/tests/unit/src/com/android/tv/util/UtilsTest_GetMultiAudioString.java b/tests/unit/src/com/android/tv/util/UtilsTest_GetMultiAudioString.java
index 8a6f3e3b..1e75342b 100644
--- a/tests/unit/src/com/android/tv/util/UtilsTest_GetMultiAudioString.java
+++ b/tests/unit/src/com/android/tv/util/UtilsTest_GetMultiAudioString.java
@@ -16,21 +16,26 @@
package com.android.tv.util;
+import static android.support.test.InstrumentationRegistry.getTargetContext;
+import static org.junit.Assert.assertEquals;
+
import android.content.Context;
import android.media.tv.TvTrackInfo;
import android.support.test.filters.SmallTest;
-import android.test.AndroidTestCase;
+
+import org.junit.Test;
/**
* Tests for {@link com.android.tv.util.Utils#getMultiAudioString}.
*/
@SmallTest
-public class UtilsTest_GetMultiAudioString extends AndroidTestCase {
+public class UtilsTest_GetMultiAudioString {
private static final String TRACK_ID = "test_track_id";
private static final int AUDIO_SAMPLE_RATE = 48000;
+ @Test
public void testAudioTrackLanguage() {
- Context context = getContext();
+ Context context = getTargetContext();
assertEquals("Korean",
Utils.getMultiAudioString(context, createAudioTrackInfo("kor"), false));
assertEquals("English",
@@ -42,8 +47,9 @@ public class UtilsTest_GetMultiAudioString extends AndroidTestCase {
assertEquals("abc", Utils.getMultiAudioString(context, createAudioTrackInfo("abc"), false));
}
+ @Test
public void testAudioTrackCount() {
- Context context = getContext();
+ Context context = getTargetContext();
assertEquals("English",
Utils.getMultiAudioString(context, createAudioTrackInfo("eng", -1), false));
assertEquals("English",
@@ -66,11 +72,14 @@ public class UtilsTest_GetMultiAudioString extends AndroidTestCase {
Utils.getMultiAudioString(context, createAudioTrackInfo("eng", 8), false));
}
+ @Test
public void testShowSampleRate() {
assertEquals("Korean (48kHz)",
- Utils.getMultiAudioString(getContext(), createAudioTrackInfo("kor", 0), true));
+ Utils.getMultiAudioString(getTargetContext(),
+ createAudioTrackInfo("kor", 0), true));
assertEquals("Korean (7.1 surround, 48kHz)",
- Utils.getMultiAudioString(getContext(), createAudioTrackInfo("kor", 8), true));
+ Utils.getMultiAudioString(getTargetContext(),
+ createAudioTrackInfo("kor", 8), true));
}
private static TvTrackInfo createAudioTrackInfo(String language) {
diff --git a/tests/unit/src/com/android/tv/util/UtilsTest_IsInGivenDay.java b/tests/unit/src/com/android/tv/util/UtilsTest_IsInGivenDay.java
index 926deb07..2b43abc1 100644
--- a/tests/unit/src/com/android/tv/util/UtilsTest_IsInGivenDay.java
+++ b/tests/unit/src/com/android/tv/util/UtilsTest_IsInGivenDay.java
@@ -16,8 +16,12 @@
package com.android.tv.util;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import android.support.test.filters.SmallTest;
-import android.test.AndroidTestCase;
+
+import org.junit.Test;
import java.util.Calendar;
import java.util.GregorianCalendar;
@@ -27,19 +31,22 @@ import java.util.TimeZone;
* Tests for {@link com.android.tv.util.Utils#isInGivenDay}.
*/
@SmallTest
-public class UtilsTest_IsInGivenDay extends AndroidTestCase {
+public class UtilsTest_IsInGivenDay {
+ @Test
public void testIsInGivenDay() {
assertTrue(Utils.isInGivenDay(
new GregorianCalendar(2015, Calendar.JANUARY, 1).getTimeInMillis(),
new GregorianCalendar(2015, Calendar.JANUARY, 1, 0, 30).getTimeInMillis()));
}
+ @Test
public void testIsNotInGivenDay() {
assertFalse(Utils.isInGivenDay(
new GregorianCalendar(2015, Calendar.JANUARY, 1).getTimeInMillis(),
new GregorianCalendar(2015, Calendar.JANUARY, 2).getTimeInMillis()));
}
+ @Test
public void testIfTimeZoneApplied() {
TimeZone timeZone = TimeZone.getDefault();