@Test public void shouldBeAbleToPickupOptionalFieldTypes() throws Exception { List<String> headers = new ArrayList<String>(); headers.add("optionalStringField"); headers.add("OPTIONAL INT FIELD"); headers.add("optional date field"); Optional optionalForString = mock(Optional.class); Optional optionalForInt = mock(Optional.class); Optional optionalForDate = mock(Optional.class); whenNew(Optional.class).withArguments(CsvCellProcessors.typeMappings.get("String")).thenReturn(optionalForString); whenNew(Optional.class).withArguments(CsvCellProcessors.typeMappings.get("int")).thenReturn(optionalForInt); whenNew(Optional.class).withArguments(CsvCellProcessors.typeMappings.get("Date")).thenReturn(optionalForDate); List<CellProcessor> cellProcessors = CsvCellProcessors.getProcessors(dummyImportableClass, headers); assertEquals(3, cellProcessors.size()); assertThat((Optional) cellProcessors.get(0), is(optionalForString)); assertThat((Optional) cellProcessors.get(1), is(optionalForInt)); assertThat((Optional) cellProcessors.get(2), is(optionalForDate)); }
public static List<CellProcessor> getProcessors(ModelClass modelClass, List<String> headers) { List<CellProcessor> processors = new ArrayList<>(); for (String header : headers) { org.openlmis.upload.model.Field field = modelClass.findImportFieldWithName(header); CellProcessor processor = null; if (field != null) { processor = chainTypeProcessor(field); } processors.add(processor); } return processors; }
CsvCellProcessors { public static List<CellProcessor> getProcessors(ModelClass modelClass, List<String> headers) { List<CellProcessor> processors = new ArrayList<>(); for (String header : headers) { org.openlmis.upload.model.Field field = modelClass.findImportFieldWithName(header); CellProcessor processor = null; if (field != null) { processor = chainTypeProcessor(field); } processors.add(processor); } return processors; } }
CsvCellProcessors { public static List<CellProcessor> getProcessors(ModelClass modelClass, List<String> headers) { List<CellProcessor> processors = new ArrayList<>(); for (String header : headers) { org.openlmis.upload.model.Field field = modelClass.findImportFieldWithName(header); CellProcessor processor = null; if (field != null) { processor = chainTypeProcessor(field); } processors.add(processor); } return processors; }  }
CsvCellProcessors { public static List<CellProcessor> getProcessors(ModelClass modelClass, List<String> headers) { List<CellProcessor> processors = new ArrayList<>(); for (String header : headers) { org.openlmis.upload.model.Field field = modelClass.findImportFieldWithName(header); CellProcessor processor = null; if (field != null) { processor = chainTypeProcessor(field); } processors.add(processor); } return processors; }  static List<CellProcessor> getProcessors(ModelClass modelClass, List<String> headers); }
CsvCellProcessors { public static List<CellProcessor> getProcessors(ModelClass modelClass, List<String> headers) { List<CellProcessor> processors = new ArrayList<>(); for (String header : headers) { org.openlmis.upload.model.Field field = modelClass.findImportFieldWithName(header); CellProcessor processor = null; if (field != null) { processor = chainTypeProcessor(field); } processors.add(processor); } return processors; }  static List<CellProcessor> getProcessors(ModelClass modelClass, List<String> headers); static Map<String, CellProcessor> typeMappings; }