From 1abddd9f6225298066094e20a6c29061b6af4590 Mon Sep 17 00:00:00 2001 From: Nick Chalko Date: Wed, 9 Dec 2015 13:48:17 -0800 Subject: Sync to ub-tv-heroes at 1.08.301 source change id If9b64d7bbc6e8f77b360e502d34e5452775c0402 Change-Id: I4ffe87911cb85e54880d1d918d1b8fb7bb8cfb7d --- .../android/tv/data/ProgramDataManagerTest.java | 4 +- .../android/tv/data/TvInputNewComparatorTest.java | 85 ++++++++++++++++ .../com/android/tv/dvr/DvrDataManagerImplTest.java | 61 +++++++++++ .../android/tv/dvr/DvrRecordingServiceTest.java | 73 ++++++++++++++ .../src/com/android/tv/dvr/RecordingTaskTest.java | 112 +++++++++++++++++++++ .../unit/src/com/android/tv/dvr/RecordingTest.java | 50 +++++++++ .../unit/src/com/android/tv/dvr/SchedulerTest.java | 85 ++++++++++++++++ .../unit/src/com/android/tv/ui/SetupViewTest.java | 86 ---------------- tests/unit/src/com/android/tv/util/FakeClock.java | 34 ------- .../tv/util/UtilsTest_GetMultiAudioString.java | 4 +- 10 files changed, 470 insertions(+), 124 deletions(-) create mode 100644 tests/unit/src/com/android/tv/data/TvInputNewComparatorTest.java create mode 100644 tests/unit/src/com/android/tv/dvr/DvrDataManagerImplTest.java create mode 100644 tests/unit/src/com/android/tv/dvr/DvrRecordingServiceTest.java create mode 100644 tests/unit/src/com/android/tv/dvr/RecordingTaskTest.java create mode 100644 tests/unit/src/com/android/tv/dvr/RecordingTest.java create mode 100644 tests/unit/src/com/android/tv/dvr/SchedulerTest.java delete mode 100644 tests/unit/src/com/android/tv/ui/SetupViewTest.java delete mode 100644 tests/unit/src/com/android/tv/util/FakeClock.java (limited to 'tests/unit/src/com') diff --git a/tests/unit/src/com/android/tv/data/ProgramDataManagerTest.java b/tests/unit/src/com/android/tv/data/ProgramDataManagerTest.java index 78b3a930..96ecefdf 100644 --- a/tests/unit/src/com/android/tv/data/ProgramDataManagerTest.java +++ b/tests/unit/src/com/android/tv/data/ProgramDataManagerTest.java @@ -32,7 +32,7 @@ import android.util.SparseArray; import com.android.tv.testing.Constants; import com.android.tv.testing.ProgramInfo; -import com.android.tv.util.FakeClock; +import com.android.tv.testing.FakeClock; import com.android.tv.util.Utils; import java.util.ArrayList; @@ -70,7 +70,7 @@ public class ProgramDataManagerTest extends AndroidTestCase { protected void setUp() throws Exception { super.setUp(); - mClock = new FakeClock(); + mClock = FakeClock.createWithCurrentTime(); mListener = new TestProgramDataManagerListener(); mContentProvider = new FakeContentProvider(getContext()); mContentResolver = new FakeContentResolver(); diff --git a/tests/unit/src/com/android/tv/data/TvInputNewComparatorTest.java b/tests/unit/src/com/android/tv/data/TvInputNewComparatorTest.java new file mode 100644 index 00000000..bc239a8a --- /dev/null +++ b/tests/unit/src/com/android/tv/data/TvInputNewComparatorTest.java @@ -0,0 +1,85 @@ +/* + * 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.data; + +import android.content.pm.ResolveInfo; +import android.media.tv.TvInputInfo; +import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.SmallTest; + +import com.android.tv.testing.ComparatorTester; +import com.android.tv.util.SetupUtils; +import com.android.tv.util.TestUtils; +import com.android.tv.util.TvInputManagerHelper; + +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 TvInputNewComparator} + */ +@SmallTest +public class TvInputNewComparatorTest extends AndroidTestCase { + public void testComparator() throws Exception { + final LinkedHashMap INPUT_ID_TO_NEW_INPUT = new LinkedHashMap<>(); + INPUT_ID_TO_NEW_INPUT.put("2_new_input", true); + INPUT_ID_TO_NEW_INPUT.put("4_new_input", true); + INPUT_ID_TO_NEW_INPUT.put("0_old_input", false); + INPUT_ID_TO_NEW_INPUT.put("1_old_input", false); + INPUT_ID_TO_NEW_INPUT.put("3_old_input", false); + + SetupUtils setupUtils = Mockito.mock(SetupUtils.class); + Mockito.when(setupUtils.isNewInput(Matchers.anyString())).thenAnswer( + new Answer() { + @Override + public Boolean answer(InvocationOnMock invocation) throws Throwable { + String inputId = (String) invocation.getArguments()[0]; + return INPUT_ID_TO_NEW_INPUT.get(inputId); + } + } + ); + TvInputManagerHelper inputManager = Mockito.mock(TvInputManagerHelper.class); + Mockito.when(inputManager.getDefaultTvInputInfoComparator()).thenReturn( + new Comparator() { + @Override + public int compare(TvInputInfo lhs, TvInputInfo rhs) { + return lhs.getId().compareTo(rhs.getId()); + } + } + ); + TvInputNewComparator comparator = new TvInputNewComparator(setupUtils, inputManager); + ComparatorTester comparatorTester = + ComparatorTester.withoutEqualsTest(comparator); + ResolveInfo resolveInfo = TestUtils.createResolveInfo("test", "test"); + for (String id : INPUT_ID_TO_NEW_INPUT.keySet()) { + // Put mock resolveInfo to prevent NPE in {@link TvInputInfo#toString} + TvInputInfo info1 = TestUtils.createTvInputInfo( + resolveInfo, id, "test1", TvInputInfo.TYPE_TUNER, false); + TvInputInfo info2 = TestUtils.createTvInputInfo( + resolveInfo, id, "test2", TvInputInfo.TYPE_DISPLAY_PORT, true); + TvInputInfo info3 = TestUtils.createTvInputInfo( + resolveInfo, id, "test", TvInputInfo.TYPE_HDMI, true); + comparatorTester.addComparableGroup(info1, info2, info3); + } + comparatorTester.test(); + } +} diff --git a/tests/unit/src/com/android/tv/dvr/DvrDataManagerImplTest.java b/tests/unit/src/com/android/tv/dvr/DvrDataManagerImplTest.java new file mode 100644 index 00000000..06cf7315 --- /dev/null +++ b/tests/unit/src/com/android/tv/dvr/DvrDataManagerImplTest.java @@ -0,0 +1,61 @@ +/* + * 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.dvr; + +import android.test.suitebuilder.annotation.SmallTest; + +import com.android.tv.testing.dvr.RecordingTestUtils; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.List; + +/** + * Tests for {@link DvrDataManagerImplTest} + */ +@SmallTest +public class DvrDataManagerImplTest extends TestCase { + public void testGetNextScheduledStartTimeAfter() throws Exception { + long id = 1; + List recordings = new ArrayList<>(); + assertNextStartTime(recordings, 0L, DvrDataManager.NEXT_START_TIME_NOT_FOUND); + recordings.add(RecordingTestUtils.createTestRecordingWithPeriod(id++, 10L, 20L)); + assertNextStartTime(recordings, 9L, 10L); + assertNextStartTime(recordings, 10L, DvrDataManager.NEXT_START_TIME_NOT_FOUND); + recordings.add(RecordingTestUtils.createTestRecordingWithPeriod(id++, 20L, 30L)); + assertNextStartTime(recordings, 9L, 10L); + assertNextStartTime(recordings, 10L, 20L); + assertNextStartTime(recordings, 20L, DvrDataManager.NEXT_START_TIME_NOT_FOUND); + recordings.add(RecordingTestUtils.createTestRecordingWithPeriod(id++, 30L, 40L)); + assertNextStartTime(recordings, 9L, 10L); + assertNextStartTime(recordings, 10L, 20L); + assertNextStartTime(recordings, 20L, 30L); + assertNextStartTime(recordings, 30L, DvrDataManager.NEXT_START_TIME_NOT_FOUND); + recordings.clear(); + recordings.add(RecordingTestUtils.createTestRecordingWithPeriod(id++, 10L, 20L)); + recordings.add(RecordingTestUtils.createTestRecordingWithPeriod(id++, 10L, 20L)); + recordings.add(RecordingTestUtils.createTestRecordingWithPeriod(id++, 10L, 20L)); + assertNextStartTime(recordings, 9L, 10L); + assertNextStartTime(recordings, 10L, DvrDataManager.NEXT_START_TIME_NOT_FOUND); + } + + private void assertNextStartTime(List recordings, long startTime, long expected) { + assertEquals("getNextScheduledStartTimeAfter()", expected, + DvrDataManagerImpl.getNextStartTimeAfter(recordings, startTime)); + } +} \ No newline at end of file diff --git a/tests/unit/src/com/android/tv/dvr/DvrRecordingServiceTest.java b/tests/unit/src/com/android/tv/dvr/DvrRecordingServiceTest.java new file mode 100644 index 00000000..85c2f661 --- /dev/null +++ b/tests/unit/src/com/android/tv/dvr/DvrRecordingServiceTest.java @@ -0,0 +1,73 @@ +/* + * 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.dvr; + +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import android.test.ServiceTestCase; +import android.test.suitebuilder.annotation.SmallTest; + +import com.android.tv.ApplicationSingletons; +import com.android.tv.Features; +import com.android.tv.MockTvApplication; +import com.android.tv.common.feature.TestableFeature; + +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; + +/** + * Tests for {@link DvrRecordingService}. + */ +@SmallTest +public class DvrRecordingServiceTest extends ServiceTestCase { + + @Mock Scheduler mMockScheduler; + @Mock ApplicationSingletons mApplicationSingletons; + private final TestableFeature mDvrFeature = Features.DVR; + private DvrDataManagerInMemoryImpl mDataManager; + private DvrRecordingService mService; + + @Override + protected void setUp() throws Exception { + super.setUp(); + mDvrFeature.enableForTest(); + MockitoAnnotations.initMocks(this); + mDataManager = new DvrDataManagerInMemoryImpl(getContext()); + setApplication(new MockTvApplication(mApplicationSingletons)); + when(mApplicationSingletons.getDvrDataManager()).thenReturn(mDataManager); + setupService(); + mService = getService(); + mService.setScheduler(mMockScheduler); + } + + @Override + protected void tearDown() throws Exception { + mDvrFeature.resetForTests(); + super.tearDown(); + } + + public DvrRecordingServiceTest() { + super(DvrRecordingService.class); + } + + public void testStartService_null() throws Exception { + startService(null); + verify(mMockScheduler, Mockito.only()).update(); + } +} \ No newline at end of file diff --git a/tests/unit/src/com/android/tv/dvr/RecordingTaskTest.java b/tests/unit/src/com/android/tv/dvr/RecordingTaskTest.java new file mode 100644 index 00000000..063cd61f --- /dev/null +++ b/tests/unit/src/com/android/tv/dvr/RecordingTaskTest.java @@ -0,0 +1,112 @@ +/* + * 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.dvr; + +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + +import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.SmallTest; + +import com.android.tv.common.dvr.DvrSessionClient; +import com.android.tv.data.Channel; +import com.android.tv.testing.FakeClock; +import com.android.tv.testing.dvr.RecordingTestUtils; + +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +/** + * Tests for {@link RecordingTask}. + */ +@SmallTest +public class RecordingTaskTest extends AndroidTestCase { + private FakeClock mFakeClock; + private DvrDataManagerInMemoryImpl mDataManager; + @Mock + DvrSessionManager mMockSessionManager; + @Mock + DvrSessionClient mMockDvrSessionClient; + + @Override + protected void setUp() throws Exception { + super.setUp(); + MockitoAnnotations.initMocks(this); + mFakeClock = FakeClock.createWithTimeOne(); + mDataManager = new DvrDataManagerInMemoryImpl(getContext()); + } + + public void testRun_sleepUntil() { + long startTime = mFakeClock.currentTimeMillis(); + long endTime = startTime + 1; + Recording r = RecordingTestUtils.createTestRecordingWithPeriod(1, startTime, endTime); + RecordingTask task = new RecordingTask(r, mMockSessionManager, mDataManager, + mFakeClock); + + Channel channel = r.getChannel(); + String inputId = channel.getInputId(); + when(mMockSessionManager.canAcquireDvrSession(inputId, channel)) + .thenReturn(true); + when(mMockSessionManager.acquireDvrSession(inputId, channel)) + .thenReturn(mMockDvrSessionClient); + task.run(); + assertEquals("Recording " + r + "finish time", endTime + RecordingTask.MS_AFTER_END, + mFakeClock.currentTimeMillis()); + } + + public void testRun_connectAndRelease() { + long startTime = mFakeClock.currentTimeMillis(); + long endTime = startTime + 1; + Recording r = RecordingTestUtils.createTestRecordingWithPeriod(1, startTime, endTime); + RecordingTask task = new RecordingTask(r, mMockSessionManager, mDataManager, + mFakeClock); + + Channel channel = r.getChannel(); + String inputId = channel.getInputId(); + when(mMockSessionManager.canAcquireDvrSession(inputId, channel)) + .thenReturn(true); + when(mMockSessionManager.acquireDvrSession(inputId, channel)) + .thenReturn(mMockDvrSessionClient); + task.run(); + + verify(mMockSessionManager).canAcquireDvrSession(inputId, channel); + verify(mMockSessionManager).acquireDvrSession(inputId, channel); + verify(mMockDvrSessionClient).connect(inputId, task); + verify(mMockDvrSessionClient).startRecord(channel.getUri(), + RecordingTask.getIdAsMediaUri(r)); + verify(mMockDvrSessionClient).stopRecord(); + verify(mMockSessionManager).releaseDvrSession(mMockDvrSessionClient); + verifyNoMoreInteractions(mMockDvrSessionClient, mMockSessionManager); + } + + + public void testRun_cannotAcquireSession() { + long startTime = mFakeClock.currentTimeMillis(); + long endTime = startTime + 1; + Recording r = RecordingTestUtils.createTestRecordingWithPeriod(1, startTime, endTime); + mDataManager.addRecording(r); + RecordingTask task = new RecordingTask(r, mMockSessionManager, mDataManager, + mFakeClock); + + when(mMockSessionManager.canAcquireDvrSession(r.getChannel().getInputId(), r.getChannel())) + .thenReturn(false); + task.run(); + Recording updatedRecording = mDataManager.getRecording(r.getId()); + assertEquals("status",Recording.STATE_RECORDING_FAILED, updatedRecording.getState() ); + } +} \ No newline at end of file diff --git a/tests/unit/src/com/android/tv/dvr/RecordingTest.java b/tests/unit/src/com/android/tv/dvr/RecordingTest.java new file mode 100644 index 00000000..ef012248 --- /dev/null +++ b/tests/unit/src/com/android/tv/dvr/RecordingTest.java @@ -0,0 +1,50 @@ +/* + * 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.dvr; + +import android.test.suitebuilder.annotation.SmallTest; +import android.util.Range; + +import com.android.tv.testing.dvr.RecordingTestUtils; + +import junit.framework.TestCase; + +/** + * Tests for {@link RecordingTest} + */ +@SmallTest +public class RecordingTest extends TestCase { + public void testIsOverLapping() throws Exception { + Recording r = RecordingTestUtils.createTestRecordingWithPeriod(1, 10L, 20L); + assertOverLapping(false, 1L, 9L, r); + + assertOverLapping(true, 1L, 20L, r); + assertOverLapping(true, 1L, 10L, r); + assertOverLapping(true, 10L, 19L, r); + assertOverLapping(true, 10L, 20L, r); + assertOverLapping(true, 11L, 20L, r); + assertOverLapping(true, 11L, 21L, r); + assertOverLapping(true, 20L, 21L, r); + + assertOverLapping(false, 21L, 29L, r); + } + + private void assertOverLapping(boolean expected, long lower, long upper, Recording r) { + assertEquals("isOverlapping(Range(" + lower + "," + upper + "), recording " + r, expected, + r.isOverLapping(new Range(lower, upper))); + } +} diff --git a/tests/unit/src/com/android/tv/dvr/SchedulerTest.java b/tests/unit/src/com/android/tv/dvr/SchedulerTest.java new file mode 100644 index 00000000..281b055a --- /dev/null +++ b/tests/unit/src/com/android/tv/dvr/SchedulerTest.java @@ -0,0 +1,85 @@ +/* + * 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.dvr; + + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyZeroInteractions; + +import android.app.AlarmManager; +import android.app.PendingIntent; +import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.SmallTest; + +import com.android.tv.testing.FakeClock; +import com.android.tv.testing.dvr.RecordingTestUtils; + +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import java.util.concurrent.TimeUnit; + +/** + * Tests for {@link Scheduler}. + */ +@SmallTest +public class SchedulerTest extends AndroidTestCase { + private FakeClock mClock; + private DvrDataManagerInMemoryImpl mDataManager; + private Scheduler mScheduler; + @Mock DvrSessionManager mSessionManager; + @Mock AlarmManager mMockAlarmManager; + + @Override + protected void setUp() throws Exception { + super.setUp(); + MockitoAnnotations.initMocks(this); + mClock = FakeClock.createWithCurrentTime(); + mDataManager = new DvrDataManagerInMemoryImpl(getContext()); + mScheduler = new Scheduler(mSessionManager, mDataManager, getContext(), mClock, + mMockAlarmManager); + } + + public void testUpdate_none() throws Exception { + mScheduler.update(); + verifyZeroInteractions(mMockAlarmManager); + } + + public void testUpdate_nextIn12Hours() throws Exception { + long now = mClock.currentTimeMillis(); + long startTime = now + TimeUnit.HOURS.toMillis(12); + Recording r = RecordingTestUtils.createTestRecordingWithPeriod(1, startTime, + startTime + TimeUnit.HOURS.toMillis(1)); + mDataManager.addRecording(r); + mScheduler.update(); + verify(mMockAlarmManager).set( + eq(AlarmManager.RTC_WAKEUP), + eq(startTime - Scheduler.MS_TO_WAKE_BEFORE_START), + any(PendingIntent.class)); + } + + public void testStartsWithin() throws Exception { + long now = mClock.currentTimeMillis(); + long startTime = now + 3; + Recording r = RecordingTestUtils + .createTestRecordingWithPeriod(1, startTime, startTime + 100); + assertFalse(mScheduler.startsWithin(r, 2)); + assertTrue(mScheduler.startsWithin(r, 3)); + } +} \ No newline at end of file diff --git a/tests/unit/src/com/android/tv/ui/SetupViewTest.java b/tests/unit/src/com/android/tv/ui/SetupViewTest.java deleted file mode 100644 index d3579d13..00000000 --- a/tests/unit/src/com/android/tv/ui/SetupViewTest.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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.ui; - -import android.content.pm.ResolveInfo; -import android.media.tv.TvInputInfo; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.SmallTest; - -import com.android.tv.testing.ComparatorTester; -import com.android.tv.util.SetupUtils; -import com.android.tv.util.TestUtils; -import com.android.tv.util.TvInputManagerHelper; - -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} - */ -@SmallTest -public class SetupViewTest extends AndroidTestCase { - public void testComparator() throws Exception { - final LinkedHashMap INPUT_ID_TO_NEW_INPUT = new LinkedHashMap<>(); - INPUT_ID_TO_NEW_INPUT.put("2_new_input", true); - INPUT_ID_TO_NEW_INPUT.put("4_new_input", true); - INPUT_ID_TO_NEW_INPUT.put("0_old_input", false); - INPUT_ID_TO_NEW_INPUT.put("1_old_input", false); - INPUT_ID_TO_NEW_INPUT.put("3_old_input", false); - - SetupUtils setupUtils = Mockito.mock(SetupUtils.class); - Mockito.when(setupUtils.isNewInput(Matchers.anyString())).thenAnswer( - new Answer() { - @Override - public Boolean answer(InvocationOnMock invocation) throws Throwable { - String inputId = (String) invocation.getArguments()[0]; - return INPUT_ID_TO_NEW_INPUT.get(inputId); - } - } - ); - TvInputManagerHelper inputManager = Mockito.mock(TvInputManagerHelper.class); - Mockito.when(inputManager.getDefaultTvInputInfoComparator()).thenReturn( - new Comparator() { - @Override - public int compare(TvInputInfo lhs, TvInputInfo rhs) { - return lhs.getId().compareTo(rhs.getId()); - } - } - ); - SetupView.TvInputInfoComparator comparator = - new SetupView.TvInputInfoComparator(setupUtils, inputManager); - ComparatorTester comparatorTester = - ComparatorTester.withoutEqualsTest(comparator); - ResolveInfo resolveInfo = TestUtils.createResolveInfo("test", "test"); - for (String id : INPUT_ID_TO_NEW_INPUT.keySet()) { - // Put mock resolveInfo to prevent NPE in {@link TvInputInfo#toString} - TvInputInfo info1 = TestUtils.createTvInputInfo( - resolveInfo, id, "test1", TvInputInfo.TYPE_TUNER, false); - TvInputInfo info2 = TestUtils.createTvInputInfo( - resolveInfo, id, "test2", TvInputInfo.TYPE_DISPLAY_PORT, true); - TvInputInfo info3 = TestUtils.createTvInputInfo( - resolveInfo, id, "test", TvInputInfo.TYPE_HDMI, true); - comparatorTester.addComparableGroup(info1, info2, info3); - } - comparatorTester.test(); - } -} diff --git a/tests/unit/src/com/android/tv/util/FakeClock.java b/tests/unit/src/com/android/tv/util/FakeClock.java deleted file mode 100644 index a4ab2e4f..00000000 --- a/tests/unit/src/com/android/tv/util/FakeClock.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.util; - -public class FakeClock implements Clock { - private long mCurrentTimeMillis; - - public FakeClock() { - mCurrentTimeMillis = System.currentTimeMillis(); - } - - public void setCurrentTimeMillis(long time) { - mCurrentTimeMillis = time; - } - - @Override - public long currentTimeMillis() { - return mCurrentTimeMillis; - } -} 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 601ed661..afcb812a 100644 --- a/tests/unit/src/com/android/tv/util/UtilsTest_GetMultiAudioString.java +++ b/tests/unit/src/com/android/tv/util/UtilsTest_GetMultiAudioString.java @@ -37,8 +37,8 @@ public class UtilsTest_GetMultiAudioString extends AndroidTestCase { Utils.getMultiAudioString(context, createAudioTrackInfo("eng"), false)); assertEquals("Unknown language", Utils.getMultiAudioString(context, createAudioTrackInfo(null), false)); - // TODO: Check whether the following tests are expected. - assertEquals("", Utils.getMultiAudioString(context, createAudioTrackInfo(""), false)); + assertEquals("Unknown language", + Utils.getMultiAudioString(context, createAudioTrackInfo(""), false)); assertEquals("abc", Utils.getMultiAudioString(context, createAudioTrackInfo("abc"), false)); } -- cgit v1.2.3