AbstractFormatExporter implements FormatExporter { static void setDataType(VariableDescriptor variableDescriptor, String dataTypeName) { if (StringUtils.isBlank(dataTypeName)) { throw new IllegalStateException("datatype not set for '" + variableDescriptor.getName() + "'"); } if ("uint".equalsIgnoreCase(dataTypeName)) { variableDescriptor.setDataType(DataType.INT); variableDescriptor.setUnsigned(true); } else if ("int".equalsIgnoreCase(dataTypeName)) { variableDescriptor.setDataType(DataType.INT); } else if ("float".equalsIgnoreCase(dataTypeName)) { variableDescriptor.setDataType(DataType.FLOAT); } else if ("ubyte".equalsIgnoreCase(dataTypeName)) { variableDescriptor.setDataType(DataType.BYTE); variableDescriptor.setUnsigned(true); } else if ("ushort".equalsIgnoreCase(dataTypeName)) { variableDescriptor.setDataType(DataType.SHORT); variableDescriptor.setUnsigned(true); } else if ("short".equalsIgnoreCase(dataTypeName)) { variableDescriptor.setDataType(DataType.SHORT); } else if ("ulong".equalsIgnoreCase(dataTypeName)) { variableDescriptor.setDataType(DataType.LONG); variableDescriptor.setUnsigned(true); } else if ("double".equalsIgnoreCase(dataTypeName)) { variableDescriptor.setDataType(DataType.DOUBLE); } else { throw new IllegalArgumentException("unsupported datatype: '" + dataTypeName + "'"); } }  @Override void initialize(Product product, ExportParameter exportParameter); @Override void prepareGeographicSubset(NFileWriteable nFileWriteable, ExportParameter exportParameter); @Override void addGlobalAttributes(NFileWriteable nFileWriteable, MetadataElement metadataRoot, ExportParameter exportParameter); @Override void addVariables(NFileWriteable nFileWriteable, ExportParameter exportParameter); @Override abstract void addDimensions(NFileWriteable nFileWriteable);  }
@Test public void testSetDataType_noTypeNameSet() { final VariableDescriptor variableDescriptor = new VariableDescriptor(); try { AbstractFormatExporter.setDataType(variableDescriptor, ""); fail("IllegalStateException expected"); } catch (IllegalStateException expected) { } try { AbstractFormatExporter.setDataType(variableDescriptor, null); fail("IllegalStateException expected"); } catch (IllegalStateException expected) { } }
@Test public void testSetDataType_unsupportedType() { final VariableDescriptor variableDescriptor = new VariableDescriptor(); try { AbstractFormatExporter.setDataType(variableDescriptor, "ArrayOfWordDocuments"); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { } }
@Test public void testSetDataType_Uint() { final VariableDescriptor variableDescriptor = new VariableDescriptor(); AbstractFormatExporter.setDataType(variableDescriptor, "uint"); assertEquals(DataType.INT, variableDescriptor.getDataType()); assertTrue(variableDescriptor.isUnsigned()); }
@Test public void testSetDataType_Int() { final VariableDescriptor variableDescriptor = new VariableDescriptor(); AbstractFormatExporter.setDataType(variableDescriptor, "int"); assertEquals(DataType.INT, variableDescriptor.getDataType()); assertFalse(variableDescriptor.isUnsigned()); }
@Test public void testSetDataType_Float() { final VariableDescriptor variableDescriptor = new VariableDescriptor(); AbstractFormatExporter.setDataType(variableDescriptor, "float"); assertEquals(DataType.FLOAT, variableDescriptor.getDataType()); assertFalse(variableDescriptor.isUnsigned()); }
@Test public void testSetDataType_UByte() { final VariableDescriptor variableDescriptor = new VariableDescriptor(); AbstractFormatExporter.setDataType(variableDescriptor, "ubyte"); assertEquals(DataType.BYTE, variableDescriptor.getDataType()); assertTrue(variableDescriptor.isUnsigned()); }
@Test public void testSetDataType_UShort() { final VariableDescriptor variableDescriptor = new VariableDescriptor(); AbstractFormatExporter.setDataType(variableDescriptor, "ushort"); assertEquals(DataType.SHORT, variableDescriptor.getDataType()); assertTrue(variableDescriptor.isUnsigned()); }
@Test public void testSetDataType_Short() { final VariableDescriptor variableDescriptor = new VariableDescriptor(); AbstractFormatExporter.setDataType(variableDescriptor, "short"); assertEquals(DataType.SHORT, variableDescriptor.getDataType()); assertFalse(variableDescriptor.isUnsigned()); }
@Test public void testSetDataType_ULong() { final VariableDescriptor variableDescriptor = new VariableDescriptor(); AbstractFormatExporter.setDataType(variableDescriptor, "ulong"); assertEquals(DataType.LONG, variableDescriptor.getDataType()); assertTrue(variableDescriptor.isUnsigned()); }
@Test public void testSetDataType_Double() { final VariableDescriptor variableDescriptor = new VariableDescriptor(); AbstractFormatExporter.setDataType(variableDescriptor, "double"); assertEquals(DataType.DOUBLE, variableDescriptor.getDataType()); assertFalse(variableDescriptor.isUnsigned()); }