ReaderUtils { public static String getVariableName(RasterDataNode rasterDataNode) { String name = N3iosp.makeValidNetcdfObjectName(rasterDataNode.getName()); name = name.replace( '.', '_' ); if (!VariableNameHelper.isVariableNameValid(name)) { name = VariableNameHelper.convertToValidName(name); } return name; }  static ProductData createProductData(int productDataType, Array values); static boolean hasValidExtension(String pathname); static Variable[] getVariables(List<Variable> variables, String[] names); static String getRasterName(Variable variable); static String getVariableName(RasterDataNode rasterDataNode); static String getVariableName(NetcdfFile netcdfFile, RasterDataNode rasterDataNode);  }
@Test public void testGetVariableName() throws Exception { NetcdfFile netcdfFile = null; try { netcdfFile = NetcdfFileOpener.open(getClass().getResource("test_orig_name.nc").toString()); Band band = new Band("sun angle", ProductData.TYPE_INT16, 10, 10); String variableName = ReaderUtils.getVariableName(netcdfFile, band); assertEquals("sun_angle", variableName); } finally { if (netcdfFile != null) { netcdfFile.close(); } } }
@Test public void testGetVariableName_2() throws Exception { NetcdfFile netcdfFile = null; try { netcdfFile = NetcdfFileOpener.open(getClass().getResource("test_orig_name.nc").toString()); Band band = new Band("longitude", ProductData.TYPE_INT16, 10, 10); String variableName = ReaderUtils.getVariableName(netcdfFile, band); assertEquals("longitude", variableName); } finally { if (netcdfFile != null) { netcdfFile.close(); } } }
@Test(expected = IllegalStateException.class) public void testGetVariableName_exception() throws Exception { NetcdfFile netcdfFile = null; try { netcdfFile = NetcdfFileOpener.open(getClass().getResource("test_orig_name.nc").toString()); Band band = new Band("kaputtnick", ProductData.TYPE_INT16, 10, 10); ReaderUtils.getVariableName(netcdfFile, band); } finally { if (netcdfFile != null) { netcdfFile.close(); } } }