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

Require UserId for MapLoadEvent #41

Merged
merged 1 commit into from
Jan 10, 2018
Merged

Conversation

electrostat
Copy link
Contributor

Spec changed to require UserId for MapLoadEvent

Copy link
Contributor

@Guardiola31337 Guardiola31337 left a comment

Choose a reason for hiding this comment

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

I don't know if this PR is ready for review because it's labeled as in progress but a review was requested.

Anyways, some details to take into account before merging it.

We should also include some unit tests around userId now being a required field for map load events.

@@ -234,6 +235,12 @@ private void checkLoad(Event.Type type) {
}
}

private void checkUserId(String userId) {
if (userId == null && userId.isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This would cause a NullPointerException 💥 if userId is null.

Method invocation 'isEmpty' may produce 'java.lang.NullPointerException'

The IDE hints you about this potential issue/crash.

Copy link
Contributor

Choose a reason for hiding this comment

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

IllegalArgumentException should be thrown in two situations:

  • If userId is null
  • If userId is not null but it's empty

Why not using TelemetryUtils#isEmpty?

@@ -29,7 +29,7 @@ public void checksMapLoadEvent() throws Exception {
initializeMapboxTelemetry();
MapEventFactory aMapEventFactory = new MapEventFactory();

Event mapLoadEvent = aMapEventFactory.createMapLoadEvent(Event.Type.MAP_LOAD);
Event mapLoadEvent = aMapEventFactory.createMapLoadEvent(Event.Type.MAP_LOAD, "aUserId");
Copy link
Contributor

Choose a reason for hiding this comment

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

This is actually a valid user id.
The same thing happens in the tests below 👇
We should add the missing not valid tests.

public void checksLoadEmptyUserId() throws Exception {
initializeMapboxTelemetry();
MapEventFactory aMapEventFactory = new MapEventFactory();
Event.Type notALoadMapType = Event.Type.MAP_CLICK;
Copy link
Contributor

Choose a reason for hiding this comment

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

This test is passing but it's not testing that when creating a map load event (Event.Type.MAP_LOAD) with an empty user id it throws an IllegalArgumentException.
It's actually throwing an IllegalArgumentException because it's not a load map type (Event.Type.MAP_CLICK) which is already tested.

public void checksLoadNullUserId() throws Exception {
initializeMapboxTelemetry();
MapEventFactory aMapEventFactory = new MapEventFactory();
Event.Type notALoadMapType = Event.Type.MAP_CLICK;
Copy link
Contributor

Choose a reason for hiding this comment

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

This test is passing but it's not testing that when creating a map load event (Event.Type.MAP_LOAD) with an null user id it throws an IllegalArgumentException.
It's actually throwing an IllegalArgumentException because it's not a load map type (Event.Type.MAP_CLICK) which is already tested.

@@ -113,7 +113,7 @@ private Event obtainLoadEvent() {
when(mockedContext.getSystemService(Context.WINDOW_SERVICE)).thenReturn(mockedWindowManager);
initializeMapboxTelemetry(mockedContext);
MapEventFactory mapEventFactory = new MapEventFactory();
Event loadEvent = mapEventFactory.createMapLoadEvent(Event.Type.MAP_LOAD);
Event loadEvent = mapEventFactory.createMapLoadEvent(Event.Type.MAP_LOAD, "aUserId");
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT "aValidUserId"

Copy link
Contributor

@Guardiola31337 Guardiola31337 left a comment

Choose a reason for hiding this comment

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

This should have been rebased from master instead of merged.

Could you do that? Most changes come from #42 (already reviewed and merged) making hard this PR's revision.

Copy link
Contributor

@Guardiola31337 Guardiola31337 left a comment

Choose a reason for hiding this comment

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

This branch is out-of-date with the base branch

We'd need to rebase from master

After ☝️ this should be ready to go :shipit:

- require a String userId when creating maploadevent
- add excemption for invalid userId
- update and tweak tests
@electrostat electrostat merged commit d34dcf7 into master Jan 10, 2018
@electrostat electrostat deleted the aa-userid-meets-spec branch January 10, 2018 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants