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