aboutsummaryrefslogtreecommitdiff
path: root/robolectric/src/test/java/org/robolectric/shadows/ShadowRoleManagerTest.java
blob: 86109b09555332bd1d391e534f43a66ed713d055 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package org.robolectric.shadows;

import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;
import static org.robolectric.RuntimeEnvironment.getApplication;
import static org.robolectric.Shadows.shadowOf;

import android.app.role.RoleManager;
import android.content.Context;
import android.os.Build;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;

/** Unit tests for {@link org.robolectric.shadows.ShadowRoleManager}. */
@RunWith(AndroidJUnit4.class)
@Config(minSdk = Build.VERSION_CODES.Q)
public final class ShadowRoleManagerTest {
  private RoleManager roleManager;

  @Before
  public void setUp() {
    roleManager = (RoleManager) getApplication().getSystemService(Context.ROLE_SERVICE);
  }

  @Test(expected = IllegalArgumentException.class)
  public void isRoleHeld_shouldThrowWithNullArgument() {
    shadowOf(roleManager).isRoleHeld(null);
  }

  @Test()
  public void addHeldRole_isPresentInIsRoleHeld() {
    shadowOf(roleManager).addHeldRole(RoleManager.ROLE_SMS);
    assertThat(roleManager.isRoleHeld(RoleManager.ROLE_SMS)).isTrue();
  }

  @Test()
  public void removeHeldRole_notPresentInIsRoleHeld() {
    shadowOf(roleManager).addHeldRole(RoleManager.ROLE_SMS);
    shadowOf(roleManager).removeHeldRole(RoleManager.ROLE_SMS);
    assertThat(roleManager.isRoleHeld(RoleManager.ROLE_SMS)).isFalse();
  }

  @Test()
  public void isRoleHeld_noValueByDefault() {
    assertThat(roleManager.isRoleHeld(RoleManager.ROLE_SMS)).isFalse();
  }

  @Test
  public void isRoleAvailable_shouldThrowWithNullArgument() {
    assertThrows(IllegalArgumentException.class, () -> shadowOf(roleManager).isRoleAvailable(null));
  }

  @Test()
  public void addAvailableRole_isPresentInIsRoleAvailable() {
    shadowOf(roleManager).addAvailableRole(RoleManager.ROLE_SMS);
    assertThat(roleManager.isRoleAvailable(RoleManager.ROLE_SMS)).isTrue();
  }

  @Test()
  public void addAvailableRole_shouldThrowWithEmptyArgument() {
    assertThrows(IllegalArgumentException.class, () -> shadowOf(roleManager).addAvailableRole(""));
  }

  @Test()
  public void removeAvailableRole_notPresentInIsRoleAvailable() {
    shadowOf(roleManager).addAvailableRole(RoleManager.ROLE_SMS);
    shadowOf(roleManager).removeAvailableRole(RoleManager.ROLE_SMS);
    assertThat(roleManager.isRoleAvailable(RoleManager.ROLE_SMS)).isFalse();
  }

  @Test()
  public void isRoleAvailable_noValueByDefault() {
    assertThat(roleManager.isRoleAvailable(RoleManager.ROLE_SMS)).isFalse();
  }
}