MapboxOfflineDownloaderService extends Service implements OfflineRegionObserver, OnDownloadMapListener { @Override public void mapboxTileCountLimitExceeded(long limit) { String finalMessage = String.format(getString(R.string.error_mapbox_tile_count_limit), limit, currentMapDownloadName); Log.e(TAG, finalMessage); sendBroadcast(SERVICE_ACTION_RESULT.FAILED, currentMapDownloadName, SERVICE_ACTION.DOWNLOAD_MAP, finalMessage); LAST_DOWNLOAD_ERROR_NOTIFICATION_ID++; CriticalDownloadErrorNotification criticalDownloadErrorNotification = new CriticalDownloadErrorNotification(this); criticalDownloadErrorNotification.displayNotification(String.format(getString(R.string.error_occurred_download_map), currentMapDownloadName) , String.format(getString(R.string.mapbox_tile_count_limit_of_exceeded), limit), LAST_DOWNLOAD_ERROR_NOTIFICATION_ID); cleanupAndExit(); } MapboxOfflineDownloaderService(); @Override int onStartCommand(@Nullable Intent intent, int flags, int startId); @Nullable @Override IBinder onBind(Intent intent); @Override void onStatusChanged(@NonNull OfflineRegionStatus status, @NonNull OfflineRegion offlineRegion); @Override void onError(String error); @Override void onError(@NonNull String reason, @Nullable String message); @Override void mapboxTileCountLimitExceeded(long limit); @Override void onDestroy(); static final String KEY_RESULT_STATUS; static final String KEY_RESULT_MESSAGE; static final String KEY_RESULTS_PARENT_ACTION; static final String MY_PREFERENCES; static final String PREFERENCE_MAPBOX_ACCESS_TOKEN; static final int PROGRESS_NOTIFICATION_ID; static final int REQUEST_ID_STOP_MAP_DOWNLOAD; static int LAST_DOWNLOAD_COMPLETE_NOTIFICATION_ID; static int LAST_DOWNLOAD_ERROR_NOTIFICATION_ID; @RestrictTo(RestrictTo.Scope.TESTS)
    public boolean onStartCommandCalled; @RestrictTo(RestrictTo.Scope.TESTS)
    public boolean persistOfflineMapTaskCalled; @RestrictTo(RestrictTo.Scope.TESTS)
    public boolean performNextTaskCalled; @RestrictTo(RestrictTo.Scope.TESTS)
    public boolean observeOfflineRegionCalled; }
@Test public void mapboxTileLimitExceededShouldCreateValidBroadcast() throws InterruptedException, NoSuchFieldException, IllegalAccessException { latch = new CountDownLatch(1); registerLocalBroadcastReceiverForDownloadServiceUpdates(); setMapNameAndDownloadAction(mapName, MapboxOfflineDownloaderService.SERVICE_ACTION.DOWNLOAD_MAP); mapboxOfflineDownloaderService.mapboxTileCountLimitExceeded(60000); latch.await(); Intent intent = (Intent) resultsToCheck.get(0); assertBroadcastResults(intent, MapboxOfflineDownloaderService.SERVICE_ACTION_RESULT.FAILED, mapName, "MapBox Tile Count limit exceeded 60000 while Downloading " + mapName, MapboxOfflineDownloaderService.SERVICE_ACTION.DOWNLOAD_MAP); }