### Question:
RadlValidator implements Application { void reportIssues(Map<String, Collection<Issue>> issues, IssueReporter reporter) { reporter.start(); for (Entry<String, Collection<Issue>> entry : issues.entrySet()) { reporter.file(entry.getKey()); for (Issue issue : entry.getValue()) { reporter.issue(issue); } } reporter.end(); }  static void main(String[] args); @Override int run(Arguments arguments); void validate(Arguments arguments, Map<String, Collection<Issue>> issues, File reportDir);  }### Answer:
@Test(expected = IllegalArgumentException.class) public void throwsExceptionOnError() { Map<String, Collection<Issue>> issues = new HashMap<>(); issues.put(RANDOM.string(), Arrays.asList(new Issue(Validator.class, Level.ERROR, RANDOM.integer(), RANDOM.integer(), RANDOM.string()))); radlValidator.reportIssues(issues, new PrintStreamIssueReporter(System.err)); }
@Test public void printsWarningsAndInfos() throws UnsupportedEncodingException { String fileName = RANDOM.string(8) + ".radl"; String warning = RANDOM.string(); String info = RANDOM.string(); int line1 = RANDOM.integer(); int column1 = RANDOM.integer(); int line2 = RANDOM.integer(); int column2 = RANDOM.integer(); ByteArrayOutputStream stream = new ByteArrayOutputStream(); String encoding = "UTF8"; try (PrintStream out = new PrintStream(stream, true, encoding)) { List<Issue> issuesByFile = Arrays.asList(new Issue(Validator.class, Level.WARNING, line1, column1, warning), new Issue(Validator.class, Level.INFO, line2, column2, info)); Map<String, Collection<Issue>> issues = new HashMap<>(); issues.put(fileName, issuesByFile); radlValidator.reportIssues(issues, new PrintStreamIssueReporter(out)); } assertEquals("Printed issues", String.format("File: %s; %s [%d,%d]: %s%nFile: %s; %s [%d,%d]: %s%n", fileName, Level.WARNING, line1, column1, warning, fileName, Level.INFO, line2, column2, info), new String(stream.toByteArray(), "UTF8")); }
@Test public void reportsIssues() throws Exception { String fileName = RANDOM.string(8) + ".radl"; String warning = RANDOM.string(); String info = RANDOM.string(); Issue issue2 = new Issue(Validator.class, Level.INFO, RANDOM.integer(), RANDOM.integer(), info); Issue issue1 = new Issue(Validator.class, Level.WARNING, RANDOM.integer(), RANDOM.integer(), warning); Map<String, Collection<Issue>> issues = new HashMap<>(); issues.put(fileName, Arrays.asList(issue1, issue2)); IssueReporter reporter = mock(IssueReporter.class); radlValidator.reportIssues(issues, reporter); verify(reporter).start(); verify(reporter).file(fileName); verify(reporter).issue(issue1); verify(reporter).issue(issue2); verify(reporter).end(); }