View Javadoc

    1   /**
    2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
    3    */
    4   package net.sourceforge.pmd.cpd;
    5
    6   import static org.junit.Assert.assertEquals;
    7   import net.sourceforge.pmd.PMD;
    8   import net.sourceforge.pmd.cpd.JavaTokenizer;
    9   import net.sourceforge.pmd.cpd.SourceCode;
    10  import net.sourceforge.pmd.cpd.Tokens;
    11
    12  import org.junit.Test;
    13
    14  public class SourceCodeTest {
    15
    16      @Test
    17      public void testSimple() throws Throwable {
    18          JavaTokenizer tokenizer = new JavaTokenizer();
    19          SourceCode sourceCode = new SourceCode(new SourceCode.StringCodeLoader(MatchAlgorithmTest.getSampleCode(), "Foo.java"));
    20          assertEquals("Foo.java", sourceCode.getFileName());
    21          tokenizer.tokenize(sourceCode, new Tokens());
    22
    23          assertEquals(MatchAlgorithmTest.LINE_1, sourceCode.getSlice(1, 1));
    24          assertEquals(MatchAlgorithmTest.LINE_2, sourceCode.getSlice(2, 2));
    25          assertEquals(MatchAlgorithmTest.LINE_1 + PMD.EOL + MatchAlgorithmTest.LINE_2, sourceCode.getSlice(1, 2));
    26      }
    27
    28      public static junit.framework.Test suite() {
    29          return new junit.framework.JUnit4TestAdapter(SourceCodeTest.class);
    30      }
    31  }