01: package test.net.sourceforge.pmd;
02:
03: import static org.junit.Assert.assertEquals;
04: import net.sourceforge.pmd.SourceFileSelector;
05:
06: import org.junit.Test;
07:
08: import java.io.File;
09:
10: /**
11: * Tests on FileSelector.
12: *
13: * @author pieter_van_raemdonck - Application Engineers NV/SA - www.ae.be
14: */
15: public class FileSelectorTest {
16:
17: /**
18: * Test default selection of .java files.
19: */
20: @Test
21: public void testSelectJavaFile() {
22: SourceFileSelector fileSelector = new SourceFileSelector();
23:
24: File javaFile = new File("/path/to/MyClass.java");
25:
26: boolean selected = fileSelector.isWantedFile(javaFile);
27: assertEquals("Java file must be selected!", true, selected);
28: }
29:
30: /**
31: * Test wanted selection of .jsp files.
32: */
33: @Test
34: public void testSelectJspFile() {
35: SourceFileSelector fileSelector = new SourceFileSelector();
36: fileSelector.setSelectJspFiles(true);
37:
38: File javaFile = new File("/path/to/MyPage.jsp");
39:
40: boolean selected = fileSelector.isWantedFile(javaFile);
41: assertEquals("Jsp file must be selected!", true, selected);
42: }
43:
44: /**
45: * Test unwanted selection of a non source file.
46: */
47: @Test
48: public void testUnwantedFile() {
49: SourceFileSelector fileSelector = new SourceFileSelector();
50:
51: File javaFile = new File("/path/to/myFile.txt");
52:
53: boolean selected = fileSelector.isWantedFile(javaFile);
54: assertEquals("Not-source file must not be selected!", false,
55: selected);
56: }
57:
58: /**
59: * Test unwanted selection of a java file.
60: */
61: @Test
62: public void testUnwantedJavaFile() {
63: SourceFileSelector fileSelector = new SourceFileSelector();
64: fileSelector.setSelectJavaFiles(false);
65:
66: File javaFile = new File("/path/to/MyClass.java");
67:
68: boolean selected = fileSelector.isWantedFile(javaFile);
69: assertEquals("Unwanted java file must not be selected!", false,
70: selected);
71: }
72:
73: public static junit.framework.Test suite() {
74: return new junit.framework.JUnit4TestAdapter(
75: FileSelectorTest.class);
76: }
77: }
|