    1   package test.net.sourceforge.pmd.jsp.rules;
    2
    3   import net.sourceforge.pmd.Rule;
    4   import net.sourceforge.pmd.SourceType;
    5   import net.sourceforge.pmd.jsp.rules.DuplicateJspImports;
    6
    7   import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
    8   import test.net.sourceforge.pmd.testframework.TestDescriptor;
    9
    10  public class DuplicateJspImportTest extends SimpleAggregatorTst {
    11
    12      public void testAll() {
    13
    14          Rule rule = new DuplicateJspImports();
    15          rule.setMessage("");
    16          runTests(new TestDescriptor[]{
    17                  new TestDescriptor(TEST1_OK, "Just 1 import", 0, rule),
    18                  new TestDescriptor(TEST2_FAIL, "Duplicate imports", 1, rule),
    19                  new TestDescriptor(TEST3_FAIL, "Duplicate imports", 1, rule),
    20                  new TestDescriptor(TEST4_FAIL, "Duplicate imports", 1, rule),
    21                  new TestDescriptor(TEST5_FAIL, "Duplicate imports", 2, rule),
    22                  new TestDescriptor(TEST6_OK, "Just 1 import", 0, rule),
    23          }, SourceType.JSP);
    24      }
    25
    26      private static final String TEST1_OK =
    27          "<%@ page import=\"com.foo.MyClass\"%><html><body><b><img src=\"<%=Some.get()%>/foo\">xx</img>text</b></body></html>";
    28      private static final String TEST2_FAIL =
    29          "<%@ page import=\"com.foo.MyClass,com.foo.MyClass\"%><html><body><b><img src=\"<%=Some.get()%>/foo\">xx</img>text</b></body></html>";
    30      private static final String TEST3_FAIL =
    31          "<%@ page import=\"com.foo.MyClass\"%><%@ page import=\"com.foo.MyClass\"%><html><body><b><img src=\"<%=Some.get()%>/foo\">xx</img>text</b></body></html>";
    32      private static final String TEST4_FAIL =
    33          "<%@ page import=\"com.foo.MyClass,com.foo.AClass\"%><%@ page import=\"com.foo.MyClass\"%><html><body><b><img src=\"<%=Some.get()%>/foo\">xx</img>text</b></body></html>";
    34      private static final String TEST5_FAIL =
    35          "<%@ page import=\"com.foo.MyClass,com.foo.MyClass\"%><%@ page import=\"com.foo.MyClass\"%><html><body><b><img src=\"<%=Some.get()%>/foo\">xx</img>text</b></body></html>";
    36      private static final String TEST6_OK =
    37          "<%@ page import=\"com.foo.AClass\"%><%@ page import=\"com.foo.MyClass\"%><html><body><b><img src=\"<%=Some.get()%>/foo\">xx</img>text</b></body></html>";
    38  }