View Javadoc

1   package net.sourceforge.pmd;
2   
3   import static org.junit.Assert.assertEquals;
4   
5   import java.io.File;
6   
7   import net.sourceforge.pmd.lang.Language;
8   import net.sourceforge.pmd.lang.LanguageFilenameFilter;
9   
10  import org.junit.Test;
11  
12  /**
13   * Tests on FileSelector.
14   *
15   * @author pieter_van_raemdonck - Application Engineers NV/SA - www.ae.be
16   */
17  public class FileSelectorTest {
18  
19      /**
20       * Test wanted selection of a source file.
21       */
22      @Test
23      public void testWantedFile() {
24          LanguageFilenameFilter fileSelector = new LanguageFilenameFilter(Language.JAVA);
25  
26          File javaFile = new File("/path/to/myFile.java");
27  
28          boolean selected = fileSelector.accept(javaFile.getParentFile(), javaFile.getName());
29          assertEquals("This file should be selected !",true, selected);
30      }
31  
32      
33      /**
34       * Test unwanted selection of a non source file.
35       */
36      @Test
37      public void testUnwantedFile() {
38          LanguageFilenameFilter fileSelector = new LanguageFilenameFilter(Language.JAVA);
39  
40          File javaFile = new File("/path/to/myFile.txt");
41  
42          boolean selected = fileSelector.accept(javaFile.getParentFile(), javaFile.getName());
43          assertEquals("Not-source file must not be selected!", false, selected);
44      }
45  
46      /**
47       * Test unwanted selection of a java file.
48       */
49      @Test
50      public void testUnwantedJavaFile() {
51          LanguageFilenameFilter fileSelector = new LanguageFilenameFilter(Language.XML);
52  
53          File javaFile = new File("/path/to/MyClass.java");
54  
55          boolean selected = fileSelector.accept(javaFile.getParentFile(), javaFile.getName());
56          assertEquals("Unwanted java file must not be selected!", false, selected);
57      }
58  
59      public static junit.framework.Test suite() {
60          return new junit.framework.JUnit4TestAdapter(FileSelectorTest.class);
61      }
62  }