1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
/*
* 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.os.Looper;
import android.support.test.filters.SdkSuppress;
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
@SdkSuppress(minSdkVersion = 23)
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(Looper.myLooper(), 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(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(startTime, startTime + 100);
assertFalse(mScheduler.startsWithin(r, 2));
assertTrue(mScheduler.startsWithin(r, 3));
}
}
|