### Question:
WMSLayer extends AbstractModel implements ImageProvider<TileImageKey> { @Override public Image getImage(TileImageKey key) { if (myImageProvider == null) { throw new IllegalStateException("getImage called before image provider has been set."); } return myImageProvider.getImage(key); } WMSLayer(Builder builder); static List<Vector2d> createQuadSplitLayerCellDimensions(int numLevels, double levelZeroSizeD); static PropertyAccessor<WMSLayer, String> getKeyAccessor(); Collection<GeographicBoundingBox> generateFixedGrid(int level); Collection<GeographicBoundingBox> generateGrid(int level); WMSLayerConfig getConfiguration(); @Override Image getImage(TileImageKey key); ImageProvider<TileImageKey> getImageProvider(); int getMaximumDisplaySize(); int getMinimumDisplaySize(); Vector2d getMinimumGridSize(); TimeSpan getTimeSpan(); String getTitle(); WMSDataTypeInfo getTypeInfo(); Duration getValidDuration(); boolean isTimeless(); @Override String toString(); static final PropertyDescriptor<WMSLayer> PROPERTY_DESCRIPTOR; static final PropertyDescriptor<String> KEY_PROPERTY_DESCRIPTOR; }### Answer:
@Test public void testGetImage() throws IOException { List<Vector2d> layerCellDimensions = new ArrayList<Vector2d>(); Vector2d twentyByTwenty = new Vector2d(20., 20.); Vector2d tenByTen = new Vector2d(10., 10.); Vector2d fiveByFive = new Vector2d(5., 5.); layerCellDimensions.add(twentyByTwenty); layerCellDimensions.add(tenByTen); layerCellDimensions.add(fiveByFive); final Image expectedImage = new DDSImage(new byte[0]); GeographicBoundingBox bbox = new GeographicBoundingBox(LatLonAlt.createFromDegrees(0., 0.), LatLonAlt.createFromDegrees(1., 1.)); TimeSpan timeSpan = TimeSpan.get(100L, 200L); final TileImageKey imageKey = new TileImageKey(bbox, timeSpan); ImageProvider<TileImageKey> imageProvider = new ImageProvider<TileImageKey>() { @Override public Image getImage(TileImageKey key) { return key.equals(imageKey) ? expectedImage : null; } }; WMSLayerConfig conf = createLayerConfig(GeographicBoundingBox.WHOLE_GLOBE); WMSDataTypeInfo info = new WMSDataTypeInfo(getToolbox(), (Preferences)null, DATA_TYPE_HOST_NAME, new WMSLayerConfigurationSet(null, conf, null), conf.getLayerKey(), conf.getLayerTitle()); WMSLayer.Builder builder = new WMSLayer.Builder(info); builder.setLayerCellDimensions(layerCellDimensions); builder.setImageProvider(imageProvider); WMSLayer wmsLayer = new WMSLayer(builder); Image image = wmsLayer.getImage(imageKey); assertEquals(expectedImage, image); }
@Test(expected = IllegalStateException.class) public void testGetImageNullImageProvider() { List<Vector2d> emptyList = Collections.emptyList(); WMSLayerConfig conf = createLayerConfig(GeographicBoundingBox.WHOLE_GLOBE); WMSDataTypeInfo info = new WMSDataTypeInfo(getToolbox(), (Preferences)null, DATA_TYPE_HOST_NAME, new WMSLayerConfigurationSet(null, conf, null), conf.getLayerKey(), conf.getLayerTitle()); WMSLayer.Builder builder = new WMSLayer.Builder(info); builder.setLayerCellDimensions(emptyList); WMSLayer wmsLayer = new WMSLayer(builder); wmsLayer.getImage((TileImageKey)null); }