View Javadoc

1   package net.sourceforge.pmd;
2   
3   import static org.junit.Assert.assertEquals;
4   
5   import java.util.Arrays;
6   import java.util.Collection;
7   
8   import junit.framework.JUnit4TestAdapter;
9   import net.sourceforge.pmd.ant.SourceLanguage;
10  import net.sourceforge.pmd.lang.LanguageVersion;
11  
12  import org.junit.Test;
13  import org.junit.runner.RunWith;
14  import org.junit.runners.Parameterized;
15  import org.junit.runners.Parameterized.Parameters;
16  
17  @RunWith(Parameterized.class)
18  public class LanguageVersionTest {
19  
20      private String language;
21      private String version;
22      private String terseName;
23      private LanguageVersion expected;
24  
25      public LanguageVersionTest(String language, String version, LanguageVersion expected) {
26          this.language = language;
27          this.version = version;
28          this.terseName = language;
29          if (version != null && !version.isEmpty()) {
30              this.terseName += " " + version;
31          }
32          this.expected = expected;
33      }
34  
35      @Parameters
36      public static Collection data() {
37          return Arrays.asList(new Object[][] {
38                  { "java", "1.3", LanguageVersion.JAVA_13 },
39                  { "java", "1.4", LanguageVersion.JAVA_14 },
40                  { "java", "1.5", LanguageVersion.JAVA_15 },
41                  { "java", "1.6", LanguageVersion.JAVA_16 },
42                  { "java", "1.7", LanguageVersion.JAVA_17 },
43                  { "java", "1.8", LanguageVersion.JAVA_18 },
44                  { "jsp", "", LanguageVersion.JSP },
45                  { "xml", "", LanguageVersion.XML },
46                  { "xsl", "", LanguageVersion.XSL },
47                  { "ecmascript", "3", LanguageVersion.ECMASCRIPT },
48                  { "cpp", "", LanguageVersion.CPP },
49                  { "fortran", "", LanguageVersion.FORTRAN },
50                  { "php", "", LanguageVersion.PHP },
51                  { "ruby", "", LanguageVersion.RUBY },
52                  { "vm", "", LanguageVersion.VM },
53  
54                  // this one won't be found: case sensitive!
55                  { "JAVA", "1.7", null },
56              });
57      }
58  
59      @Test
60      public void testGetLanguageVersionForTerseName() {
61          assertEquals(expected, LanguageVersion.findByTerseName(terseName));
62      }
63  
64      @Test
65      public void testFindVersionsForLanguageTerseName() {
66          SourceLanguage sourceLanguage = new SourceLanguage();
67          sourceLanguage.setName(language);
68          sourceLanguage.setVersion(version);
69  
70          LanguageVersion languageVersion = LanguageVersion.findVersionsForLanguageTerseName(sourceLanguage.getName(),
71                  sourceLanguage.getVersion());
72  
73          assertEquals(expected, languageVersion);
74      }
75  
76      public static junit.framework.Test suite() {
77          return new JUnit4TestAdapter(LanguageVersionTest.class);
78      }
79  }