This change will generate full fakefeatureflagsimpl in prod mode. FakeFeatureFlagsImp will be the same in test mode and the prod mode. FeatureFlagsImpl will be all unimplemented in test mode. setFlag, resetAll are added into the interface FeatureFlags. The reason to make this change is for project using injection pattern, the project doesn't have to use test mode to test the flag guarded code. The project can directly use the FakeFeatureFlagsImpl for testing. Bug: 294838180 Test: atest AconfigJavaHostTest --host AND atest aconfig.test.java Change-Id: Ib6d40fd3a9ef872e01594fd4f8d6c4cb10bb173a
68 lines
2.7 KiB
Java
68 lines
2.7 KiB
Java
import static com.android.aconfig.test.Flags.FLAG_DISABLED_RO;
|
|
import static com.android.aconfig.test.Flags.FLAG_DISABLED_RW;
|
|
import static com.android.aconfig.test.Flags.FLAG_ENABLED_FIXED_RO;
|
|
import static com.android.aconfig.test.Flags.FLAG_ENABLED_RO;
|
|
import static com.android.aconfig.test.Flags.FLAG_ENABLED_RW;
|
|
import static com.android.aconfig.test.Flags.disabledRo;
|
|
import static com.android.aconfig.test.Flags.disabledRw;
|
|
import static com.android.aconfig.test.Flags.enabledFixedRo;
|
|
import static com.android.aconfig.test.Flags.enabledRo;
|
|
import static com.android.aconfig.test.Flags.enabledRw;
|
|
import static org.junit.Assert.assertEquals;
|
|
import static org.junit.Assert.assertFalse;
|
|
import static org.junit.Assert.assertThrows;
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
import org.junit.Test;
|
|
import org.junit.runner.RunWith;
|
|
import org.junit.runners.JUnit4;
|
|
|
|
import com.android.aconfig.test.FakeFeatureFlagsImpl;
|
|
import com.android.aconfig.test.FeatureFlags;
|
|
|
|
@RunWith(JUnit4.class)
|
|
public final class AconfigTest {
|
|
@Test
|
|
public void testDisabledReadOnlyFlag() {
|
|
assertEquals("com.android.aconfig.test.disabled_ro", FLAG_DISABLED_RO);
|
|
assertFalse(disabledRo());
|
|
}
|
|
|
|
@Test
|
|
public void testEnabledReadOnlyFlag() {
|
|
assertEquals("com.android.aconfig.test.disabled_rw", FLAG_DISABLED_RW);
|
|
// TODO: change to assertTrue(enabledRo()) when the build supports reading tests/*.values
|
|
// (currently all flags are assigned the default READ_ONLY + DISABLED)
|
|
assertFalse(enabledRo());
|
|
}
|
|
|
|
@Test
|
|
public void testEnabledFixedReadOnlyFlag() {
|
|
assertEquals("com.android.aconfig.test.enabled_fixed_ro", FLAG_ENABLED_FIXED_RO);
|
|
// TODO: change to assertTrue(enabledFixedRo()) when the build supports reading tests/*.values
|
|
// (currently all flags are assigned the default READ_ONLY + DISABLED)
|
|
assertFalse(enabledFixedRo());
|
|
}
|
|
|
|
@Test
|
|
public void testDisabledReadWriteFlag() {
|
|
assertEquals("com.android.aconfig.test.enabled_ro", FLAG_ENABLED_RO);
|
|
assertFalse(disabledRw());
|
|
}
|
|
|
|
@Test
|
|
public void testEnabledReadWriteFlag() {
|
|
assertEquals("com.android.aconfig.test.enabled_rw", FLAG_ENABLED_RW);
|
|
// TODO: change to assertTrue(enabledRw()) when the build supports reading tests/*.values
|
|
// (currently all flags are assigned the default READ_ONLY + DISABLED)
|
|
assertFalse(enabledRw());
|
|
}
|
|
|
|
@Test
|
|
public void testFakeFeatureFlagsImplImpled() {
|
|
FakeFeatureFlagsImpl fakeFeatureFlags = new FakeFeatureFlagsImpl();
|
|
fakeFeatureFlags.setFlag(FLAG_ENABLED_RW, false);
|
|
assertFalse(fakeFeatureFlags.enabledRw());
|
|
}
|
|
}
|