TaskScanner { public Report scan(final Path file, final Charset charset) { try (Stream<String> lines = Files.lines(file, charset)) { return scanTasks(lines.iterator(), new IssueBuilder().setFileName(file.toString())); } catch (IOException | UncheckedIOException exception) { Report report = new Report(); Throwable cause = exception.getCause(); if (cause instanceof MalformedInputException || cause instanceof UnmappableCharacterException) { report.logError("Can't read source file '%s', defined encoding '%s' seems to be wrong", file, charset); } else { report.logException(exception, "Exception while reading the source code file '%s':", file); } return report; } } TaskScanner(final @CheckForNull String highTags, final @CheckForNull String normalTags,
            final @CheckForNull String lowTags,
            final CaseMode caseMode, final MatcherMode matcherMode); String getErrors(); Report scan(final Path file, final Charset charset);  }
@Test void shouldReportFileExceptionError() { TaskScanner scanner = new TaskScannerBuilder().build(); Report report = scanner.scan(new File("").toPath(), StandardCharsets.UTF_8); assertThat(report.getErrorMessages()).contains("Exception while reading the source code file '':"); }
@Test void shouldHandleMalformedInputException() { TaskScanner scanner = new TaskScannerBuilder().build(); Path pathToFile = getResourceAsFile("file-with-strange-characters.txt"); Report report = scanner.scan(pathToFile, StandardCharsets.UTF_8); assertThat(report.getErrorMessages()).isNotEmpty().contains("Can't read source file '" + pathToFile.toString() + "', defined encoding 'UTF-8' seems to be wrong"); }