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