View Javadoc
1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd.cli;
5   
6   import java.io.ByteArrayOutputStream;
7   import java.io.PrintStream;
8   
9   import org.junit.Assert;
10  import org.junit.Test;
11  
12  public class XPathCLITest {
13  
14      @Test
15      public void runXPath() throws Exception {
16          PrintStream oldOut = System.out;
17          ByteArrayOutputStream output = new ByteArrayOutputStream();
18          System.setOut(new PrintStream(output));
19  
20          try {
21              XPathCLI.main(new String[] {
22                      "-xpath",
23                      "//ClassOrInterfaceDeclaration",
24                      "-filename",
25                      "src/test/java/net/sourceforge/pmd/cli/XPathCLITest.java"
26              });
27              System.out.flush();
28          } finally {
29              System.setOut(oldOut);
30          }
31  
32          Assert.assertTrue(output.toString("UTF-8").startsWith("Match at line "));
33      }
34  }