• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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.intentresolver
18 
19 import android.content.Context
20 import android.content.Intent
21 import android.content.IntentSender
22 import androidx.test.ext.junit.runners.AndroidJUnit4
23 import com.android.intentresolver.chooser.TargetInfo
24 import org.junit.Test
25 import org.junit.runner.RunWith
26 import org.mockito.ArgumentCaptor
27 import org.mockito.Mockito
28 import java.util.function.Consumer
29 import org.junit.Assert.assertEquals
30 
31 @RunWith(AndroidJUnit4::class)
32 class ChooserRefinementManagerTest {
33     @Test
testMaybeHandleSelectionnull34     fun testMaybeHandleSelection() {
35         val intentSender = mock<IntentSender>()
36         val refinementManager = ChooserRefinementManager(
37             mock<Context>(),
38             intentSender,
39             Consumer<TargetInfo>{},
40             Runnable{})
41 
42         val intents = listOf(Intent(Intent.ACTION_VIEW), Intent(Intent.ACTION_EDIT))
43         val targetInfo = mock<TargetInfo>{
44             whenever(allSourceIntents).thenReturn(intents)
45         }
46 
47         refinementManager.maybeHandleSelection(targetInfo)
48 
49         val intentCaptor = ArgumentCaptor.forClass(Intent::class.java)
50         Mockito.verify(intentSender).sendIntent(
51             any(), eq(0), intentCaptor.capture(), eq(null), eq(null))
52 
53         val intent = intentCaptor.value
54         assertEquals(intents[0], intent.getParcelableExtra(Intent.EXTRA_INTENT, Intent::class.java))
55 
56         val alternates =
57             intent.getParcelableArrayExtra(Intent.EXTRA_ALTERNATE_INTENTS, Intent::class.java)
58         assertEquals(1, alternates?.size)
59         assertEquals(intents[1], alternates?.get(0))
60     }
61 }
62