@Test public void performPauseOnlyDetachesPausedRequest() { Action action1 = mockAction(URI_KEY_1, URI_1, mockTarget(), "tag1"); Action action2 = mockAction(URI_KEY_1, URI_1, mockTarget(), "tag2"); BitmapHunter hunter = mockHunter(URI_KEY_1, bitmap1, false); when(hunter.getActions()).thenReturn(Arrays.asList(action1, action2)); dispatcher.hunterMap.put(URI_KEY_1, hunter); dispatcher.performPauseTag("tag1"); assertThat(dispatcher.hunterMap).hasSize(1).containsValue(hunter); assertThat(dispatcher.pausedActions).hasSize(1).containsValue(action1); verify(hunter).detach(action1); verify(hunter, never()).detach(action2); }
void performPauseTag(Object tag) { if (!pausedTags.add(tag)) { return; } for (Iterator<BitmapHunter> it = hunterMap.values().iterator(); it.hasNext();) { BitmapHunter hunter = it.next(); boolean loggingEnabled = hunter.getPicasso().loggingEnabled; Action single = hunter.getAction(); List<Action> joined = hunter.getActions(); boolean hasMultiple = joined != null && !joined.isEmpty(); if (single == null && !hasMultiple) { continue; } if (single != null && single.getTag().equals(tag)) { hunter.detach(single); pausedActions.put(single.getTarget(), single); if (loggingEnabled) { log(OWNER_DISPATCHER, VERB_PAUSED, single.request.logId(), "because tag '" + tag + "' was paused"); } } if (hasMultiple) { for (int i = joined.size() - 1; i >= 0; i--) { Action action = joined.get(i); if (!action.getTag().equals(tag)) { continue; } hunter.detach(action); pausedActions.put(action.getTarget(), action); if (loggingEnabled) { log(OWNER_DISPATCHER, VERB_PAUSED, action.request.logId(), "because tag '" + tag + "' was paused"); } } } if (hunter.cancel()) { it.remove(); if (loggingEnabled) { log(OWNER_DISPATCHER, VERB_CANCELED, getLogIdsForHunter(hunter), "all actions paused"); } } } }
Dispatcher { void performPauseTag(Object tag) { if (!pausedTags.add(tag)) { return; } for (Iterator<BitmapHunter> it = hunterMap.values().iterator(); it.hasNext();) { BitmapHunter hunter = it.next(); boolean loggingEnabled = hunter.getPicasso().loggingEnabled; Action single = hunter.getAction(); List<Action> joined = hunter.getActions(); boolean hasMultiple = joined != null && !joined.isEmpty(); if (single == null && !hasMultiple) { continue; } if (single != null && single.getTag().equals(tag)) { hunter.detach(single); pausedActions.put(single.getTarget(), single); if (loggingEnabled) { log(OWNER_DISPATCHER, VERB_PAUSED, single.request.logId(), "because tag '" + tag + "' was paused"); } } if (hasMultiple) { for (int i = joined.size() - 1; i >= 0; i--) { Action action = joined.get(i); if (!action.getTag().equals(tag)) { continue; } hunter.detach(action); pausedActions.put(action.getTarget(), action); if (loggingEnabled) { log(OWNER_DISPATCHER, VERB_PAUSED, action.request.logId(), "because tag '" + tag + "' was paused"); } } } if (hunter.cancel()) { it.remove(); if (loggingEnabled) { log(OWNER_DISPATCHER, VERB_CANCELED, getLogIdsForHunter(hunter), "all actions paused"); } } } } }
Dispatcher { void performPauseTag(Object tag) { if (!pausedTags.add(tag)) { return; } for (Iterator<BitmapHunter> it = hunterMap.values().iterator(); it.hasNext();) { BitmapHunter hunter = it.next(); boolean loggingEnabled = hunter.getPicasso().loggingEnabled; Action single = hunter.getAction(); List<Action> joined = hunter.getActions(); boolean hasMultiple = joined != null && !joined.isEmpty(); if (single == null && !hasMultiple) { continue; } if (single != null && single.getTag().equals(tag)) { hunter.detach(single); pausedActions.put(single.getTarget(), single); if (loggingEnabled) { log(OWNER_DISPATCHER, VERB_PAUSED, single.request.logId(), "because tag '" + tag + "' was paused"); } } if (hasMultiple) { for (int i = joined.size() - 1; i >= 0; i--) { Action action = joined.get(i); if (!action.getTag().equals(tag)) { continue; } hunter.detach(action); pausedActions.put(action.getTarget(), action); if (loggingEnabled) { log(OWNER_DISPATCHER, VERB_PAUSED, action.request.logId(), "because tag '" + tag + "' was paused"); } } } if (hunter.cancel()) { it.remove(); if (loggingEnabled) { log(OWNER_DISPATCHER, VERB_CANCELED, getLogIdsForHunter(hunter), "all actions paused"); } } } } Dispatcher(Context context, ExecutorService service, Handler mainThreadHandler,
      Downloader downloader, Cache cache, Stats stats); }
Dispatcher { void performPauseTag(Object tag) { if (!pausedTags.add(tag)) { return; } for (Iterator<BitmapHunter> it = hunterMap.values().iterator(); it.hasNext();) { BitmapHunter hunter = it.next(); boolean loggingEnabled = hunter.getPicasso().loggingEnabled; Action single = hunter.getAction(); List<Action> joined = hunter.getActions(); boolean hasMultiple = joined != null && !joined.isEmpty(); if (single == null && !hasMultiple) { continue; } if (single != null && single.getTag().equals(tag)) { hunter.detach(single); pausedActions.put(single.getTarget(), single); if (loggingEnabled) { log(OWNER_DISPATCHER, VERB_PAUSED, single.request.logId(), "because tag '" + tag + "' was paused"); } } if (hasMultiple) { for (int i = joined.size() - 1; i >= 0; i--) { Action action = joined.get(i); if (!action.getTag().equals(tag)) { continue; } hunter.detach(action); pausedActions.put(action.getTarget(), action); if (loggingEnabled) { log(OWNER_DISPATCHER, VERB_PAUSED, action.request.logId(), "because tag '" + tag + "' was paused"); } } } if (hunter.cancel()) { it.remove(); if (loggingEnabled) { log(OWNER_DISPATCHER, VERB_CANCELED, getLogIdsForHunter(hunter), "all actions paused"); } } } } Dispatcher(Context context, ExecutorService service, Handler mainThreadHandler,
      Downloader downloader, Cache cache, Stats stats);  }
Dispatcher { void performPauseTag(Object tag) { if (!pausedTags.add(tag)) { return; } for (Iterator<BitmapHunter> it = hunterMap.values().iterator(); it.hasNext();) { BitmapHunter hunter = it.next(); boolean loggingEnabled = hunter.getPicasso().loggingEnabled; Action single = hunter.getAction(); List<Action> joined = hunter.getActions(); boolean hasMultiple = joined != null && !joined.isEmpty(); if (single == null && !hasMultiple) { continue; } if (single != null && single.getTag().equals(tag)) { hunter.detach(single); pausedActions.put(single.getTarget(), single); if (loggingEnabled) { log(OWNER_DISPATCHER, VERB_PAUSED, single.request.logId(), "because tag '" + tag + "' was paused"); } } if (hasMultiple) { for (int i = joined.size() - 1; i >= 0; i--) { Action action = joined.get(i); if (!action.getTag().equals(tag)) { continue; } hunter.detach(action); pausedActions.put(action.getTarget(), action); if (loggingEnabled) { log(OWNER_DISPATCHER, VERB_PAUSED, action.request.logId(), "because tag '" + tag + "' was paused"); } } } if (hunter.cancel()) { it.remove(); if (loggingEnabled) { log(OWNER_DISPATCHER, VERB_CANCELED, getLogIdsForHunter(hunter), "all actions paused"); } } } } Dispatcher(Context context, ExecutorService service, Handler mainThreadHandler,
      Downloader downloader, Cache cache, Stats stats);   }