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.dvr; 18 19 import android.test.suitebuilder.annotation.SmallTest; 20 21 import com.android.tv.testing.dvr.RecordingTestUtils; 22 23 import junit.framework.TestCase; 24 25 import java.util.ArrayList; 26 import java.util.List; 27 28 /** 29 * Tests for {@link DvrDataManagerImpl} 30 */ 31 @SmallTest 32 public class DvrDataManagerImplTest extends TestCase { 33 private static final int CHANNEL_ID = 273; 34 testGetNextScheduledStartTimeAfter()35 public void testGetNextScheduledStartTimeAfter() throws Exception { 36 long id = 1; 37 List<ScheduledRecording> scheduledRecordings = new ArrayList<>(); 38 assertNextStartTime(scheduledRecordings, 0L, DvrDataManager.NEXT_START_TIME_NOT_FOUND); 39 scheduledRecordings.add(RecordingTestUtils 40 .createTestRecordingWithIdAndPeriod(id++, CHANNEL_ID, 10L, 20L)); 41 assertNextStartTime(scheduledRecordings, 9L, 10L); 42 assertNextStartTime(scheduledRecordings, 10L, DvrDataManager.NEXT_START_TIME_NOT_FOUND); 43 scheduledRecordings.add(RecordingTestUtils 44 .createTestRecordingWithIdAndPeriod(id++, CHANNEL_ID, 20L, 30L)); 45 assertNextStartTime(scheduledRecordings, 9L, 10L); 46 assertNextStartTime(scheduledRecordings, 10L, 20L); 47 assertNextStartTime(scheduledRecordings, 20L, DvrDataManager.NEXT_START_TIME_NOT_FOUND); 48 scheduledRecordings.add(RecordingTestUtils 49 .createTestRecordingWithIdAndPeriod(id++, CHANNEL_ID, 30L, 40L)); 50 assertNextStartTime(scheduledRecordings, 9L, 10L); 51 assertNextStartTime(scheduledRecordings, 10L, 20L); 52 assertNextStartTime(scheduledRecordings, 20L, 30L); 53 assertNextStartTime(scheduledRecordings, 30L, DvrDataManager.NEXT_START_TIME_NOT_FOUND); 54 scheduledRecordings.clear(); 55 scheduledRecordings.add(RecordingTestUtils 56 .createTestRecordingWithIdAndPeriod(id++, CHANNEL_ID, 10L, 20L)); 57 scheduledRecordings.add(RecordingTestUtils 58 .createTestRecordingWithIdAndPeriod(id++, CHANNEL_ID, 10L, 20L)); 59 scheduledRecordings.add(RecordingTestUtils 60 .createTestRecordingWithIdAndPeriod(id++, CHANNEL_ID, 10L, 20L)); 61 assertNextStartTime(scheduledRecordings, 9L, 10L); 62 assertNextStartTime(scheduledRecordings, 10L, DvrDataManager.NEXT_START_TIME_NOT_FOUND); 63 } 64 assertNextStartTime(List<ScheduledRecording> scheduledRecordings, long startTime, long expected)65 private void assertNextStartTime(List<ScheduledRecording> scheduledRecordings, long startTime, long expected) { 66 assertEquals("getNextScheduledStartTimeAfter()", expected, 67 DvrDataManagerImpl.getNextStartTimeAfter(scheduledRecordings, startTime)); 68 } 69 }