WriterRegistrationService { public TransformerWriter getWriter(String format, OutputStream output, Map<String, String> parameters) { try { final ExportFormat formatByName = formatRegistrationService.getByName(format); if (formatByName == null || !formatByName.isEnabled()) { throw new TDPException(UNABLE_TO_USE_EXPORT, ExceptionContext.build().put("format", format)); } if (parameters.isEmpty()) { return (TransformerWriter) context.getBean("writer#" + format, output); } else { return (TransformerWriter) context.getBean("writer#" + format, output, parameters); } } catch (BeansException be) { throw new TDPException(TransformationErrorCodes.OUTPUT_TYPE_NOT_SUPPORTED, be); } }  TransformerWriter getWriter(String format, OutputStream output, Map<String, String> parameters);  }
@Test public void shouldReturnSimpleWriter() { final TransformerWriter jsonWriter = service.getWriter(JsonFormat.JSON, output, Collections.emptyMap()); Assert.assertTrue(jsonWriter instanceof JsonWriter); }
@Test public void shouldReturnWriterWithParameter() { Map<String, String> parameters = new HashMap<>(); parameters.put(CSVWriterTest.SEPARATOR_PARAM_NAME, "|"); final TransformerWriter csvWriter = service.getWriter(CSVFormat.CSV, output, parameters); Assert.assertTrue(csvWriter instanceof CSVWriter); }
@Test(expected = TDPException.class) public void shouldNotReturnAnything() { service.getWriter("toto", output, Collections.emptyMap()); }