NoxItemCatalog extends Observable { void load(int position, boolean useCircularTransformation) { if (isDownloading(position)) { return; } NoxItem noxItem = noxItems.get(position); if ((noxItem.hasUrl() && !isBitmapReady(position)) || noxItem.hasResourceId() && !isDrawableReady(position)) { loading[position] = true; loadNoxItem(position, noxItem, useCircularTransformation); } } NoxItemCatalog(List<NoxItem> noxItems, int noxItemSize, ImageLoader imageLoader); void recreate();  }
@Test public void shouldNotLoadNoxItemIfBitmapIsReady() { NoxItemCatalog noxItemCatalog = givenOneNoxItemCatalog(); noxItemCatalog.load(0, USE_CIRCULAR_TRANSFORMATION); noxItemCatalog.load(0, USE_CIRCULAR_TRANSFORMATION); verify(imageLoader).load(ANY_URL); }
@Test public void shouldNotLoadNoxItemIfBitmapIsBeingLoaded() { ImageLoader imageLoader = new FakeImageLoader(true); imageLoader = spy(imageLoader); NoxItemCatalog noxItemCatalog = givenOneNoxItemCatalog(imageLoader); noxItemCatalog.load(0, USE_CIRCULAR_TRANSFORMATION); noxItemCatalog.load(0, USE_CIRCULAR_TRANSFORMATION); verify(imageLoader).load(ANY_URL); }
@Test public void shouldRetryLoadIfLoadFailedBefore() { FakeImageLoader imageLoader = new FakeImageLoader(true); imageLoader = spy(imageLoader); NoxItemCatalog noxItemCatalog = givenOneNoxItemCatalog(imageLoader); noxItemCatalog.load(0, USE_CIRCULAR_TRANSFORMATION); imageLoader.forceError(); noxItemCatalog.load(0, USE_CIRCULAR_TRANSFORMATION); verify(imageLoader, times(2)).load(ANY_URL); }
@Test public void shouldUseCircularTransformationToLoadNoxItemImages() { NoxItemCatalog noxItemCatalog = givenOneNoxItemCatalog(); noxItemCatalog.load(0, USE_CIRCULAR_TRANSFORMATION); verify(imageLoader).useCircularTransformation(USE_CIRCULAR_TRANSFORMATION); }
@Test public void shouldNotifyObserversWhenAnImageAndPlaceholderAreLoadedIndicatingNoxItemPosition() { NoxItemCatalog noxItemCatalog = givenOneNoxItemCatalog(); noxItemCatalog.addObserver(observer); noxItemCatalog.load(0, USE_CIRCULAR_TRANSFORMATION); verify(observer, times(2)).update(noxItemCatalog, 0); }
@Test public void shouldNotifyObserversWhenNoxItemsAreLoadedIndicatingNoxItemPositionWithSomeElements() { List<NoxItem> noxItems = new LinkedList<NoxItem>(); noxItems.add(new NoxItem(ANY_URL)); noxItems.add(new NoxItem(ANY_URL_2)); NoxItemCatalog noxItemCatalog = givenOneNoxItemCatalog(noxItems); noxItemCatalog.addObserver(observer); noxItemCatalog.load(0, USE_CIRCULAR_TRANSFORMATION); noxItemCatalog.load(1, USE_CIRCULAR_TRANSFORMATION); verify(observer, times(2)).update(noxItemCatalog, 0); verify(observer, times(2)).update(noxItemCatalog, 1); }
@Test public void shouldLoadImagesForEveryNoxItemUsingNoxItemUrl() { List<NoxItem> noxItems = new LinkedList<NoxItem>(); noxItems.add(new NoxItem(ANY_URL)); noxItems.add(new NoxItem(ANY_URL_2)); NoxItemCatalog noxItemCatalog = givenOneNoxItemCatalog(noxItems); noxItemCatalog.load(0, USE_CIRCULAR_TRANSFORMATION); noxItemCatalog.load(1, USE_CIRCULAR_TRANSFORMATION); verify(imageLoader).load(ANY_URL); verify(imageLoader).load(ANY_URL_2); }