    1   package test.net.sourceforge.pmd;
    2
    3   import junit.framework.TestCase;
    4   import net.sourceforge.pmd.SourceType;
    5   import net.sourceforge.pmd.SourceTypeDiscoverer;
    6
    7   import java.io.File;
    8
    9   public class SourceTypeDiscovererTest extends TestCase {
    10
    11      /***
    12       * Test on JSP file.
    13       */
    14      public void testJspFile() {
    15          SourceTypeDiscoverer discoverer = new SourceTypeDiscoverer();
    16          File jspFile = new File("/path/to/MyPage.jsp");
    17
    18          SourceType type = discoverer.getSourceTypeOfFile(jspFile);
    19
    20          assertEquals("SourceType must be JSP!", SourceType.JSP, type);
    21      }
    22
    23      /***
    24       * Test on Java file with default options.
    25       */
    26      public void testJavaFileUsingDefaults() {
    27          SourceTypeDiscoverer discoverer = new SourceTypeDiscoverer();
    28          File javaFile = new File("/path/to/MyClass.java");
    29
    30          SourceType type = discoverer.getSourceTypeOfFile(javaFile);
    31
    32          assertEquals("SourceType must be Java 1.4!", SourceType.JAVA_14, type);
    33      }
    34
    35      /***
    36       * Test on Java file with Java version set to 1.5.
    37       */
    38      public void testJavaFileUsing15() {
    39          SourceTypeDiscoverer discoverer = new SourceTypeDiscoverer();
    40          discoverer.setSourceTypeOfJavaFiles(SourceType.JAVA_15);
    41          File javaFile = new File("/path/to/MyClass.java");
    42
    43          SourceType type = discoverer.getSourceTypeOfFile(javaFile);
    44
    45          assertEquals("SourceType must be Java 1.5!", SourceType.JAVA_15, type);
    46      }
    47  }