@Test public void should_process_input_file() throws Exception { doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { InputStream inputStreamArg = (InputStream) invocation.getArguments()[0]; List<String> inputStreamLines = CharStreams.readLines(new InputStreamReader(inputStreamArg)); 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.getAbsolutePath()); verify(processor).processSourceCode(any(InputStream.class), eq(rulesets), eq(ruleContext)); }
public void process(File file, RuleSets rulesets, RuleContext ruleContext) { ruleContext.setSourceCodeFilename(file.getAbsolutePath()); InputStream inputStream = null; try { inputStream = new FileInputStream(file); processor.processSourceCode(inputStream, rulesets, ruleContext); } catch (Exception e) { LOG.error("Fail to execute PMD. Following file is ignored: " + file, e); } finally { Closeables.closeQuietly(inputStream); } }
PmdTemplate { public void process(File file, RuleSets rulesets, RuleContext ruleContext) { ruleContext.setSourceCodeFilename(file.getAbsolutePath()); InputStream inputStream = null; try { inputStream = new FileInputStream(file); processor.processSourceCode(inputStream, rulesets, ruleContext); } catch (Exception e) { LOG.error("Fail to execute PMD. Following file is ignored: " + file, e); } finally { Closeables.closeQuietly(inputStream); } } }
PmdTemplate { public void process(File file, RuleSets rulesets, RuleContext ruleContext) { ruleContext.setSourceCodeFilename(file.getAbsolutePath()); InputStream inputStream = null; try { inputStream = new FileInputStream(file); processor.processSourceCode(inputStream, rulesets, ruleContext); } catch (Exception e) { LOG.error("Fail to execute PMD. Following file is ignored: " + file, e); } finally { Closeables.closeQuietly(inputStream); } } @VisibleForTesting  PmdTemplate(PMDConfiguration configuration, SourceCodeProcessor processor); }
PmdTemplate { public void process(File file, RuleSets rulesets, RuleContext ruleContext) { ruleContext.setSourceCodeFilename(file.getAbsolutePath()); InputStream inputStream = null; try { inputStream = new FileInputStream(file); processor.processSourceCode(inputStream, rulesets, ruleContext); } catch (Exception e) { LOG.error("Fail to execute PMD. Following file is ignored: " + file, e); } finally { Closeables.closeQuietly(inputStream); } } @VisibleForTesting  PmdTemplate(PMDConfiguration configuration, SourceCodeProcessor processor); static PmdTemplate create(String javaVersion, ClassLoader classloader, Charset charset); void process(File file, RuleSets rulesets, RuleContext ruleContext); }
PmdTemplate { public void process(File file, RuleSets rulesets, RuleContext ruleContext) { ruleContext.setSourceCodeFilename(file.getAbsolutePath()); InputStream inputStream = null; try { inputStream = new FileInputStream(file); processor.processSourceCode(inputStream, rulesets, ruleContext); } catch (Exception e) { LOG.error("Fail to execute PMD. Following file is ignored: " + file, e); } finally { Closeables.closeQuietly(inputStream); } } @VisibleForTesting  PmdTemplate(PMDConfiguration configuration, SourceCodeProcessor processor); static PmdTemplate create(String javaVersion, ClassLoader classloader, Charset charset); void process(File file, RuleSets rulesets, RuleContext ruleContext);  }