AssetTileProvider extends MapTileFileStorageProviderBase { @Override public final void setTileSource(final ITileSource tileSource) { if (tileSource instanceof NicTileSource) { this.tileSource = (NicTileSource) tileSource; } else { throw new IllegalArgumentException("TileSource " + tileSource + " is not supported!"); } } AssetTileProvider(final IRegisterReceiver registerReceiver, final NicTileSource tileSource,
                             AssetManager assetManager); @Override int getMaximumZoomLevel(); @Override int getMinimumZoomLevel(); @Override boolean getUsesDataConnection(); @Override final void setTileSource(final ITileSource tileSource);  }
@Test(expected = IllegalArgumentException.class) public void testSetWrongTileSource() { IRegisterReceiver registerReceiver = mock(IRegisterReceiver.class); NicTileSource goodTileSource = mock(NicTileSource.class); ITileSource badTileSource = mock(ITileSource.class); AssetTileProvider atp = new AssetTileProvider(registerReceiver, goodTileSource, null); atp.setTileSource(badTileSource); }
@Test public void testSetNullTileSource() { NicTileSource tileSource = mock(NicTileSource.class); IRegisterReceiver registerReceiver = mock(IRegisterReceiver.class); AssetTileProvider atp = new AssetTileProvider(registerReceiver, tileSource, null); try { atp.setTileSource(null); fail("tileSource == null should throw an exception. We don't want NPE later on."); } catch (IllegalArgumentException ex) { } }
@Test public void testSetTileSource() { NicTileSource oldTileSource = mock(NicTileSource.class); when(oldTileSource.getMaximumZoomLevel()).thenReturn(7); NicTileSource newTileSource = mock(NicTileSource.class); when(newTileSource.getMaximumZoomLevel()).thenReturn(42); IRegisterReceiver registerReceiver = mock(IRegisterReceiver.class); AssetTileProvider atp = new AssetTileProvider(registerReceiver, oldTileSource, null); assertEquals(atp.getMaximumZoomLevel(), 7); atp.setTileSource(newTileSource); assertEquals(atp.getMaximumZoomLevel(), 42); }