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