package org.osmdroid.tileprovider.cachemanager;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.osmdroid.util.BoundingBox;
import org.robolectric.RobolectricTestRunner;

import java.util.Collection;
import java.util.Iterator;

@RunWith(RobolectricTestRunner.class)
public class CacheManagerTest {
    /**
     * Make sure {@link org.osmdroid.tileprovider.cachemanager.CacheManager#getTilesCoverageIterable(BoundingBox, int, int)} returns the
     * same size and elements as the {@link org.osmdroid.tileprovider.cachemanager.CacheManager#getTilesCoverage(BoundingBox, int, int)}
     * for a big mapTileUpperBound
     */
    @Test
    public void testGetTilesIterableForBigMapTileUpperBound() {
        verifyGetTilesIterable(15, 15);
    }

    /**
     * Make sure {@link org.osmdroid.tileprovider.cachemanager.CacheManager#getTilesCoverageIterable(BoundingBox, int, int)} returns the
     * same size and elements as the {@link org.osmdroid.tileprovider.cachemanager.CacheManager#getTilesCoverage(BoundingBox, int, int)}
     * for a small mapTileUpperBound
     */
    @Test
    public void testGetTilesIterableForSmallMapTileUpperBound() {
        verifyGetTilesIterable(2, 2);
    }

    /**
     * Make sure {@link org.osmdroid.tileprovider.cachemanager.CacheManager#getTilesCoverageIterable(BoundingBox, int, int)} returns the
     * same size and elements as the {@link org.osmdroid.tileprovider.cachemanager.CacheManager#getTilesCoverage(BoundingBox, int, int)}
     * for the range of zoom levels.
     */
    @Test
    public void testGetTilesIterableForRangeOfZooms() {
        verifyGetTilesIterable(3, 6);
    }

    private void verifyGetTilesIterable(int minZoom, int maxZoom) {
        BoundingBox boundingBox = new BoundingBox(52.95131467958858, 13.6473953271975,
                52.886830733534954, 13.3473953271975);
        //extract the collection using the current way
        Collection<Long> allPointsCollection = org.osmdroid.tileprovider.cachemanager.CacheManager.getTilesCoverage(boundingBox, minZoom,
                maxZoom);
        Iterator<Long> allPointsIterator = allPointsCollection.iterator();

        //retrieve an iterator for returning points in the "lazy" way
        org.osmdroid.tileprovider.cachemanager.CacheManager.IterableWithSize iterableWithSize = org.osmdroid.tileprovider.cachemanager.CacheManager.getTilesCoverageIterable(boundingBox,
                minZoom, maxZoom);

        //confirm both iterables contain the same number of elements
        Assert.assertEquals(allPointsCollection.size(), iterableWithSize.size());
        //confirm both iterables return the same elements
        for (Long value : org.osmdroid.tileprovider.cachemanager.CacheManager.getTilesCoverageIterable(boundingBox, minZoom, maxZoom)) {
            Assert.assertEquals(allPointsIterator.next(), value);
        }
    }
}

@@ -206,16 +206,58 @@
 tRunner;
+%0Aimport org.robolectric.annotation.Config;
 %0A%0Aimport
@@ -345,16 +345,48 @@
 .class)%0A
+@Config(manifest = Config.NONE)%0A
 public c
@@ -2057,47 +2057,8 @@
 n = 
-org.osmdroid.tileprovider.cachemanager.
 Cach
@@ -2289,47 +2289,8 @@
     
-org.osmdroid.tileprovider.cachemanager.
 Cach
@@ -2338,47 +2338,8 @@
 e = 
-org.osmdroid.tileprovider.cachemanager.
 Cach

Add Config.NONE to CacheManagerTest