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 static org.junit.Assert.assertFalse;
    8   import static org.junit.Assert.assertTrue;
    9   import net.sourceforge.pmd.cpd.Match;
    10  import net.sourceforge.pmd.cpd.TokenEntry;
    11
    12  import org.junit.Test;
    13
    14  import java.util.Iterator;
    15
    16  public class MatchTest {
    17
    18      @Test
    19      public void testSimple() {
    20          TokenEntry mark1 = new TokenEntry("public", "/var/Foo.java", 1);
    21          TokenEntry mark2 = new TokenEntry("class", "/var/Foo.java", 1);
    22          Match match = new Match(1, mark1, mark2);
    23          match.setSourceCodeSlice("public class Foo {}");
    24          assertEquals("public class Foo {}", match.getSourceCodeSlice());
    25          match.setLineCount(10);
    26          assertEquals(10, match.getLineCount());
    27          assertEquals(1, match.getTokenCount());
    28          Iterator i = match.iterator();
    29          assertEquals(mark1, i.next());
    30          assertEquals(mark2, i.next());
    31          assertFalse(i.hasNext());
    32      }
    33
    34      @Test
    35      public void testCompareTo() {
    36          Match m1 = new Match(1, new TokenEntry("public", "/var/Foo.java", 1), new TokenEntry("class", "/var/Foo.java", 1));
    37          Match m2 = new Match(2, new TokenEntry("Foo", "/var/Foo.java", 1), new TokenEntry("{", "/var/Foo.java", 1));
    38          assertTrue(m2.compareTo(m1) < 0);
    39      }
    40
    41      public static junit.framework.Test suite() {
    42          return new junit.framework.JUnit4TestAdapter(MatchTest.class);
    43      }
    44  }