TransformerFactory { public Transformer get(Configuration configuration) { List<Transformer> electedTransformers = context .getBeansOfType(Transformer.class) .values() .stream() .filter(transformer -> transformer.accept(configuration)) .collect(Collectors.toList()); if (electedTransformers.isEmpty()) { throw new IllegalStateException("No transformers eligible for configuration."); } if (electedTransformers.size() > 1) { throw new IllegalStateException("Too many transformers eligible for configuration (got " + electedTransformers.size() + ": " + Arrays.toString(electedTransformers.toArray()) + ")"); } return electedTransformers.get(0); } private  TransformerFactory(); Transformer get(Configuration configuration);  }
@Test public void getExporter_csv_exporter_should_write_csv_format() throws Exception { Map<String, String> arguments = new HashMap<>(); arguments.put(ExportFormat.PREFIX + CSVFormat.ParametersCSV.FIELDS_DELIMITER, ";"); arguments.put(ExportFormat.PREFIX + CSVFormat.ParametersCSV.ENCLOSURE_MODE, CSVFormat.ParametersCSV.ENCLOSURE_ALL_FIELDS); final OutputStream outputStream = new ByteArrayOutputStream(); final Configuration configuration = Configuration .builder() .args(arguments) .format(CSV) .output(outputStream) .actions(IOUtils.toString(TransformerFactoryTest.class.getResourceAsStream("upper_case_firstname.json"), UTF_8)) .build(); final Transformer transformer = factory.get(configuration); final String expectedCsv = IOUtils.toString( TransformerFactoryTest.class.getResourceAsStream("expected_export_preparation_uppercase_firstname.csv"), UTF_8); final InputStream inputStream = TransformerFactoryTest.class.getResourceAsStream("../../format/export_dataset.json"); try (JsonParser parser = mapper.getFactory().createParser(inputStream)) { final DataSet dataSet = mapper.readerFor(DataSet.class).readValue(parser); transformer.buildExecutable(dataSet, configuration).execute(); assertThat(outputStream.toString()).isEqualTo(expectedCsv); } }