Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getCallingPackage and setCallingPackage to ShadowActivity #5126

Merged
merged 1 commit into from Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -1006,6 +1006,23 @@ public void getCallingActivity_returnsSetValue() {
assertEquals(componentName, activity.getCallingActivity());
}

@Test
public void getCallingPackage_defaultsToNull() {
Activity activity = Robolectric.setupActivity(Activity.class);

assertNull(activity.getCallingPackage());
}

@Test
public void getCallingPackage_returnsSetValue() {
Activity activity = Robolectric.setupActivity(Activity.class);
String packageName = "com.example.package";

shadowOf(activity).setCallingPackage(packageName);

assertEquals(packageName, activity.getCallingPackage());
}

@Test
@Config(minSdk = LOLLIPOP)
public void lockTask() {
Expand Down
Expand Up @@ -74,6 +74,7 @@ public class ShadowActivity extends ShadowContextThemeWrapper {
private boolean mIsTaskRoot = true;
private Menu optionsMenu;
private ComponentName callingActivity;
private String callingPackage;
private PermissionsRequest lastRequestedPermission;
private ActivityController controller;
private boolean inMultiWindowMode = false;
Expand Down Expand Up @@ -137,6 +138,15 @@ protected ComponentName getCallingActivity() {
return callingActivity;
}

public void setCallingPackage(String packageName) {
callingPackage = packageName;
}

@Implementation
protected String getCallingPackage() {
return callingPackage;
}

@Implementation
protected void setDefaultKeyMode(int keyMode) {
mDefaultKeyMode = keyMode;
Expand Down