### Question:
PmdTemplate { public void process(InputFile file, RuleSets rulesets, RuleContext ruleContext) { ruleContext.setSourceCodeFilename(file.uri().toString()); try (InputStream inputStream = file.inputStream()) { processor.processSourceCode(inputStream, rulesets, ruleContext); } catch (RuntimeException | IOException | PMDException e) { LOG.error("Fail to execute PMD. Following file is ignored: " + file, e); } } PmdTemplate(PMDConfiguration configuration, SourceCodeProcessor processor); static PmdTemplate create(String javaVersion, ClassLoader classloader, Charset charset); void process(InputFile file, RuleSets rulesets, RuleContext ruleContext);  }### Answer:
@Test void should_process_input_file() throws Exception { doAnswer((Answer<Void>) invocation -> { final InputStream inputStreamArg = (InputStream) invocation.getArguments()[0]; final List<String> inputStreamLines = new BufferedReader(new InputStreamReader(inputStreamArg)) .lines() .collect(Collectors.toList()); assertThat(inputStreamLines).containsExactly("Example source"); return null; }).when(processor).processSourceCode(any(InputStream.class), eq(rulesets), eq(ruleContext)); new PmdTemplate(configuration, processor).process(inputFile, rulesets, ruleContext); verify(ruleContext).setSourceCodeFilename(inputFile.uri().toString()); verify(processor).processSourceCode(any(InputStream.class), eq(rulesets), eq(ruleContext)); }
@Test void should_ignore_PMD_error() throws PMDException { doThrow(new PMDException("BUG")) .when(processor).processSourceCode(any(InputStream.class), any(RuleSets.class), any(RuleContext.class)); new PmdTemplate(configuration, processor).process(inputFile, rulesets, ruleContext); }