1 /*
2  * Copyright 2025 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 androidx.appfunctions.testing
18 
19 import androidx.appfunctions.AppFunctionFunctionNotFoundException
20 import androidx.appfunctions.AppFunctionSearchSpec
21 import androidx.appfunctions.internal.AppFunctionReader
22 import androidx.appfunctions.metadata.AppFunctionSchemaMetadata
23 
24 class FakeAppFunctionReader : AppFunctionReader {
25 
26     private val appFunctionMetadataMap =
27         mutableMapOf<Pair<String, String>, AppFunctionSchemaMetadata>()
28 
addAppFunctionMetadatanull29     fun addAppFunctionMetadata(
30         functionId: String,
31         packageName: String,
32         metadata: AppFunctionSchemaMetadata
33     ) {
34         appFunctionMetadataMap[Pair(functionId, packageName)] = metadata
35     }
36 
clearnull37     fun clear() {
38         appFunctionMetadataMap.clear()
39     }
40 
searchAppFunctionsnull41     override fun searchAppFunctions(searchFunctionSpec: AppFunctionSearchSpec) =
42         TODO("Not yet implemented")
43 
44     override suspend fun getAppFunctionSchemaMetadata(
45         functionId: String,
46         packageName: String
47     ): AppFunctionSchemaMetadata? {
48         val key = Pair(functionId, packageName)
49         if (!appFunctionMetadataMap.containsKey(key)) throw AppFunctionFunctionNotFoundException()
50         return appFunctionMetadataMap[key]
51     }
52 }
53