Skip to content

Check for successful tar response in TarFetchedCallback#1620

Merged
danesfeder merged 1 commit into
masterfrom
dan-error-tar
Dec 12, 2018
Merged

Check for successful tar response in TarFetchedCallback#1620
danesfeder merged 1 commit into
masterfrom
dan-error-tar

Conversation

@danesfeder
Copy link
Copy Markdown
Contributor

We can check for a successful Response in the TarFetchedCallback to provide more information for situations like #1618, where developers are using tokens are aren't compatible with offline routing.

The main point of this PR was:

  @Override
  public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) {
    if (response.isSuccessful()) {
      downloadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, response.body());
    } else {
      OfflineError error = new OfflineError(response.message());
      downloader.onError(error);
    }
  }

But, I also took some time to extract some of the callbacks and listeners that were living in the RouteTileDownloader. By extracting them, we can add tests to verify the business logic being executed in each callback or listener. I did not change any business logic, this was mainly shuffling classes around / adding constructors for the dependencies they needed.

@codecov-io
Copy link
Copy Markdown

codecov-io commented Dec 10, 2018

Codecov Report

Merging #1620 into master will increase coverage by 0.81%.
The diff coverage is 87.87%.

@@             Coverage Diff              @@
##             master    #1620      +/-   ##
============================================
+ Coverage     22.76%   23.58%   +0.81%     
- Complexity      704      728      +24     
============================================
  Files           189      193       +4     
  Lines          8244     8276      +32     
  Branches        609      609              
============================================
+ Hits           1877     1952      +75     
+ Misses         6184     6139      -45     
- Partials        183      185       +2

Copy link
Copy Markdown
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.

Great work @danesfeder

I've left a couple of minor comments / questions.

Thanks for running with this one.


@Test
public void onSuccessfulResponse_downloadTaskIsExecuted() {
RouteTileDownloader downloader = mock(RouteTileDownloader.class);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you extract (if possible) some of the shared arrange code across these tests into a private factory method?


@Test
public void onFinishedDownloading_tarIsUnpacked() {
RouteTileDownloader downloader = mock(RouteTileDownloader.class);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you extract (if possible) some of the shared arrange code across these tests into a private factory method?

if (response.isSuccessful()) {
downloadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, response.body());
} else {
OfflineError error = new OfflineError(response.message());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It'd be 💯 appending the response code to the error message.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For extra context these are the messages used in iOS mapbox/mapbox-navigation-ios#1892

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Deep link -> here


@Override
public void onErrorDownloading() {
OfflineError error = new OfflineError("Error occurred downloading tiles: null file");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How about extracting this magic number into a constant?

@danesfeder
Copy link
Copy Markdown
Contributor Author

@Guardiola31337 thanks for the feedback, this is updated

Copy link
Copy Markdown
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.

Thanks for addressing the feedback @danesfeder

🚢:ship::ship:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants