• 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 android.platform.test.flag.junit;
18 
19 import static org.junit.Assert.assertThrows;
20 import static org.junit.Assert.assertTrue;
21 
22 import android.platform.test.flag.util.FlagReadException;
23 
24 import org.junit.After;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.junit.runners.JUnit4;
29 
30 /** Unit tests for {@code DeviceFlagsValueProvider}. */
31 @RunWith(JUnit4.class)
32 public final class DeviceFlagsValueProviderTest {
33     private final DeviceFlagsValueProvider mFlagsValueProvider = new DeviceFlagsValueProvider();
34 
35     @Before
setUp()36     public void setUp() {
37         mFlagsValueProvider.setUp();
38     }
39 
40     @After
tearDown()41     public void tearDown() {
42         mFlagsValueProvider.tearDownBeforeTest();
43     }
44 
45     @Test
getBoolean_classNotFound_throwException()46     public void getBoolean_classNotFound_throwException() {
47         assertThrows(
48                 FlagReadException.class,
49                 () -> mFlagsValueProvider.getBoolean("android.platform.test.flagName1"));
50     }
51 
52     @Test
getBoolean_noSuchMethod_throwException()53     public void getBoolean_noSuchMethod_throwException() {
54         assertThrows(
55                 FlagReadException.class,
56                 () -> mFlagsValueProvider.getBoolean("android.platfrm.test.flag.junit.flag1"));
57     }
58 
59     @Test
getBoolean_notBooleanFlag_throwException()60     public void getBoolean_notBooleanFlag_throwException() {
61         assertThrows(
62                 FlagReadException.class,
63                 () ->
64                         mFlagsValueProvider.getBoolean(
65                                 "android.platform.test.flag.junit.flag_name_2"));
66     }
67 
68     @Test
getBoolean_aconfigFlagWithNameSpace_throwException()69     public void getBoolean_aconfigFlagWithNameSpace_throwException() throws Exception {
70         assertThrows(
71                 FlagReadException.class,
72                 () ->
73                         mFlagsValueProvider.getBoolean(
74                                 "namespace/android.platform.test.flag.junit.flag_name_1"));
75     }
76 
77     @Test
getBoolean_fromNotExistLegacyFlag_throwException()78     public void getBoolean_fromNotExistLegacyFlag_throwException() {
79         assertThrows(
80                 FlagReadException.class,
81                 () -> mFlagsValueProvider.getBoolean("does_not_exist/flag"));
82     }
83 
84     @Test
getBoolean_fromLegacyNonBooleanFlag_throwException()85     public void getBoolean_fromLegacyNonBooleanFlag_throwException() {
86         assertThrows(
87                 FlagReadException.class,
88                 () -> mFlagsValueProvider.getBoolean("my_namespace/flag2"));
89     }
90 
91     @Test
getBoolean_fromLegacyBooleanFlag()92     public void getBoolean_fromLegacyBooleanFlag() throws Exception {
93         assertTrue(mFlagsValueProvider.getBoolean("my_namespace/flag1"));
94     }
95 }
96