1 /*
2  * Copyright (C) 2024 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 package com.android.adservices.shared.meta_testing;
17 
18 import static com.android.adservices.shared.testing.device.DeviceConfig.SyncDisabledModeForTest.UNTIL_REBOOT;
19 
20 import com.android.adservices.shared.testing.annotations.SetSdkSandboxStateEnabled;
21 import com.android.adservices.shared.testing.annotations.SetSyncDisabledModeForTest;
22 
23 import org.junit.runner.Description;
24 
25 import java.lang.annotation.Annotation;
26 
27 /** Provides common test descriptions and helpers for tests that test JUnit stuff. */
28 public final class CommonDescriptions {
29 
CommonDescriptions()30     private CommonDescriptions() {
31         throw new UnsupportedOperationException("provides only static methods");
32     }
33 
34     /** Creates a description that emulates a test that can only be used in a class rule context. */
newTestMethodForClassRule(Class<?> clazz, Annotation... annotations)35     public static Description newTestMethodForClassRule(Class<?> clazz, Annotation... annotations) {
36         Description child = Description.createTestDescription(clazz, "butItHasATest");
37         Description suite = Description.createSuiteDescription(clazz, annotations);
38         suite.addChild(child);
39         return suite;
40     }
41 
42     public static class AClassHasNoNothingAtAll {}
43 
44     @SetSdkSandboxStateEnabled(true)
45     public static class AClassEnablesSdkSandbox {}
46 
47     @SetSdkSandboxStateEnabled(false)
48     public static class AClassDisablesSdkSandbox {}
49 
50     @SetSyncDisabledModeForTest(UNTIL_REBOOT)
51     public static class AClassDisablesDeviceConfigUntilReboot {}
52 
53     @SetSyncDisabledModeForTest
54     public static class AClassWithDefaultSetSyncDisabledModeForTest {}
55 
56     @SetSdkSandboxStateEnabled
57     @SetSyncDisabledModeForTest(UNTIL_REBOOT)
58     public static class AClassEnablesSdkSandboxAndDisablesDeviceConfigUntilReboot {}
59 
60     @SetSdkSandboxStateEnabled(true)
61     @SetSyncDisabledModeForTest(UNTIL_REBOOT)
62     public static class ASubClassEnablesSdkSandboxAndAlsoDisablesDeviceConfigUntilReboot
63             extends AClassDisablesDeviceConfigUntilReboot {}
64 
65     @SetSyncDisabledModeForTest(UNTIL_REBOOT)
66     @SetSdkSandboxStateEnabled(true)
67     public static class ASubClassDisablesDeviceConfigUntilRebootAndAlsoEnablesSdkSandbox
68             extends AClassDisablesDeviceConfigUntilReboot {}
69 
70     /** A "typical" superclass, like a "root" CTS class" - it only disables sync mode. */
71     @SetSyncDisabledModeForTest
72     public static class ATypicalSuperClass {}
73 
74     /** A "typical" subclass - it extends superclass and don't have any annotation. */
75     public static class ATypicalSubclass extends ATypicalSuperClass {}
76 
77     @SetSdkSandboxStateEnabled
78     public interface AnInterfaceEnablesSdkSandbox {}
79 
80     public static class ATypicalSubclassThatImplementsAnInterfaceThatEnablesSdkSandbox
81             extends ATypicalSuperClass implements AnInterfaceEnablesSdkSandbox {}
82 }
83