1 // Copyright 2021 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 package org.chromium.base.test.util; 6 7 import org.junit.Assert; 8 import org.junit.Test; 9 import org.junit.runner.RunWith; 10 import org.robolectric.annotation.Config; 11 12 import org.chromium.base.CommandLine; 13 import org.chromium.base.test.BaseRobolectricTestRunner; 14 15 /** 16 * Unit tests for {@link CommandLineFlags} annotations. This is for testing when there is no 17 * annotation on the class level. 18 */ 19 @RunWith(BaseRobolectricTestRunner.class) 20 @Config(manifest = Config.NONE) 21 public class CommandLineFlagsNoClassAnnotationCheckTest { 22 @Test testNoAnnotation()23 public void testNoAnnotation() throws Throwable { 24 var switches = CommandLine.getInstance().getSwitches(); 25 Assert.assertTrue("CommandLine switches should be empty: " + switches, switches.isEmpty()); 26 } 27 28 @Test 29 @CommandLineFlags.Add("some-switch") testAddSwitch_method()30 public void testAddSwitch_method() throws Throwable { 31 Assert.assertTrue( 32 "some-switch should be appended", 33 CommandLine.getInstance().hasSwitch("some-switch")); 34 } 35 36 @Test 37 @CommandLineFlags.Add("some-switch=method_value") 38 @CommandLineFlags.Remove("some-switch") testAddThenRemoveSwitch_method()39 public void testAddThenRemoveSwitch_method() throws Throwable { 40 Assert.assertEquals( 41 "some-switch should be removed from the class level and added back, not ignored", 42 "method_value", 43 CommandLine.getInstance().getSwitchValue("some-switch")); 44 } 45 46 @Test 47 @CommandLineFlags.Remove("some-switch") 48 @CommandLineFlags.Add("some-switch=method_value") testRemoveThenAddSwitch_method()49 public void testRemoveThenAddSwitch_method() throws Throwable { 50 Assert.assertEquals( 51 "some-switch should be removed from the class level and added back, not ignored", 52 "method_value", 53 CommandLine.getInstance().getSwitchValue("some-switch")); 54 } 55 } 56