CsvInputFormat extends GenericCsvInputFormat<OUT> { @Override public String toString() { return "CSV Input (" + StringUtils.showControlCharacters(String.valueOf(getFieldDelimiter())) + ") " + getFilePath(); } protected  CsvInputFormat(Path filePath); @Override void open(FileInputSplit split); @Override OUT nextRecord(OUT record); @Override OUT readRecord(OUT reuse, byte[] bytes, int offset, int numBytes); Class<?>[] getFieldTypes(); @Override String toString(); static final String DEFAULT_LINE_DELIMITER; static final String DEFAULT_FIELD_DELIMITER; }
@Test public void testPojoTypeWithInvalidFieldMapping() throws Exception { File tempFile = File.createTempFile("CsvReaderPojoType", "tmp"); tempFile.deleteOnExit(); tempFile.setWritable(true); @SuppressWarnings("unchecked") PojoTypeInfo<PojoItem> typeInfo = (PojoTypeInfo<PojoItem>) TypeExtractor.createTypeInfo(PojoItem.class); try { new PojoCsvInputFormat<PojoItem>(new Path(tempFile.toURI().toString()), typeInfo, new String[]{"field1", "field2"}); fail("The number of POJO fields cannot be same as that of selected CSV fields"); } catch (IllegalArgumentException e) { } try { new PojoCsvInputFormat<PojoItem>(new Path(tempFile.toURI().toString()), typeInfo, new String[]{"field1", "field2", null, "field4"}); fail("Fields mapping cannot contain null."); } catch (NullPointerException e) { } try { new PojoCsvInputFormat<PojoItem>(new Path(tempFile.toURI().toString()), typeInfo, new String[]{"field1", "field2", "field3", "field5"}); fail("Invalid field name"); } catch (IllegalArgumentException e) { } }