• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.car.settings.common;
18 
19 import static com.google.common.truth.Truth.assertWithMessage;
20 
21 import androidx.preference.Preference;
22 
23 public class PreferenceControllerTestUtil {
24     /**
25      * Associates a PreferenceController with its Preference.
26      */
assignPreference(PreferenceController controller, Preference preference)27     public static void assignPreference(PreferenceController controller, Preference preference) {
28         controller.setPreference(preference);
29     }
30 
assertAvailability(int actualValue, int expectedValue)31     public static void assertAvailability(int actualValue, int expectedValue) {
32         assertWithMessage("controller availability (%s=%s, %s=%s)",
33                 actualValue, availabilityToString(actualValue),
34                 expectedValue, availabilityToString(expectedValue))
35                 .that(actualValue).isEqualTo(expectedValue);
36     }
37 
availabilityToString(int value)38     private static String availabilityToString(int value) {
39         switch (value) {
40             case PreferenceController.AVAILABLE:
41                 return "AVAILABLE";
42             case PreferenceController.AVAILABLE_FOR_VIEWING:
43                 return "AVAILABLE_FOR_VIEWING";
44             case PreferenceController.CONDITIONALLY_UNAVAILABLE:
45                 return "CONDITIONALLY_UNAVAILABLE";
46             case PreferenceController.DISABLED_FOR_PROFILE:
47                 return "DISABLED_FOR_PROFILE";
48             case PreferenceController.UNSUPPORTED_ON_DEVICE:
49                 return "UNSUPPORTED_ON_DEVICE";
50             default:
51                 return "INVALID-" + value;
52         }
53     }
54 }
55