    1   /***
    2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
    3    */
    4   package test.net.sourceforge.pmd.cpd;
    5
    6   import junit.framework.TestCase;
    7   import net.sourceforge.pmd.cpd.Match;
    8   import net.sourceforge.pmd.cpd.TokenEntry;
    9
    10  import java.util.Iterator;
    11
    12  public class MatchTest extends TestCase {
    13
    14      public void testSimple() {
    15          TokenEntry mark1 = new TokenEntry("public", "/var/Foo.java", 1);
    16          TokenEntry mark2 = new TokenEntry("class", "/var/Foo.java", 1);
    17          Match match = new Match(1, mark1, mark2);
    18          match.setSourceCodeSlice("public class Foo {}");
    19          assertEquals("public class Foo {}", match.getSourceCodeSlice());
    20          match.setLineCount(10);
    21          assertEquals(10, match.getLineCount());
    22          assertEquals(1, match.getTokenCount());
    23          Iterator i = match.iterator();
    24          assertEquals(mark1, i.next());
    25          assertEquals(mark2, i.next());
    26          assertFalse(i.hasNext());
    27      }
    28
    29      public void testCompareTo() {
    30          Match m1 = new Match(1, new TokenEntry("public", "/var/Foo.java", 1), new TokenEntry("class", "/var/Foo.java", 1));
    31          Match m2 = new Match(2, new TokenEntry("Foo", "/var/Foo.java", 1), new TokenEntry("{", "/var/Foo.java", 1));
    32          assertTrue(m2.compareTo(m1) < 0);
    33      }
    34  }