diff options
author | Nick Chalko <nchalko@google.com> | 2015-09-01 09:05:04 -0700 |
---|---|---|
committer | Nick Chalko <nchalko@google.com> | 2015-09-16 06:46:50 -0700 |
commit | 07b043dc3db83d6d20f0e8513b946830ab00e37b (patch) | |
tree | 705ade719e5c2853c070fe40b8518a56ac37f6d0 /tests/unit/src/com/android | |
parent | b5429e4406a580953bbdac5817e421cf0ab7aae3 (diff) | |
download | TV-07b043dc3db83d6d20f0e8513b946830ab00e37b.tar.gz |
Sync to ub-tv-friends at 1.06.202
git hash 3c1965f5dcc60243f1fe600cb35f19bd5f01fc27
Change-Id: I90b77790f9074677ecef72a23235d2b33eacb76a
Diffstat (limited to 'tests/unit/src/com/android')
22 files changed, 320 insertions, 98 deletions
diff --git a/tests/unit/src/com/android/tv/BaseMainActivityTestCase.java b/tests/unit/src/com/android/tv/BaseMainActivityTestCase.java index 99d5ea3e..208085d6 100644 --- a/tests/unit/src/com/android/tv/BaseMainActivityTestCase.java +++ b/tests/unit/src/com/android/tv/BaseMainActivityTestCase.java @@ -25,6 +25,7 @@ import com.android.tv.testing.ChannelInfo; import com.android.tv.testing.testinput.ChannelStateData; import com.android.tv.testing.testinput.TestInputControlConnection; import com.android.tv.testing.testinput.TestInputControlUtils; +import com.android.tv.testing.testinput.TvTestInputConstants; import java.util.List; @@ -117,6 +118,11 @@ public abstract class BaseMainActivityTestCase * @param channel the channel to tune to */ protected void updateThenTune(ChannelStateData data, ChannelInfo channel) { + if (channel.equals(TvTestInputConstants.CH_1_DEFAULT_DONT_MODIFY)) { + throw new IllegalArgumentException( + "By convention " + TvTestInputConstants.CH_1_DEFAULT_DONT_MODIFY.name + + " should not be modified."); + } mConnection.updateChannelState(channel, data); tuneToChannel(channel); } diff --git a/tests/unit/src/com/android/tv/MainActivityTest.java b/tests/unit/src/com/android/tv/MainActivityTest.java index ae789895..04271a7b 100644 --- a/tests/unit/src/com/android/tv/MainActivityTest.java +++ b/tests/unit/src/com/android/tv/MainActivityTest.java @@ -51,6 +51,7 @@ public class MainActivityTest extends BaseMainActivityTestCase { public void testShowProgramGuide() throws Throwable { tuneToChannel(TvTestInputConstants.CH_2); showProgramGuide(); + getInstrumentation().waitForIdleSync(); assertChannelBannerShown(false); assertProgramGuide(true); } @@ -70,8 +71,8 @@ public class MainActivityTest extends BaseMainActivityTestCase { assertEquals("Channel Name", displayName, channelNameView.getText()); } - private View assertProgramGuide(boolean isShown) { - return assertViewIsShown("Program Guide", R.id.program_guide, isShown); + private void assertProgramGuide(boolean isShown) { + assertViewIsShown("Program Guide", R.id.program_guide, isShown); } private ChannelBannerView assertChannelBannerShown(boolean isShown) { diff --git a/tests/unit/src/com/android/tv/data/ChannelDataManagerTest.java b/tests/unit/src/com/android/tv/data/ChannelDataManagerTest.java index 38ccdfb6..b239d0ed 100644 --- a/tests/unit/src/com/android/tv/data/ChannelDataManagerTest.java +++ b/tests/unit/src/com/android/tv/data/ChannelDataManagerTest.java @@ -36,6 +36,7 @@ import android.text.TextUtils; import android.util.Log; import android.util.SparseArray; +import com.android.tv.analytics.StubTracker; import com.android.tv.testing.ChannelInfo; import com.android.tv.testing.Constants; import com.android.tv.util.TvInputManagerHelper; @@ -44,6 +45,7 @@ import org.mockito.Matchers; import org.mockito.Mockito; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -83,8 +85,8 @@ public class ChannelDataManagerTest extends AndroidTestCase { mContentResolver.addProvider(TvContract.AUTHORITY, mContentProvider); mHandlerThread = new HandlerThread(TAG); mHandlerThread.start(); - mChannelDataManager = new ChannelDataManager( - getContext(), mockHelper, mContentResolver, mHandlerThread.getLooper()); + mChannelDataManager = new ChannelDataManager(getContext(), mockHelper, new StubTracker(), + mContentResolver, mHandlerThread.getLooper()); mListener = new TestChannelDataManagerListener(); mChannelDataManager.addListener(mListener); @@ -171,7 +173,7 @@ public class ChannelDataManagerTest extends AndroidTestCase { public void testBrowsable() throws Exception { startAndWaitForComplete(); - // Test if all channels are browable + // Test if all channels are browsable List<Channel> channelList = new ArrayList<>(mChannelDataManager.getChannelList()); List<Channel> browsableChannelList = mChannelDataManager.getBrowsableChannelList(); for (Channel browsableChannel : browsableChannelList) { @@ -276,7 +278,8 @@ public class ChannelDataManagerTest extends AndroidTestCase { ChannelInfo testChannelInfo = ChannelInfo.create(getContext(), (int) testChannelId); testChannelId = Constants.UNIT_TEST_CHANNEL_COUNT + 1; mContentProvider.simulateInsert(testChannelInfo); - assertTrue(mListener.channeListUpdatedLatch.await(WAIT_TIME_OUT_MS, TimeUnit.MILLISECONDS)); + assertTrue( + mListener.channelListUpdatedLatch.await(WAIT_TIME_OUT_MS, TimeUnit.MILLISECONDS)); assertEquals(Constants.UNIT_TEST_CHANNEL_COUNT + 1, mChannelDataManager.getChannelCount()); // Test channel update @@ -286,9 +289,10 @@ public class ChannelDataManagerTest extends AndroidTestCase { mChannelDataManager.addChannelListener(testChannelId, channelListener); String newName = testChannelInfo.name + "_test"; mContentProvider.simulateUpdate(testChannelId, newName); - assertTrue(mListener.channeListUpdatedLatch.await(WAIT_TIME_OUT_MS, TimeUnit.MILLISECONDS)); - assertTrue(channelListener.channelChangedLatch.await( - WAIT_TIME_OUT_MS, TimeUnit.MILLISECONDS)); + assertTrue( + mListener.channelListUpdatedLatch.await(WAIT_TIME_OUT_MS, TimeUnit.MILLISECONDS)); + assertTrue( + channelListener.channelChangedLatch.await(WAIT_TIME_OUT_MS, TimeUnit.MILLISECONDS)); assertEquals(0, channelListener.removedChannels.size()); assertEquals(1, channelListener.updatedChannels.size()); Channel updatedChannel = channelListener.updatedChannels.get(0); @@ -302,9 +306,10 @@ public class ChannelDataManagerTest extends AndroidTestCase { mListener.reset(); channelListener.reset(); mContentProvider.simulateDelete(testChannelId); - assertTrue(mListener.channeListUpdatedLatch.await(WAIT_TIME_OUT_MS, TimeUnit.MILLISECONDS)); - assertTrue(channelListener.channelChangedLatch.await( - WAIT_TIME_OUT_MS, TimeUnit.MILLISECONDS)); + assertTrue( + mListener.channelListUpdatedLatch.await(WAIT_TIME_OUT_MS, TimeUnit.MILLISECONDS)); + assertTrue( + channelListener.channelChangedLatch.await(WAIT_TIME_OUT_MS, TimeUnit.MILLISECONDS)); assertEquals(1, channelListener.removedChannels.size()); assertEquals(0, channelListener.updatedChannels.size()); Channel removedChannel = channelListener.removedChannels.get(0); @@ -344,7 +349,7 @@ public class ChannelDataManagerTest extends AndroidTestCase { // This implements the minimal methods in content resolver // and detailed assumptions are written in each method. private class FakeContentProvider extends MockContentProvider { - private SparseArray<ChannelInfoWrapper> mChannelInfoList = new SparseArray<>(); + private final SparseArray<ChannelInfoWrapper> mChannelInfoList = new SparseArray<>(); public FakeContentProvider(Context context) { super(context); @@ -365,14 +370,8 @@ public class ChannelDataManagerTest extends AndroidTestCase { if (DEBUG) { Log.d(TAG, "dump query"); Log.d(TAG, " uri=" + uri); - if (projection == null || projection.length == 0) { - Log.d(TAG, " projection=" + projection); - } else { - for (int i = 0; i < projection.length; i++) { - Log.d(TAG, " projection=" + projection[i]); - } - } - Log.d(TAG," selection=" + selection); + Log.d(TAG, " projection=" + Arrays.toString(projection)); + Log.d(TAG, " selection=" + selection); } assertChannelUri(uri); return new FakeCursor(projection); @@ -493,7 +492,7 @@ public class ChannelDataManagerTest extends AndroidTestCase { } private class FakeCursor extends MockCursor { - private String[] ALL_COLUMNS = { + private final String[] ALL_COLUMNS = { Channels._ID, Channels.COLUMN_DISPLAY_NAME, Channels.COLUMN_DISPLAY_NUMBER, @@ -502,7 +501,7 @@ public class ChannelDataManagerTest extends AndroidTestCase { Channels.COLUMN_ORIGINAL_NETWORK_ID, COLUMN_BROWSABLE, COLUMN_LOCKED}; - private String[] mColumns; + private final String[] mColumns; private int mPosition; public FakeCursor(String[] columns) { @@ -594,7 +593,7 @@ public class ChannelDataManagerTest extends AndroidTestCase { private class TestChannelDataManagerListener implements ChannelDataManager.Listener { public CountDownLatch loadFinishedLatch = new CountDownLatch(1); - public CountDownLatch channeListUpdatedLatch = new CountDownLatch(1); + public CountDownLatch channelListUpdatedLatch = new CountDownLatch(1); public boolean channelBrowsableChangedCalled; @Override @@ -604,7 +603,7 @@ public class ChannelDataManagerTest extends AndroidTestCase { @Override public void onChannelListUpdated() { - channeListUpdatedLatch.countDown(); + channelListUpdatedLatch.countDown(); } @Override @@ -614,7 +613,7 @@ public class ChannelDataManagerTest extends AndroidTestCase { public void reset() { loadFinishedLatch = new CountDownLatch(1); - channeListUpdatedLatch = new CountDownLatch(1); + channelListUpdatedLatch = new CountDownLatch(1); channelBrowsableChangedCalled = false; } } @@ -622,8 +621,8 @@ public class ChannelDataManagerTest extends AndroidTestCase { private class TestChannelDataManagerChannelListener implements ChannelDataManager.ChannelListener { public CountDownLatch channelChangedLatch = new CountDownLatch(1); - public List<Channel> removedChannels = new ArrayList<>(); - public List<Channel> updatedChannels = new ArrayList<>(); + public final List<Channel> removedChannels = new ArrayList<>(); + public final List<Channel> updatedChannels = new ArrayList<>(); @Override public void onChannelRemoved(Channel channel) { diff --git a/tests/unit/src/com/android/tv/data/ChannelNumberTest.java b/tests/unit/src/com/android/tv/data/ChannelNumberTest.java index 9914f75e..1935b4d9 100644 --- a/tests/unit/src/com/android/tv/data/ChannelNumberTest.java +++ b/tests/unit/src/com/android/tv/data/ChannelNumberTest.java @@ -54,15 +54,17 @@ public class ChannelNumberTest extends TestCase { */ public void testCompareTo() { new ComparableTester<ChannelNumber>() - .addEquivelentGroup(parseChannelNumber("1"), parseChannelNumber("1")) - .addEquivelentGroup(parseChannelNumber("2")) - .addEquivelentGroup(parseChannelNumber("2 1"), parseChannelNumber("2.1"), + .addEquivalentGroup(parseChannelNumber("1"), parseChannelNumber("1")) + .addEquivalentGroup(parseChannelNumber("2")) + .addEquivalentGroup(parseChannelNumber("2 1"), parseChannelNumber("2.1"), parseChannelNumber("2-1")) - .addEquivelentGroup(parseChannelNumber("2-2")) - .addEquivelentGroup(parseChannelNumber("2-10")) - .addEquivelentGroup(parseChannelNumber("3")) - .addEquivelentGroup(parseChannelNumber("10")) - .addEquivelentGroup(parseChannelNumber("100")) + .addEquivalentGroup(parseChannelNumber("2-2")) + .addEquivalentGroup(parseChannelNumber("2-10")) + .addEquivalentGroup(parseChannelNumber("3")) + .addEquivalentGroup(parseChannelNumber("4"), parseChannelNumber("4 0"), + parseChannelNumber("4.0"), parseChannelNumber("4-0")) + .addEquivalentGroup(parseChannelNumber("10")) + .addEquivalentGroup(parseChannelNumber("100")) .test(); } @@ -70,7 +72,7 @@ public class ChannelNumberTest extends TestCase { * Test method for {@link ChannelNumber#compare(java.lang.String, java.lang.String)}. */ public void testCompare() { - // Only need to test nulls, the reset is tested by testComparteTo + // Only need to test nulls, the reset is tested by testCompareTo assertEquals("compareTo(null,null)", 0, ChannelNumber.compare(null, null)); assertEquals("compareTo(1,1)", 0, ChannelNumber.compare("1", "1")); assertEquals("compareTo(null,1)<0", true, ChannelNumber.compare(null, "1") < 0); diff --git a/tests/unit/src/com/android/tv/data/ChannelTest.java b/tests/unit/src/com/android/tv/data/ChannelTest.java index f32bf02a..c39942d9 100644 --- a/tests/unit/src/com/android/tv/data/ChannelTest.java +++ b/tests/unit/src/com/android/tv/data/ChannelTest.java @@ -22,6 +22,7 @@ import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.SmallTest; import com.android.tv.testing.ComparatorTester; import com.android.tv.util.TvInputManagerHelper; @@ -36,6 +37,7 @@ import java.util.Comparator; /** * Tests for {@link Channel}. */ +@SmallTest public class ChannelTest extends AndroidTestCase { // Used for testing TV inputs with invalid input package. This could happen when a TV input is // uninstalled while drawing an app link card. @@ -50,40 +52,41 @@ public class ChannelTest extends AndroidTestCase { private static final String LEANBACK_TV_INPUT_PACKAGE_NAME = "com.android.tv.leanback_tv_input"; private static final String TEST_APP_LINK_TEXT = "test_app_link_text"; + private static final String PARTNER_INPUT_ID = "partner"; private static final ActivityInfo TEST_ACTIVITY_INFO = new ActivityInfo(); private Context mMockContext; private Intent mInvalidIntent; private Intent mValidIntent; - private Intent mLiveChannelsIntent; - private Intent mLeanbackTvInputIntent; + @Override public void setUp() throws Exception { super.setUp(); mInvalidIntent = new Intent(Intent.ACTION_VIEW); mInvalidIntent.setComponent(new ComponentName(INVALID_TV_INPUT_PACKAGE_NAME, ".test")); mValidIntent = new Intent(Intent.ACTION_VIEW); mValidIntent.setComponent(new ComponentName(LEANBACK_TV_INPUT_PACKAGE_NAME, ".test")); - mLiveChannelsIntent = new Intent(Intent.ACTION_VIEW); - mLiveChannelsIntent.setComponent( + Intent liveChannelsIntent = new Intent(Intent.ACTION_VIEW); + liveChannelsIntent.setComponent( new ComponentName(LIVE_CHANNELS_PACKAGE_NAME, ".MainActivity")); - mLeanbackTvInputIntent = new Intent(Intent.ACTION_VIEW); - mLeanbackTvInputIntent.setComponent( + Intent leanbackTvInputIntent = new Intent(Intent.ACTION_VIEW); + leanbackTvInputIntent.setComponent( new ComponentName(LEANBACK_TV_INPUT_PACKAGE_NAME, ".test")); PackageManager mockPackageManager = Mockito.mock(PackageManager.class); Mockito.when(mockPackageManager.getLeanbackLaunchIntentForPackage( INVALID_TV_INPUT_PACKAGE_NAME)).thenReturn(null); Mockito.when(mockPackageManager.getLeanbackLaunchIntentForPackage( - LIVE_CHANNELS_PACKAGE_NAME)).thenReturn(mLiveChannelsIntent); + LIVE_CHANNELS_PACKAGE_NAME)).thenReturn(liveChannelsIntent); Mockito.when(mockPackageManager.getLeanbackLaunchIntentForPackage( NONE_LEANBACK_TV_INPUT_PACKAGE_NAME)).thenReturn(null); Mockito.when(mockPackageManager.getLeanbackLaunchIntentForPackage( - LEANBACK_TV_INPUT_PACKAGE_NAME)).thenReturn(mLeanbackTvInputIntent); + LEANBACK_TV_INPUT_PACKAGE_NAME)).thenReturn(leanbackTvInputIntent); // Channel.getAppLinkIntent() calls initAppLinkTypeAndIntent() which calls // Intent.resolveActivityInfo() which calls PackageManager.getActivityInfo(). Mockito.doAnswer(new Answer<ActivityInfo>() { + @Override public ActivityInfo answer(InvocationOnMock invocation) { // We only check the package name, since the class name can be changed // when an intent is changed to an uri and created from the uri. @@ -165,17 +168,19 @@ public class ChannelTest extends AndroidTestCase { private void assertAppLinkType(int expectedType, String inputPackageName, String appLinkText, Intent appLinkIntent) { + // In Channel, Intent.URI_INTENT_SCHEME is used to parse the URI. So the same flag should be + // used when the URI is created. Channel testChannel = new Channel.Builder() .setPackageName(inputPackageName) .setAppLinkText(appLinkText) - .setAppLinkIntentUri(appLinkIntent == null ? null : appLinkIntent.toUri(0)) + .setAppLinkIntentUri(appLinkIntent == null ? null : appLinkIntent.toUri( + Intent.URI_INTENT_SCHEME)) .build(); assertEquals("Unexpected app-link type for for " + testChannel, expectedType, testChannel.getAppLinkType(mMockContext)); } public void testComparator() { - final String PARTNER_INPUT_ID = "partner"; TvInputManagerHelper manager = Mockito.mock(TvInputManagerHelper.class); Mockito.when(manager.isPartnerInput(Matchers.anyString())).thenAnswer( @@ -183,18 +188,23 @@ public class ChannelTest extends AndroidTestCase { @Override public Boolean answer(InvocationOnMock invocation) throws Throwable { String inputId = (String) invocation.getArguments()[0]; - return PARTNER_INPUT_ID.equals(inputId); + boolean isPartner = PARTNER_INPUT_ID.equals(inputId); + return isPartner; } }); Comparator<Channel> comparator = new TestChannelComparator(manager); ComparatorTester<Channel> comparatorTester = ComparatorTester.withoutEqualsTest(comparator); comparatorTester.addComparableGroup( - new Channel.Builder().setInputId(PARTNER_INPUT_ID).setDisplayNumber("100").build()); + new Channel.Builder().setInputId(PARTNER_INPUT_ID).build()); + comparatorTester.addComparableGroup( + new Channel.Builder().setInputId("1").build()); comparatorTester.addComparableGroup( new Channel.Builder().setInputId("1").setDisplayNumber("2").build()); comparatorTester.addComparableGroup( new Channel.Builder().setInputId("2").setDisplayNumber("1.0").build()); + + // display name does not affect comparator comparatorTester.addComparableGroup( new Channel.Builder().setInputId("2").setDisplayNumber("1.62") .setDisplayName("test1").build(), @@ -204,11 +214,47 @@ public class ChannelTest extends AndroidTestCase { .setDisplayName("test3").build()); comparatorTester.addComparableGroup( new Channel.Builder().setInputId("2").setDisplayNumber("2.0").build()); + // Numeric display number sorting comparatorTester.addComparableGroup( new Channel.Builder().setInputId("2").setDisplayNumber("12.2").build()); comparatorTester.test(); } + /** + * Test Input Label handled by {@link com.android.tv.data.Channel.DefaultComparator}. + * + * <p>Sort partner inputs first, then sort by input label, then by input id. + * See <a href="http://b/23031603">b/23031603</a>. + */ + public void testComparatorLabel() { + + TvInputManagerHelper manager = Mockito.mock(TvInputManagerHelper.class); + Mockito.when(manager.isPartnerInput(Matchers.anyString())).thenAnswer( + new Answer<Boolean>() { + @Override + public Boolean answer(InvocationOnMock invocation) throws Throwable { + String inputId = (String) invocation.getArguments()[0]; + return PARTNER_INPUT_ID.equals(inputId); + } + }); + Comparator<Channel> comparator = new ChannelComparatorWithDescriptionAsLabel(manager); + ComparatorTester<Channel> comparatorTester = + ComparatorTester.withoutEqualsTest(comparator); + + comparatorTester.addComparableGroup( + new Channel.Builder().setInputId(PARTNER_INPUT_ID).setDescription("A").build()); + + // The description is used as a label for this test. + comparatorTester.addComparableGroup( + new Channel.Builder().setDescription("A").setInputId("1").build()); + comparatorTester.addComparableGroup( + new Channel.Builder().setDescription("A").setInputId("2").build()); + comparatorTester.addComparableGroup( + new Channel.Builder().setDescription("B").setInputId("1").build()); + + comparatorTester.test(); + } + private class TestChannelComparator extends Channel.DefaultComparator { public TestChannelComparator(TvInputManagerHelper manager) { super(null, manager); @@ -218,5 +264,16 @@ public class ChannelTest extends AndroidTestCase { public String getInputLabelForChannel(Channel channel) { return channel.getInputId(); } - }; + } + + private static class ChannelComparatorWithDescriptionAsLabel extends Channel.DefaultComparator { + public ChannelComparatorWithDescriptionAsLabel(TvInputManagerHelper manager) { + super(null, manager); + } + + @Override + public String getInputLabelForChannel(Channel channel) { + return channel.getDescription(); + } + } } diff --git a/tests/unit/src/com/android/tv/data/ProgramDataManagerTest.java b/tests/unit/src/com/android/tv/data/ProgramDataManagerTest.java index 31ad54f0..60e3e210 100644 --- a/tests/unit/src/com/android/tv/data/ProgramDataManagerTest.java +++ b/tests/unit/src/com/android/tv/data/ProgramDataManagerTest.java @@ -37,6 +37,7 @@ import com.android.tv.util.FakeClock; import com.android.tv.util.Utils; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -257,17 +258,18 @@ public class ProgramDataManagerTest extends AndroidTestCase { private final int index; private final long startTimeMs; private final ProgramInfo programInfo; + public ProgramInfoWrapper(int index, long startTimeMs, ProgramInfo programInfo) { this.index = index; this.startTimeMs = startTimeMs; this.programInfo = programInfo; } } - + // This implements the minimal methods in content resolver // and detailed assumptions are written in each method. private class FakeContentProvider extends MockContentProvider { - private SparseArray<List<ProgramInfoWrapper>> mProgramInfoList = new SparseArray<>(); + private final SparseArray<List<ProgramInfoWrapper>> mProgramInfoList = new SparseArray<>(); /** * Constructor for FakeContentProvider @@ -304,14 +306,8 @@ public class ProgramDataManagerTest extends AndroidTestCase { if (DEBUG) { Log.d(TAG, "dump query"); Log.d(TAG, " uri=" + uri); - if (projection == null || projection.length == 0) { - Log.d(TAG, " projection=" + projection); - } else { - for (int i = 0; i < projection.length; i++) { - Log.d(TAG, " projection=" + projection[i]); - } - } - Log.d(TAG," selection=" + selection); + Log.d(TAG, " projection=" + Arrays.toString(projection)); + Log.d(TAG, " selection=" + selection); } long startTimeMs = Long.parseLong(uri.getQueryParameter(PARAM_START_TIME)); long endTimeMs = Long.parseLong(uri.getQueryParameter(PARAM_END_TIME)); @@ -368,7 +364,7 @@ public class ProgramDataManagerTest extends AndroidTestCase { } private class FakeCursor extends MockCursor { - private String[] ALL_COLUMNS = { + private final String[] ALL_COLUMNS = { TvContract.Programs.COLUMN_CHANNEL_ID, TvContract.Programs.COLUMN_TITLE, TvContract.Programs.COLUMN_SHORT_DESCRIPTION, @@ -409,9 +405,9 @@ public class ProgramDataManagerTest extends AndroidTestCase { mChannelId = channelId; mProgramPosition = -1; if (DEBUG) { - Log.d(TAG, "FakeCursor(columns=" + columns + ", channelId=" + channelId - + ", startTimeMs=" + startTimeMs + ", endTimeMs=" + endTimeMs - + ") has mCount=" + mCount); + Log.d(TAG, "FakeCursor(columns=" + Arrays.toString(columns) + + ", channelId=" + channelId + ", startTimeMs=" + startTimeMs + + ", endTimeMs=" + endTimeMs + ") has mCount=" + mCount); } } @@ -519,7 +515,7 @@ public class ProgramDataManagerTest extends AndroidTestCase { private class TestProgramDataManagerOnCurrentProgramUpdatedListener implements OnCurrentProgramUpdatedListener { - public CountDownLatch currentProgramUpdatedLatch = new CountDownLatch(1); + public final CountDownLatch currentProgramUpdatedLatch = new CountDownLatch(1); public long updatedChannelId = -1; public Program updatedProgram = null; diff --git a/tests/unit/src/com/android/tv/data/ProgramTest.java b/tests/unit/src/com/android/tv/data/ProgramTest.java index b4d78733..25856e18 100644 --- a/tests/unit/src/com/android/tv/data/ProgramTest.java +++ b/tests/unit/src/com/android/tv/data/ProgramTest.java @@ -18,6 +18,8 @@ package com.android.tv.data; import static android.media.tv.TvContract.Programs.Genres.COMEDY; import static android.media.tv.TvContract.Programs.Genres.FAMILY_KIDS; +import android.test.suitebuilder.annotation.SmallTest; + import junit.framework.TestCase; import java.util.Arrays; @@ -25,6 +27,7 @@ import java.util.Arrays; /** * Tests for {@link Program}. */ +@SmallTest public class ProgramTest extends TestCase { private static final int NOT_FOUND_GENRE = 987; diff --git a/tests/unit/src/com/android/tv/menu/MenuTest.java b/tests/unit/src/com/android/tv/menu/MenuTest.java new file mode 100644 index 00000000..324706f0 --- /dev/null +++ b/tests/unit/src/com/android/tv/menu/MenuTest.java @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2015 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.menu; + +import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.SmallTest; + +import com.android.tv.menu.Menu.OnMenuVisibilityChangeListener; + +import org.mockito.Matchers; +import org.mockito.Mockito; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; + +/** + * Tests for {@link Menu}. + */ +@SmallTest +public class MenuTest extends AndroidTestCase { + private Menu mMenu; + private IMenuView mMenuView; + private OnMenuVisibilityChangeListener mVisibilityChangeListener; + + @Override + protected void setUp() throws Exception { + super.setUp(); + mMenuView = Mockito.mock(IMenuView.class); + MenuRowFactory factory = Mockito.mock(MenuRowFactory.class); + Mockito.when(factory.createMenuRow(Mockito.any(Menu.class), Mockito.any(Class.class))) + .thenReturn(null); + mVisibilityChangeListener = Mockito.mock(OnMenuVisibilityChangeListener.class); + mMenu = new Menu(getContext(), mMenuView, factory, mVisibilityChangeListener); + mMenu.disableAnimationForTest(); + } + + public void testScheduleHide() { + mMenu.show(Menu.REASON_NONE); + setMenuVisible(true); + assertTrue("Hide is not scheduled", mMenu.isHideScheduled()); + mMenu.hide(false); + setMenuVisible(false); + assertFalse("Hide is scheduled", mMenu.isHideScheduled()); + + mMenu.setKeepVisible(true); + mMenu.show(Menu.REASON_NONE); + setMenuVisible(true); + assertFalse("Hide is scheduled", mMenu.isHideScheduled()); + mMenu.setKeepVisible(false); + assertTrue("Hide is not scheduled", mMenu.isHideScheduled()); + mMenu.setKeepVisible(true); + assertFalse("Hide is scheduled", mMenu.isHideScheduled()); + mMenu.hide(false); + setMenuVisible(false); + assertFalse("Hide is scheduled", mMenu.isHideScheduled()); + } + + public void testShowHide_ReasonNone() { + // Show with REASON_NONE + mMenu.show(Menu.REASON_NONE); + setMenuVisible(true); + // Listener should be called with "true" argument. + Mockito.verify(mVisibilityChangeListener, Mockito.atLeastOnce()) + .onMenuVisibilityChange(Matchers.eq(true)); + Mockito.verify(mVisibilityChangeListener, Mockito.never()) + .onMenuVisibilityChange(Matchers.eq(false)); + // IMenuView.show should be called with the same parameter. + Mockito.verify(mMenuView).onShow(Matchers.eq(Menu.REASON_NONE), + Matchers.isNull(String.class), Matchers.isNull(Runnable.class)); + mMenu.hide(true); + setMenuVisible(false); + // Listener should be called with "false" argument. + Mockito.verify(mVisibilityChangeListener, Mockito.atLeastOnce()) + .onMenuVisibilityChange(Matchers.eq(false)); + Mockito.verify(mMenuView).onHide(); + } + + public void testShowHide_ReasonGuide() { + // Show with REASON_GUIDE + mMenu.show(Menu.REASON_GUIDE); + setMenuVisible(true); + // Listener should be called with "true" argument. + Mockito.verify(mVisibilityChangeListener, Mockito.atLeastOnce()) + .onMenuVisibilityChange(Matchers.eq(true)); + Mockito.verify(mVisibilityChangeListener, Mockito.never()) + .onMenuVisibilityChange(Matchers.eq(false)); + // IMenuView.show should be called with the same parameter. + Mockito.verify(mMenuView).onShow(Matchers.eq(Menu.REASON_GUIDE), + Matchers.eq(ChannelsRow.ID), Matchers.isNull(Runnable.class)); + mMenu.hide(false); + setMenuVisible(false); + // Listener should be called with "false" argument. + Mockito.verify(mVisibilityChangeListener, Mockito.atLeastOnce()) + .onMenuVisibilityChange(Matchers.eq(false)); + Mockito.verify(mMenuView).onHide(); + } + + public void testShowHide_ReasonPlayControlsFastForward() { + // Show with REASON_PLAY_CONTROLS_FAST_FORWARD + mMenu.show(Menu.REASON_PLAY_CONTROLS_FAST_FORWARD); + setMenuVisible(true); + // Listener should be called with "true" argument. + Mockito.verify(mVisibilityChangeListener, Mockito.atLeastOnce()) + .onMenuVisibilityChange(Matchers.eq(true)); + Mockito.verify(mVisibilityChangeListener, Mockito.never()) + .onMenuVisibilityChange(Matchers.eq(false)); + // IMenuView.show should be called with the same parameter. + Mockito.verify(mMenuView).onShow(Matchers.eq(Menu.REASON_PLAY_CONTROLS_FAST_FORWARD), + Matchers.eq(PlayControlsRow.ID), Matchers.isNull(Runnable.class)); + mMenu.hide(false); + setMenuVisible(false); + // Listener should be called with "false" argument. + Mockito.verify(mVisibilityChangeListener, Mockito.atLeastOnce()) + .onMenuVisibilityChange(Matchers.eq(false)); + Mockito.verify(mMenuView).onHide(); + } + + private void setMenuVisible(final boolean visible) { + Mockito.when(mMenuView.isVisible()).thenAnswer(new Answer<Boolean>() { + @Override + public Boolean answer(InvocationOnMock invocation) throws Throwable { + return visible; + } + }); + } +} diff --git a/tests/unit/src/com/android/tv/menu/TvOptionsRowAdapterTest.java b/tests/unit/src/com/android/tv/menu/TvOptionsRowAdapterTest.java index 4ffd9fa9..34ed30fd 100644 --- a/tests/unit/src/com/android/tv/menu/TvOptionsRowAdapterTest.java +++ b/tests/unit/src/com/android/tv/menu/TvOptionsRowAdapterTest.java @@ -17,7 +17,7 @@ package com.android.tv.menu; import android.media.tv.TvTrackInfo; import android.os.SystemClock; -import android.test.suitebuilder.annotation.SmallTest; +import android.test.suitebuilder.annotation.MediumTest; import com.android.tv.BaseMainActivityTestCase; import com.android.tv.MainActivity; @@ -32,12 +32,11 @@ import java.util.List; /** * Tests for {@link TvOptionsRowAdapter}. */ -@SmallTest +@MediumTest public class TvOptionsRowAdapterTest extends BaseMainActivityTestCase { private static final int WAIT_TRACK_SIZE_TIMEOUT_MS = 300; public static final int TRACK_SIZE_CHECK_INTERVAL_MS = 10; - // TODO: Refactor TvOptionsRowAdapter so it does not rely on MainActivity private TvOptionsRowAdapter mTvOptionsRowAdapter; @@ -50,60 +49,63 @@ public class TvOptionsRowAdapterTest extends BaseMainActivityTestCase { super.setUp(); mTvOptionsRowAdapter = new TvOptionsRowAdapter(mActivity, Collections.<CustomAction>emptyList()); - tuneToChannel(TvTestInputConstants.CH_1); + tuneToChannel(TvTestInputConstants.CH_1_DEFAULT_DONT_MODIFY); + waitUntilAudioTracksHaveSize(1); + mTvOptionsRowAdapter.update(); } public void testUpdateAudioAction_2tracks() { - mTvOptionsRowAdapter.update(); ChannelStateData data = new ChannelStateData(); data.mTvTrackInfos.add(Constants.GENERIC_AUDIO_TRACK); updateThenTune(data, TvTestInputConstants.CH_2); - waitUntilTracksHaveSize(2); + waitUntilAudioTracksHaveSize(2); - boolean result = mTvOptionsRowAdapter.updateActions(); + boolean result = mTvOptionsRowAdapter.updateMultiAudioAction(); assertEquals("update Action had change", true, result); assertEquals("Multi Audio enabled", true, MenuAction.SELECT_AUDIO_LANGUAGE_ACTION.isEnabled()); } public void testUpdateAudioAction_1track() { - mTvOptionsRowAdapter.update(); ChannelStateData data = new ChannelStateData(); data.mTvTrackInfos.clear(); data.mTvTrackInfos.add(Constants.GENERIC_AUDIO_TRACK); updateThenTune(data, TvTestInputConstants.CH_2); - waitUntilTracksHaveSize(1); + waitUntilAudioTracksHaveSize(1); - boolean result = mTvOptionsRowAdapter.updateActions(); - assertEquals("update Action had change", true, result); + boolean result = mTvOptionsRowAdapter.updateMultiAudioAction(); + assertEquals("update Action had change", false, result); assertEquals("Multi Audio enabled", false, MenuAction.SELECT_AUDIO_LANGUAGE_ACTION.isEnabled()); } public void testUpdateAudioAction_noTracks() { - mTvOptionsRowAdapter.update(); ChannelStateData data = new ChannelStateData(); data.mTvTrackInfos.clear(); updateThenTune(data, TvTestInputConstants.CH_2); - waitUntilTracksHaveSize(0); + waitUntilAudioTracksHaveSize(0); - boolean result = mTvOptionsRowAdapter.updateActions(); + boolean result = mTvOptionsRowAdapter.updateMultiAudioAction(); assertEquals("update Action had change", false, result); assertEquals("Multi Audio enabled", false, MenuAction.SELECT_AUDIO_LANGUAGE_ACTION.isEnabled()); } - private void waitUntilTracksHaveSize(int expected) { + private void waitUntilAudioTracksHaveSize(int expected) { long start = SystemClock.elapsedRealtime(); + int size = -1; while (SystemClock.elapsedRealtime() < start + WAIT_TRACK_SIZE_TIMEOUT_MS) { getInstrumentation().waitForIdleSync(); List<TvTrackInfo> tracks = mActivity.getTracks(TvTrackInfo.TYPE_AUDIO); - if (tracks != null && tracks.size() == expected) { - return; + if (tracks != null) { + size = tracks.size(); + if (size == expected) { + return; + } } SystemClock.sleep(TRACK_SIZE_CHECK_INTERVAL_MS); } fail("Waited for " + WAIT_TRACK_SIZE_TIMEOUT_MS + " milliseconds for track size to be " - + expected); + + expected + " but was " + size); } } diff --git a/tests/unit/src/com/android/tv/recommendation/ChannelRecordTest.java b/tests/unit/src/com/android/tv/recommendation/ChannelRecordTest.java index 9b0e2805..44026386 100644 --- a/tests/unit/src/com/android/tv/recommendation/ChannelRecordTest.java +++ b/tests/unit/src/com/android/tv/recommendation/ChannelRecordTest.java @@ -17,6 +17,7 @@ package com.android.tv.recommendation; import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.SmallTest; import java.util.Random; import java.util.concurrent.TimeUnit; @@ -24,6 +25,7 @@ import java.util.concurrent.TimeUnit; /** * Unit tests for {@link ChannelRecord}. */ +@SmallTest public class ChannelRecordTest extends AndroidTestCase { private static final int CHANNEL_RECORD_MAX_HISTORY_SIZE = ChannelRecord.MAX_HISTORY_SIZE; @@ -31,6 +33,7 @@ public class ChannelRecordTest extends AndroidTestCase { private ChannelRecord mChannelRecord; private long mLatestWatchEndTimeMs; + @Override public void setUp() throws Exception { super.setUp(); mLatestWatchEndTimeMs = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1); diff --git a/tests/unit/src/com/android/tv/recommendation/EvaluatorTestCase.java b/tests/unit/src/com/android/tv/recommendation/EvaluatorTestCase.java index ee9fa95f..febeeda1 100644 --- a/tests/unit/src/com/android/tv/recommendation/EvaluatorTestCase.java +++ b/tests/unit/src/com/android/tv/recommendation/EvaluatorTestCase.java @@ -17,6 +17,7 @@ package com.android.tv.recommendation; import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.SmallTest; import com.android.tv.data.Channel; import com.android.tv.recommendation.RecommendationUtils.ChannelRecordSortedMapHelper; @@ -36,6 +37,7 @@ public abstract class EvaluatorTestCase<T extends Evaluator> extends AndroidTest public T mEvaluator; + @Override public void setUp() throws Exception { super.setUp(); mChannelRecordSortedMap = new ChannelRecordSortedMapHelper(getContext()); diff --git a/tests/unit/src/com/android/tv/recommendation/FavoriteChannelEvaluatorTest.java b/tests/unit/src/com/android/tv/recommendation/FavoriteChannelEvaluatorTest.java index c33271bc..0617845b 100644 --- a/tests/unit/src/com/android/tv/recommendation/FavoriteChannelEvaluatorTest.java +++ b/tests/unit/src/com/android/tv/recommendation/FavoriteChannelEvaluatorTest.java @@ -16,12 +16,15 @@ package com.android.tv.recommendation; +import android.test.suitebuilder.annotation.SmallTest; + import java.util.List; import java.util.concurrent.TimeUnit; /** * Unit tests for {@link FavoriteChannelEvaluator}. */ +@SmallTest public class FavoriteChannelEvaluatorTest extends EvaluatorTestCase<FavoriteChannelEvaluator> { private static final int DEFAULT_NUMBER_OF_CHANNELS = 4; private static final long DEFAULT_WATCH_START_TIME_MS = @@ -30,6 +33,7 @@ public class FavoriteChannelEvaluatorTest extends EvaluatorTestCase<FavoriteChan System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1); private static final long DEFAULT_MAX_WATCH_DURATION_MS = TimeUnit.HOURS.toMillis(1); + @Override public FavoriteChannelEvaluator createEvaluator() { return new FavoriteChannelEvaluator(); } diff --git a/tests/unit/src/com/android/tv/recommendation/RecentChannelEvaluatorTest.java b/tests/unit/src/com/android/tv/recommendation/RecentChannelEvaluatorTest.java index a888ceea..c67f3bc4 100644 --- a/tests/unit/src/com/android/tv/recommendation/RecentChannelEvaluatorTest.java +++ b/tests/unit/src/com/android/tv/recommendation/RecentChannelEvaluatorTest.java @@ -16,6 +16,8 @@ package com.android.tv.recommendation; +import android.test.suitebuilder.annotation.SmallTest; + import java.util.HashMap; import java.util.List; import java.util.Map; @@ -24,6 +26,7 @@ import java.util.concurrent.TimeUnit; /** * Unit tests for {@link RecentChannelEvaluator}. */ +@SmallTest public class RecentChannelEvaluatorTest extends EvaluatorTestCase<RecentChannelEvaluator> { private static final int DEFAULT_NUMBER_OF_CHANNELS = 4; private static final long DEFAULT_WATCH_START_TIME_MS = @@ -32,6 +35,7 @@ public class RecentChannelEvaluatorTest extends EvaluatorTestCase<RecentChannelE System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1); private static final long DEFAULT_MAX_WATCH_DURATION_MS = TimeUnit.HOURS.toMillis(1); + @Override public RecentChannelEvaluator createEvaluator() { return new RecentChannelEvaluator(); } diff --git a/tests/unit/src/com/android/tv/recommendation/RecommendationUtils.java b/tests/unit/src/com/android/tv/recommendation/RecommendationUtils.java index d275bfbb..8e57a267 100644 --- a/tests/unit/src/com/android/tv/recommendation/RecommendationUtils.java +++ b/tests/unit/src/com/android/tv/recommendation/RecommendationUtils.java @@ -86,7 +86,7 @@ public class RecommendationUtils { } public static class ChannelRecordSortedMapHelper extends TreeMap<Long, ChannelRecord> { - private Context mContext; + private final Context mContext; private Recommender mRecommender; private Random mRandom = createTestRandom(); diff --git a/tests/unit/src/com/android/tv/recommendation/RecommenderTest.java b/tests/unit/src/com/android/tv/recommendation/RecommenderTest.java index 4f16d168..62c5b4ab 100644 --- a/tests/unit/src/com/android/tv/recommendation/RecommenderTest.java +++ b/tests/unit/src/com/android/tv/recommendation/RecommenderTest.java @@ -18,6 +18,7 @@ package com.android.tv.recommendation; import android.test.AndroidTestCase; import android.test.MoreAsserts; +import android.test.suitebuilder.annotation.SmallTest; import com.android.tv.data.Channel; import com.android.tv.recommendation.RecommendationUtils.ChannelRecordSortedMapHelper; @@ -31,6 +32,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; +@SmallTest public class RecommenderTest extends AndroidTestCase { private static final int DEFAULT_NUMBER_OF_CHANNELS = 5; private static final long DEFAULT_WATCH_START_TIME_MS = @@ -69,6 +71,7 @@ public class RecommenderTest extends AndroidTestCase { private Channel mChannel_3; private Channel mChannel_4; + @Override public void setUp() throws Exception { super.setUp(); @@ -306,7 +309,7 @@ public class RecommenderTest extends AndroidTestCase { } private class FakeEvaluator extends Recommender.Evaluator { - private Map<Long, Double> mChannelScore = new HashMap<>(); + private final Map<Long, Double> mChannelScore = new HashMap<>(); @Override public double evaluateChannel(long channelId) { diff --git a/tests/unit/src/com/android/tv/recommendation/RoutineWatchEvaluatorTest.java b/tests/unit/src/com/android/tv/recommendation/RoutineWatchEvaluatorTest.java index e3c92859..2511094e 100644 --- a/tests/unit/src/com/android/tv/recommendation/RoutineWatchEvaluatorTest.java +++ b/tests/unit/src/com/android/tv/recommendation/RoutineWatchEvaluatorTest.java @@ -17,6 +17,7 @@ package com.android.tv.recommendation; import android.test.MoreAsserts; +import android.test.suitebuilder.annotation.SmallTest; import com.android.tv.data.Program; import com.android.tv.recommendation.RoutineWatchEvaluator.ProgramTime; @@ -25,8 +26,10 @@ import java.util.Calendar; import java.util.List; import java.util.concurrent.TimeUnit; +@SmallTest public class RoutineWatchEvaluatorTest extends EvaluatorTestCase<RoutineWatchEvaluator> { + @Override public RoutineWatchEvaluator createEvaluator() { return new RoutineWatchEvaluator(); } @@ -157,7 +160,7 @@ public class RoutineWatchEvaluatorTest extends EvaluatorTestCase<RoutineWatchEva private void assertOverlappedIntervalScore(int expectedSeconds, boolean overlappedOnSameDay, ProgramTime t1, ProgramTime t2) { - double score = (double) expectedSeconds; + double score = expectedSeconds; if (!overlappedOnSameDay) { score *= RoutineWatchEvaluator.MULTIPLIER_FOR_UNMATCHED_DAY_OF_WEEK; } diff --git a/tests/unit/src/com/android/tv/ui/SetupViewTest.java b/tests/unit/src/com/android/tv/ui/SetupViewTest.java index ce3b79fb..d3579d13 100644 --- a/tests/unit/src/com/android/tv/ui/SetupViewTest.java +++ b/tests/unit/src/com/android/tv/ui/SetupViewTest.java @@ -26,14 +26,14 @@ import com.android.tv.util.SetupUtils; import com.android.tv.util.TestUtils; import com.android.tv.util.TvInputManagerHelper; -import java.util.Comparator; -import java.util.LinkedHashMap; - import org.mockito.Matchers; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; +import java.util.Comparator; +import java.util.LinkedHashMap; + /** * Test for {@link SetupView} */ diff --git a/tests/unit/src/com/android/tv/util/ImageCacheTest.java b/tests/unit/src/com/android/tv/util/ImageCacheTest.java index a73b79fe..396372b2 100644 --- a/tests/unit/src/com/android/tv/util/ImageCacheTest.java +++ b/tests/unit/src/com/android/tv/util/ImageCacheTest.java @@ -19,6 +19,7 @@ package com.android.tv.util; import static com.android.tv.util.BitmapUtils.createScaledBitmapInfo; import android.graphics.Bitmap; +import android.test.suitebuilder.annotation.MediumTest; import com.android.tv.util.BitmapUtils.ScaledBitmapInfo; @@ -27,8 +28,8 @@ import junit.framework.TestCase; /** * Tests for {@link ImageCache}. */ +@MediumTest public class ImageCacheTest extends TestCase { - private static final Bitmap ORIG = Bitmap.createBitmap(100, 100, Bitmap.Config.RGB_565); private static final String KEY = "same"; diff --git a/tests/unit/src/com/android/tv/util/ScaledBitmapInfoTest.java b/tests/unit/src/com/android/tv/util/ScaledBitmapInfoTest.java index ef707470..4e689780 100644 --- a/tests/unit/src/com/android/tv/util/ScaledBitmapInfoTest.java +++ b/tests/unit/src/com/android/tv/util/ScaledBitmapInfoTest.java @@ -2,14 +2,15 @@ package com.android.tv.util; import android.graphics.Bitmap; import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.SmallTest; import com.android.tv.util.BitmapUtils.ScaledBitmapInfo; /** * Tests for {@link ScaledBitmapInfo}. */ +@SmallTest public class ScaledBitmapInfoTest extends AndroidTestCase { - 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); diff --git a/tests/unit/src/com/android/tv/util/TestUtils.java b/tests/unit/src/com/android/tv/util/TestUtils.java index 872e8c51..db5e93cc 100644 --- a/tests/unit/src/com/android/tv/util/TestUtils.java +++ b/tests/unit/src/com/android/tv/util/TestUtils.java @@ -19,8 +19,7 @@ package com.android.tv.util; import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; import android.media.tv.TvInputInfo; - -import com.android.tv.common.TvCommonConstants; +import android.os.Build; import java.lang.reflect.Constructor; @@ -33,7 +32,7 @@ public class TestUtils { // Create a mock TvInputInfo by using private constructor // TODO: Find better way to mock TvInputInfo. // Note that mockito doesn't support mock/spy on final object. - if (!TvCommonConstants.IS_MNC_PREVIEW && !TvCommonConstants.IS_MNC_OR_HIGHER) { + if (Build.VERSION.SDK_INT < 23) { return createTvInputInfoForLmp(service, id, parentId, type); } return createTvInputInfoForMnc(service, id, parentId, type, isHardwareInput); diff --git a/tests/unit/src/com/android/tv/util/TvInputManagerHelperTest.java b/tests/unit/src/com/android/tv/util/TvInputManagerHelperTest.java index 6251d1a3..2f06de59 100644 --- a/tests/unit/src/com/android/tv/util/TvInputManagerHelperTest.java +++ b/tests/unit/src/com/android/tv/util/TvInputManagerHelperTest.java @@ -23,12 +23,12 @@ import android.test.suitebuilder.annotation.SmallTest; import com.android.tv.testing.ComparatorTester; -import java.util.LinkedHashMap; - import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; +import java.util.LinkedHashMap; + /** * Test for {@link TvInputManagerHelper} */ 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 1cdda744..162ff63d 100644 --- a/tests/unit/src/com/android/tv/util/UtilsTest_GetDurationString.java +++ b/tests/unit/src/com/android/tv/util/UtilsTest_GetDurationString.java @@ -17,10 +17,8 @@ package com.android.tv.util; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.SmallTest; - import android.text.format.DateUtils; -import java.lang.Exception; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.Locale; |