@Test public void should_print_to_output_stream() throws Exception { reporter.execute("someproject", new Date(), new ArrayList<>(), result, key -> RULE_DESCRIPTION); String output = new String(stream.toByteArray()); assertThat(output).contains("{\"issues\":[]"); }
@Override public void execute(String projectName, Date date, Collection<Trackable> trackables, AnalysisResults result, Function<String, RuleDetails> ruleDescriptionProducer) { try (Writer writer = new OutputStreamWriter(stream, StandardCharsets.UTF_8)) { JsonWriter jsonWriter = new Gson().newJsonWriter(writer); jsonWriter.beginObject(); jsonWriter.name("issues"); jsonWriter.beginArray(); trackables.stream().map(Trackable::getIssue).forEach(issue -> { try { issueToJSON(issue, ruleDescriptionProducer, jsonWriter); } catch (IOException e) { LOGGER.error("Failed to convert to json " + issue.toString(), e); } }); jsonWriter.endArray(); jsonWriter.endObject(); } catch (IOException e) { LOGGER.error("Error while printing to stream", e); } }
JsonReporter implements Reporter { @Override public void execute(String projectName, Date date, Collection<Trackable> trackables, AnalysisResults result, Function<String, RuleDetails> ruleDescriptionProducer) { try (Writer writer = new OutputStreamWriter(stream, StandardCharsets.UTF_8)) { JsonWriter jsonWriter = new Gson().newJsonWriter(writer); jsonWriter.beginObject(); jsonWriter.name("issues"); jsonWriter.beginArray(); trackables.stream().map(Trackable::getIssue).forEach(issue -> { try { issueToJSON(issue, ruleDescriptionProducer, jsonWriter); } catch (IOException e) { LOGGER.error("Failed to convert to json " + issue.toString(), e); } }); jsonWriter.endArray(); jsonWriter.endObject(); } catch (IOException e) { LOGGER.error("Error while printing to stream", e); } } }
JsonReporter implements Reporter { @Override public void execute(String projectName, Date date, Collection<Trackable> trackables, AnalysisResults result, Function<String, RuleDetails> ruleDescriptionProducer) { try (Writer writer = new OutputStreamWriter(stream, StandardCharsets.UTF_8)) { JsonWriter jsonWriter = new Gson().newJsonWriter(writer); jsonWriter.beginObject(); jsonWriter.name("issues"); jsonWriter.beginArray(); trackables.stream().map(Trackable::getIssue).forEach(issue -> { try { issueToJSON(issue, ruleDescriptionProducer, jsonWriter); } catch (IOException e) { LOGGER.error("Failed to convert to json " + issue.toString(), e); } }); jsonWriter.endArray(); jsonWriter.endObject(); } catch (IOException e) { LOGGER.error("Error while printing to stream", e); } } JsonReporter(OutputStream stream); }
JsonReporter implements Reporter { @Override public void execute(String projectName, Date date, Collection<Trackable> trackables, AnalysisResults result, Function<String, RuleDetails> ruleDescriptionProducer) { try (Writer writer = new OutputStreamWriter(stream, StandardCharsets.UTF_8)) { JsonWriter jsonWriter = new Gson().newJsonWriter(writer); jsonWriter.beginObject(); jsonWriter.name("issues"); jsonWriter.beginArray(); trackables.stream().map(Trackable::getIssue).forEach(issue -> { try { issueToJSON(issue, ruleDescriptionProducer, jsonWriter); } catch (IOException e) { LOGGER.error("Failed to convert to json " + issue.toString(), e); } }); jsonWriter.endArray(); jsonWriter.endObject(); } catch (IOException e) { LOGGER.error("Error while printing to stream", e); } } JsonReporter(OutputStream stream); @Override void execute(String projectName, Date date, Collection<Trackable> trackables, AnalysisResults result, Function<String, RuleDetails> ruleDescriptionProducer); }
JsonReporter implements Reporter { @Override public void execute(String projectName, Date date, Collection<Trackable> trackables, AnalysisResults result, Function<String, RuleDetails> ruleDescriptionProducer) { try (Writer writer = new OutputStreamWriter(stream, StandardCharsets.UTF_8)) { JsonWriter jsonWriter = new Gson().newJsonWriter(writer); jsonWriter.beginObject(); jsonWriter.name("issues"); jsonWriter.beginArray(); trackables.stream().map(Trackable::getIssue).forEach(issue -> { try { issueToJSON(issue, ruleDescriptionProducer, jsonWriter); } catch (IOException e) { LOGGER.error("Failed to convert to json " + issue.toString(), e); } }); jsonWriter.endArray(); jsonWriter.endObject(); } catch (IOException e) { LOGGER.error("Error while printing to stream", e); } } JsonReporter(OutputStream stream); @Override void execute(String projectName, Date date, Collection<Trackable> trackables, AnalysisResults result, Function<String, RuleDetails> ruleDescriptionProducer);  }