• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.testing;
18 
19 import android.text.TextUtils;
20 import com.android.tv.common.config.api.RemoteConfig;
21 import java.util.HashMap;
22 import java.util.Map;
23 
24 /** Fake {@link RemoteConfig} suitable for testing. */
25 public class FakeRemoteConfig implements RemoteConfig {
26     public final Map<String, String> values = new HashMap();
27 
28     @Override
fetch(OnRemoteConfigUpdatedListener listener)29     public void fetch(OnRemoteConfigUpdatedListener listener) {}
30 
31     @Override
getString(String key)32     public String getString(String key) {
33         return values.get(key);
34     }
35 
36     @Override
getBoolean(String key)37     public boolean getBoolean(String key) {
38         String value = values.get(key);
39         return TextUtils.isEmpty(value) ? false : Boolean.valueOf(key);
40     }
41 
42     @Override
getLong(String key)43     public long getLong(String key) {
44         return getLong(key, 0);
45     }
46 
47     @Override
getLong(String key, long defaultValue)48     public long getLong(String key, long defaultValue) {
49         if (values.containsKey(key)) {
50             String value = values.get(key);
51             return TextUtils.isEmpty(value) ? defaultValue : Long.valueOf(value);
52         }
53         return defaultValue;
54     }
55 }
56