1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License
15  */
16 
17 package com.android.tv.testing.dvr;
18 
19 import com.android.tv.dvr.DvrDataManagerInMemoryImpl;
20 import com.android.tv.dvr.ScheduledRecording;
21 
22 import junit.framework.Assert;
23 
24 /**
25  * Static utils for using {@link ScheduledRecording} in tests.
26  */
27 public final class RecordingTestUtils {
createTestRecordingWithIdAndPeriod(long id, long channelId, long startTime, long endTime)28     public static ScheduledRecording createTestRecordingWithIdAndPeriod(long id, long channelId,
29             long startTime, long endTime) {
30         return ScheduledRecording.builder(startTime, endTime)
31                 .setId(id)
32                 .setChannelId(channelId)
33                 .build();
34     }
35 
createTestRecordingWithPeriod(long channelId, long startTime, long endTime)36     public static ScheduledRecording createTestRecordingWithPeriod(long channelId, long startTime,
37             long endTime) {
38         return createTestRecordingWithIdAndPeriod(ScheduledRecording.ID_NOT_SET, channelId,
39                 startTime, endTime);
40     }
41 
addScheduledRecording( DvrDataManagerInMemoryImpl dvrDataManager, long channelId, long startTime, long endTime)42     public static ScheduledRecording addScheduledRecording(
43             DvrDataManagerInMemoryImpl dvrDataManager, long channelId, long startTime,
44             long endTime) {
45         ScheduledRecording recording = createTestRecordingWithPeriod(channelId, startTime, endTime);
46         recording = dvrDataManager.addScheduledRecordingInternal(recording);
47         return recording;
48     }
49 
normalizePriority(ScheduledRecording orig)50     public static ScheduledRecording normalizePriority(ScheduledRecording orig){
51         return ScheduledRecording.buildFrom(orig).setPriority(orig.getId()).build();
52     }
53 
assertRecordingEquals(ScheduledRecording expected, ScheduledRecording actual)54     public static void assertRecordingEquals(ScheduledRecording expected, ScheduledRecording actual) {
55         Assert.assertEquals("id", expected.getId(), actual.getId());
56         Assert.assertEquals("channel", expected.getChannelId(), actual.getChannelId());
57         Assert.assertEquals("programId", expected.getProgramId(), actual.getProgramId());
58         Assert.assertEquals("priority", expected.getPriority(), actual.getPriority());
59         Assert.assertEquals("start time", expected.getStartTimeMs(), actual.getStartTimeMs());
60         Assert.assertEquals("end time", expected.getEndTimeMs(), actual.getEndTimeMs());
61         Assert.assertEquals("state", expected.getState(), actual.getState());
62         Assert.assertEquals("parent season recording", expected.getParentSeasonRecording(),
63                 actual.getParentSeasonRecording());
64     }
65 
RecordingTestUtils()66     private RecordingTestUtils() { }
67 }
68