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

Catch null intent data #663

Merged
merged 2 commits into from
Jun 2, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void run() {
}

Intent intent = activity.getIntent();
if (activity.getIntent() == null) {
if (intent == null || intent.getData() == null) {
return;
}

Expand Down
66 changes: 66 additions & 0 deletions analytics/src/test/java/com/segment/analytics/AnalyticsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,72 @@ protected boolean matchesSafely(TrackPayload payload) {
}));
}

@Test
public void trackDeepLinks_nullData() {
Analytics.INSTANCES.clear();

final AtomicReference<Application.ActivityLifecycleCallbacks> callback =
new AtomicReference<>();
doNothing()
.when(application)
.registerActivityLifecycleCallbacks(
argThat(
new NoDescriptionMatcher<Application.ActivityLifecycleCallbacks>() {
@Override
protected boolean matchesSafely(Application.ActivityLifecycleCallbacks item) {
callback.set(item);
return true;
}
}));

analytics =
new Analytics(
application,
networkExecutor,
stats,
traitsCache,
analyticsContext,
defaultOptions,
Logger.with(NONE),
"qaz",
Collections.singletonList(factory),
client,
Cartographer.INSTANCE,
projectSettingsCache,
"foo",
DEFAULT_FLUSH_QUEUE_SIZE,
DEFAULT_FLUSH_INTERVAL,
analyticsExecutor,
true,
new CountDownLatch(0),
false,
false,
false,
optOut,
Crypto.none(),
Collections.<Middleware>emptyList(),
new ValueMap());

Activity activity = mock(Activity.class);

Intent intent = mock(Intent.class);

when(activity.getIntent()).thenReturn(intent);
when(intent.getData()).thenReturn(null);

callback.get().onActivityCreated(activity, new Bundle());

verify(integration, never())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the intention here to check if no interactions have occurred with the integration object or just this specific interaction?

.track(
argThat(
new NoDescriptionMatcher<TrackPayload>() {
@Override
protected boolean matchesSafely(TrackPayload payload) {
return payload.event().equals("Deep Link Opened");
}
}));
}

@Test
public void registerActivityLifecycleCallbacks() throws NameNotFoundException {
Analytics.INSTANCES.clear();
Expand Down