TvInputManagerHelperTest.java revision 07b043dc3db83d6d20f0e8513b946830ab00e37b
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.util; 18 19import android.content.pm.ResolveInfo; 20import android.media.tv.TvInputInfo; 21import android.test.AndroidTestCase; 22import android.test.suitebuilder.annotation.SmallTest; 23 24import com.android.tv.testing.ComparatorTester; 25 26import org.mockito.Mockito; 27import org.mockito.invocation.InvocationOnMock; 28import org.mockito.stubbing.Answer; 29 30import java.util.LinkedHashMap; 31 32/** 33 * Test for {@link TvInputManagerHelper} 34 */ 35@SmallTest 36public class TvInputManagerHelperTest extends AndroidTestCase { 37 public void testComparator() throws Exception { 38 final LinkedHashMap<String, Boolean> INPUT_ID_TO_PARTNER_INPUT = new LinkedHashMap<>(); 39 INPUT_ID_TO_PARTNER_INPUT.put("2_partner_input", true); 40 INPUT_ID_TO_PARTNER_INPUT.put("3_partner_input", true); 41 INPUT_ID_TO_PARTNER_INPUT.put("1_3rd_party_input", false); 42 INPUT_ID_TO_PARTNER_INPUT.put("4_3rd_party_input", false); 43 44 TvInputManagerHelper manager = Mockito.mock(TvInputManagerHelper.class); 45 Mockito.doAnswer(new Answer<Boolean>() { 46 @Override 47 public Boolean answer(InvocationOnMock invocation) throws Throwable { 48 TvInputInfo info = (TvInputInfo) invocation.getArguments()[0]; 49 return INPUT_ID_TO_PARTNER_INPUT.get(info.getId()); 50 } 51 }).when(manager).isPartnerInput(Mockito.<TvInputInfo>any()); 52 Mockito.doAnswer(new Answer<String>() { 53 @Override 54 public String answer(InvocationOnMock invocation) throws Throwable { 55 TvInputInfo info = (TvInputInfo) invocation.getArguments()[0]; 56 return info.getId(); 57 } 58 }).when(manager).loadLabel(Mockito.<TvInputInfo>any()); 59 60 ComparatorTester<TvInputInfo> comparatorTester = 61 ComparatorTester.withoutEqualsTest( 62 new TvInputManagerHelper.TvInputInfoComparator(manager)); 63 ResolveInfo resolveInfo1 = TestUtils.createResolveInfo("1_test", "1_test"); 64 ResolveInfo resolveInfo2 = TestUtils.createResolveInfo("2_test", "2_test"); 65 for (String inputId : INPUT_ID_TO_PARTNER_INPUT.keySet()) { 66 TvInputInfo info1 = TestUtils.createTvInputInfo(resolveInfo1, inputId, null, 0, false); 67 TvInputInfo info2 = TestUtils.createTvInputInfo(resolveInfo2, inputId, null, 0, false); 68 comparatorTester.addComparableGroup(info1, info2); 69 } 70 comparatorTester.test(); 71 } 72} 73