Skip to content

Commit

Permalink
Catch null intent data (#663)
Browse files Browse the repository at this point in the history
* catch null intent data

* clean java formatting

Co-authored-by: Niall Brennan <niall.brennan@segment.com>
  • Loading branch information
niallzato and Niall Brennan authored Jun 2, 2020
1 parent 6155b08 commit 1b7c5c0
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
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 @@ -1189,6 +1189,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())
.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

0 comments on commit 1b7c5c0

Please sign in to comment.