1 /* 2 * Copyright (C) 2016 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.support.annotation.NonNull; 20 import android.support.test.filters.SmallTest; 21 import android.test.AndroidTestCase; 22 import android.test.MoreAsserts; 23 24 import com.android.tv.testing.FakeClock; 25 import com.android.tv.testing.dvr.RecordingTestUtils; 26 27 import java.util.List; 28 import java.util.concurrent.TimeUnit; 29 30 /** 31 * Tests for {@link BaseDvrDataManager} using {@link DvrDataManagerInMemoryImpl}. 32 */ 33 @SmallTest 34 public class BaseDvrDataManagerTest extends AndroidTestCase { 35 private static final int CHANNEL_ID = 273; 36 37 private DvrDataManagerInMemoryImpl mDvrDataManager; 38 private FakeClock mFakeClock; 39 40 @Override setUp()41 protected void setUp() throws Exception { 42 super.setUp(); 43 mFakeClock = FakeClock.createWithCurrentTime(); 44 mDvrDataManager = new DvrDataManagerInMemoryImpl(getContext(), mFakeClock); 45 } 46 testGetNonStartedScheduledRecordings()47 public void testGetNonStartedScheduledRecordings() { 48 ScheduledRecording recording = mDvrDataManager 49 .addScheduledRecordingInternal(createNewScheduledRecordingStartingNow()); 50 List<ScheduledRecording> result = mDvrDataManager.getNonStartedScheduledRecordings(); 51 MoreAsserts.assertContentsInAnyOrder(result, recording); 52 } 53 testGetNonStartedScheduledRecordings_past()54 public void testGetNonStartedScheduledRecordings_past() { 55 mDvrDataManager.addScheduledRecordingInternal(createNewScheduledRecordingStartingNow()); 56 mFakeClock.increment(TimeUnit.MINUTES, 6); 57 List<ScheduledRecording> result = mDvrDataManager.getNonStartedScheduledRecordings(); 58 MoreAsserts.assertContentsInAnyOrder(result); 59 } 60 61 @NonNull createNewScheduledRecordingStartingNow()62 private ScheduledRecording createNewScheduledRecordingStartingNow() { 63 return ScheduledRecording.buildFrom(RecordingTestUtils 64 .createTestRecordingWithIdAndPeriod( 65 -1, 66 CHANNEL_ID, 67 mFakeClock.currentTimeMillis(), 68 mFakeClock.currentTimeMillis() + TimeUnit.MINUTES.toMillis(5))) 69 .setState(ScheduledRecording.STATE_RECORDING_NOT_STARTED) 70 .build(); 71 } 72 } 73