• 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.example.android.aconfig.demo;
18 
19 import android.platform.test.annotations.RequiresFlagsDisabled;
20 import android.platform.test.annotations.RequiresFlagsEnabled;
21 import android.platform.test.flag.junit.CheckFlagsRule;
22 import android.platform.test.flag.junit.DeviceFlagsValueProvider;
23 
24 import com.example.android.aconfig.demo.flags.Flags;
25 
26 import org.junit.Rule;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.junit.runners.JUnit4;
30 
31 /** Tests for how combination of flags states effects execution */
32 @RunWith(JUnit4.class)
33 public final class FlagStateComboTests {
34     @Rule
35     public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
36 
37     @Test
38     @RequiresFlagsEnabled(Flags.FLAG_AWESOME_FLAG_1)
requires_f1on_pass_or_skip()39     public void requires_f1on_pass_or_skip() {}
40 
41     @Test
42     @RequiresFlagsDisabled(Flags.FLAG_AWESOME_FLAG_2)
requires_f2off_pass_or_skip()43     public void requires_f2off_pass_or_skip() {}
44 
45     @Test
46     @RequiresFlagsEnabled(Flags.FLAG_AWESOME_FLAG_1)
requires_f1on_throw_or_skip()47     public void requires_f1on_throw_or_skip() {
48         throw new RuntimeException("This exception is expected if "
49             + Flags.FLAG_AWESOME_FLAG_1 + " is enabled");
50     }
51 
52     @Test
53     @RequiresFlagsDisabled(Flags.FLAG_AWESOME_FLAG_2)
requires_f2off_throw_or_skip()54     public void requires_f2off_throw_or_skip() {
55         throw new RuntimeException("This exception is expected if "
56             + Flags.FLAG_AWESOME_FLAG_2 + " is disabled");
57     }
58 
59     @Test
60     @RequiresFlagsEnabled({Flags.FLAG_AWESOME_FLAG_1, Flags.FLAG_AWESOME_FLAG_2})
requires_f1on_f2on_pass_or_skip()61     public void requires_f1on_f2on_pass_or_skip() {}
62 
63     @Test
64     @RequiresFlagsEnabled(Flags.FLAG_AWESOME_FLAG_1)
65     @RequiresFlagsDisabled(Flags.FLAG_AWESOME_FLAG_2)
requires_f1on_f2off_throw_or_skip()66     public void requires_f1on_f2off_throw_or_skip() {
67         throw new RuntimeException("This exception is expected if "
68             + Flags.FLAG_AWESOME_FLAG_1 + " is enabled and "
69             + Flags.FLAG_AWESOME_FLAG_2 + " is disabled");
70     }
71 }
72