### Question:
RecordCountTool implements Tool { @Override public int run(InputStream stdin, PrintStream out, PrintStream err, List<String> args) throws Exception { OptionParser optionParser = new OptionParser(); OptionSet optionSet = optionParser.parse(args.toArray(new String[0])); List<String> nargs = (List<String>) optionSet.nonOptionArguments(); if (nargs.isEmpty()) { printHelp(err); err.println(); optionParser.printHelpOn(err); return 0; } long count = 0L; if (ImmutableList.of("-").equals(nargs)) { count = countRecords(stdin); } else { for (Path file : Util.getFiles(nargs)) { try (final InputStream inStream = Util.openFromFS(file)) { count += countRecords(inStream); } } } out.println(count); out.flush(); return 0; }  @Override String getName(); @Override String getShortDescription(); @Override int run(InputStream stdin, PrintStream out, PrintStream err, List<String> args);  }### Answer:
@Test(expected = FileNotFoundException.class) public void testFileDoesNotExist() throws Exception { List<String> args = Collections .singletonList(new File(temporaryFolder.getRoot(), "nonExistingFile").getAbsolutePath()); int returnCode = new RecordCountTool().run(System.in, System.out, System.err, args); assertEquals(1, returnCode); }
@Test public void testBasic() throws Exception { final List<Integer> inputSizes = IntStream.range(0, 20).boxed().collect(Collectors.toList()); for (Integer inputSize : inputSizes) { File inputFile = generateData(inputSize); List<String> args = Collections.singletonList(inputFile.getAbsolutePath()); final ByteArrayOutputStream out = new ByteArrayOutputStream(); int returnCode = new RecordCountTool().run(System.in, new PrintStream(out), System.err, args); assertEquals(0, returnCode); assertEquals(inputSize.toString() + System.lineSeparator(), out.toString()); } }
@Test public void testMultipleFiles() throws Exception { File f1 = generateData(20); File f2 = generateData(200); List<String> args = Arrays.asList(f1.getAbsolutePath(), f2.getAbsolutePath()); final ByteArrayOutputStream out = new ByteArrayOutputStream(); int returnCode = new RecordCountTool().run(System.in, new PrintStream(out), System.err, args); assertEquals(0, returnCode); assertEquals("220" + System.lineSeparator(), out.toString()); }