diff options
author | Nick Chalko <nchalko@google.com> | 2017-05-04 14:37:34 -0700 |
---|---|---|
committer | Nick Chalko <nchalko@google.com> | 2017-05-05 06:18:44 -0700 |
commit | 3dfa929b24f38ac7836450176d88ceab41dc6ac5 (patch) | |
tree | 675a324760c582713e2e0080775ea17357f75b65 /tests/unit/src/com/android/tv/dvr/recorder/SchedulerTest.java | |
parent | fddf3fd148c1fc94c48ee5684e47dbb56512e758 (diff) | |
download | TV-3dfa929b24f38ac7836450176d88ceab41dc6ac5.tar.gz |
Sync to ub-tv-dev at f0024d79653da8c8999a91f995431a645a6ff4a2
Change-Id: I4199ec04cacb4a78be58b85302a39d917658dc28
Diffstat (limited to 'tests/unit/src/com/android/tv/dvr/recorder/SchedulerTest.java')
-rw-r--r-- | tests/unit/src/com/android/tv/dvr/recorder/SchedulerTest.java | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/tests/unit/src/com/android/tv/dvr/recorder/SchedulerTest.java b/tests/unit/src/com/android/tv/dvr/recorder/SchedulerTest.java new file mode 100644 index 00000000..94cfaac1 --- /dev/null +++ b/tests/unit/src/com/android/tv/dvr/recorder/SchedulerTest.java @@ -0,0 +1,110 @@ +/* + * 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.recorder; + +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.os.Build; +import android.os.Looper; +import android.support.test.filters.SdkSuppress; +import android.support.test.filters.SmallTest; +import android.test.AndroidTestCase; + +import com.android.tv.InputSessionManager; +import com.android.tv.data.ChannelDataManager; +import com.android.tv.dvr.DvrDataManagerInMemoryImpl; +import com.android.tv.dvr.DvrManager; +import com.android.tv.dvr.data.ScheduledRecording; +import com.android.tv.testing.FakeClock; +import com.android.tv.testing.dvr.RecordingTestUtils; +import com.android.tv.util.TvInputManagerHelper; + +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; + +import java.util.concurrent.TimeUnit; + +/** + * Tests for {@link Scheduler}. + */ +@SmallTest +@SdkSuppress(minSdkVersion = Build.VERSION_CODES.N) +public class SchedulerTest extends AndroidTestCase { + private static final String INPUT_ID = "input_id"; + private static final int CHANNEL_ID = 273; + + private FakeClock mFakeClock; + private DvrDataManagerInMemoryImpl mDataManager; + private Scheduler mScheduler; + @Mock DvrManager mDvrManager; + @Mock InputSessionManager mSessionManager; + @Mock AlarmManager mMockAlarmManager; + @Mock ChannelDataManager mChannelDataManager; + @Mock TvInputManagerHelper mInputManager; + + @Override + protected void setUp() throws Exception { + super.setUp(); + MockitoAnnotations.initMocks(this); + mFakeClock = FakeClock.createWithCurrentTime(); + mDataManager = new DvrDataManagerInMemoryImpl(getContext(), mFakeClock); + Mockito.when(mChannelDataManager.isDbLoadFinished()).thenReturn(true); + mScheduler = new Scheduler(Looper.myLooper(), mDvrManager, mSessionManager, mDataManager, + mChannelDataManager, mInputManager, getContext(), mFakeClock, mMockAlarmManager); + } + + public void testUpdate_none() throws Exception { + mScheduler.start(); + mScheduler.update(); + verifyZeroInteractions(mMockAlarmManager); + } + + public void testUpdate_nextIn12Hours() throws Exception { + long now = mFakeClock.currentTimeMillis(); + long startTime = now + TimeUnit.HOURS.toMillis(12); + ScheduledRecording r = RecordingTestUtils + .createTestRecordingWithPeriod(INPUT_ID, CHANNEL_ID, startTime, + startTime + TimeUnit.HOURS.toMillis(1)); + mDataManager.addScheduledRecording(r); + mScheduler.start(); + verify(mMockAlarmManager).setExactAndAllowWhileIdle( + eq(AlarmManager.RTC_WAKEUP), + eq(startTime - Scheduler.MS_TO_WAKE_BEFORE_START), + any(PendingIntent.class)); + Mockito.reset(mMockAlarmManager); + mScheduler.update(); + verify(mMockAlarmManager).setExactAndAllowWhileIdle( + eq(AlarmManager.RTC_WAKEUP), + eq(startTime - Scheduler.MS_TO_WAKE_BEFORE_START), + any(PendingIntent.class)); + } + + public void testStartsWithin() throws Exception { + long now = mFakeClock.currentTimeMillis(); + long startTime = now + 3; + ScheduledRecording r = RecordingTestUtils + .createTestRecordingWithPeriod(INPUT_ID, CHANNEL_ID, startTime, startTime + 100); + assertFalse(mScheduler.startsWithin(r, 2)); + assertTrue(mScheduler.startsWithin(r, 3)); + } +}
\ No newline at end of file |