ProductHelper { static void addVirtualBand(Product product, BandDescriptor descriptor, String bandExpression) { final VirtualBand virtualBand = new VirtualBand(descriptor.getBandName(), ProductData.TYPE_FLOAT32, product.getSceneRasterWidth(), product.getSceneRasterHeight(), bandExpression); final String validPixelExpression = createValidPixelExpression(product, bandExpression); virtualBand.setValidPixelExpression(validPixelExpression); virtualBand.setImageInfo(createImageInfo(virtualBand, descriptor)); virtualBand.setDescription(descriptor.getDescription()); virtualBand.setUnit(descriptor.getUnit()); virtualBand.setGeophysicalNoDataValue(descriptor.getFillValue()); virtualBand.setNoDataValueUsed(descriptor.hasFillValue()); product.addBand(virtualBand); } private  ProductHelper();   }
@Test public void testAddVirtualBand_bandDescriptionIsAdded() { when(bandDescriptor.getDescription()).thenReturn("the virtual description"); ProductHelper.addVirtualBand(product, bandDescriptor, "2 * source_band"); final Band band = product.getBand(VIRTUAL_BAND_NAME); assertNotNull(band); assertEquals("the virtual description", band.getDescription()); }
@Test public void testAddVirtualBand_unitIsAdded() { when(bandDescriptor.getUnit()).thenReturn("it's virtual"); ProductHelper.addVirtualBand(product, bandDescriptor, "2 * source_band"); final Band band = product.getBand(VIRTUAL_BAND_NAME); assertNotNull(band); assertEquals("it's virtual", band.getUnit()); }
@Test public void testAddVirtualBand_fillValueIsAdded() { when(bandDescriptor.getFillValue()).thenReturn(123.78); ProductHelper.addVirtualBand(product, bandDescriptor, "2 * source_band"); final Band band = product.getBand(VIRTUAL_BAND_NAME); assertNotNull(band); assertEquals(123.78, band.getGeophysicalNoDataValue(), 1e-5); }
@Test public void testAddVirtualBand_hasFillValueIsAdded() { when(bandDescriptor.hasFillValue()).thenReturn(true); ProductHelper.addVirtualBand(product, bandDescriptor, "2 * source_band"); final Band band = product.getBand(VIRTUAL_BAND_NAME); assertNotNull(band); assertTrue(band.isNoDataValueUsed()); }