• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 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;
6 
7 import static org.junit.Assert.assertFalse;
8 import static org.junit.Assert.assertTrue;
9 
10 import android.content.Context;
11 import android.content.pm.PackageManager;
12 
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.junit.runner.RunWith;
16 import org.robolectric.Shadows;
17 import org.robolectric.annotation.Config;
18 import org.robolectric.shadows.ShadowPackageManager;
19 
20 import org.chromium.base.test.BaseRobolectricTestRunner;
21 
22 /** Unit tests for {@link BuildInfo}. */
23 @RunWith(BaseRobolectricTestRunner.class)
24 @Config(manifest = Config.NONE)
25 public class BuildInfoTest {
26     private ShadowPackageManager mShadowPackageManager;
27 
28     @Before
setUp()29     public void setUp() {
30         Context context = ContextUtils.getApplicationContext();
31         mShadowPackageManager = Shadows.shadowOf(context.getPackageManager());
32     }
33 
34     @Test
testIsAutomotive_trueIfFeatureAutomotiveTrue()35     public void testIsAutomotive_trueIfFeatureAutomotiveTrue() {
36         mShadowPackageManager.setSystemFeature(
37                 PackageManager.FEATURE_AUTOMOTIVE, /* supported= */ true);
38 
39         assertTrue(BuildInfo.getInstance().isAutomotive);
40     }
41 
42     @Test
testIsAutomotive_falseIfFeatureAutomotiveFalse()43     public void testIsAutomotive_falseIfFeatureAutomotiveFalse() {
44         mShadowPackageManager.setSystemFeature(
45                 PackageManager.FEATURE_AUTOMOTIVE, /* supported= */ false);
46 
47         assertFalse(BuildInfo.getInstance().isAutomotive);
48     }
49 }
50