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                  { "jsp", "", LanguageVersion.JSP },
    44                  { "xml", "", LanguageVersion.XML },
    45                  { "xsl", "", LanguageVersion.XSL },
    46                  { "ecmascript", "3", LanguageVersion.ECMASCRIPT },
    47                  { "cpp", "", LanguageVersion.CPP },
    48                  { "fortran", "", LanguageVersion.FORTRAN },
    49                  { "php", "", LanguageVersion.PHP },
    50                  { "ruby", "", LanguageVersion.RUBY },
    51
    52                  // this one won't be found: case sensitive!
    53                  { "JAVA", "1.7", null },
    54              });
    55      }
    56
    57      @Test
    58      public void testGetLanguageVersionForTerseName() {
    59          assertEquals(expected, LanguageVersion.findByTerseName(terseName));
    60      }
    61
    62      @Test
    63      public void testFindVersionsForLanguageTerseName() {
    64          SourceLanguage sourceLanguage = new SourceLanguage();
    65          sourceLanguage.setName(language);
    66          sourceLanguage.setVersion(version);
    67
    68          LanguageVersion languageVersion = LanguageVersion.findVersionsForLanguageTerseName(sourceLanguage.getName(),
    69                  sourceLanguage.getVersion());
    70
    71          assertEquals(expected, languageVersion);
    72      }
    73
    74      public static junit.framework.Test suite() {
    75          return new JUnit4TestAdapter(LanguageVersionTest.class);
    76      }
    77  }