@Test public void read_duplication_with_duplicates_on_same_file() { DuplicationLineReader reader = duplicationLineReader(duplication(1, 2, innerDuplicate(3, 4))); reader.read(line1); reader.read(line2); reader.read(line3); reader.read(line4); assertThat(line1.getDuplicationList()).containsExactly(1); assertThat(line2.getDuplicationList()).containsExactly(1); assertThat(line3.getDuplicationList()).containsExactly(2); assertThat(line4.getDuplicationList()).containsExactly(2); }
@Test public void should_be_sorted_by_line_length() { DuplicationLineReader reader = duplicationLineReader( duplication(1, 2, innerDuplicate(3, 4)), duplication(1, 1, innerDuplicate(4, 4))); reader.read(line1); reader.read(line2); reader.read(line3); reader.read(line4); assertThat(line1.getDuplicationList()).containsExactly(1, 2); assertThat(line2.getDuplicationList()).containsExactly(2); assertThat(line3.getDuplicationList()).containsExactly(3); assertThat(line4.getDuplicationList()).containsExactly(3, 4); }
@Test public void read_many_duplications() { DuplicationLineReader reader = duplicationLineReader( duplication(1, 1, innerDuplicate(2, 2)), duplication(1, 2, innerDuplicate(3, 4))); reader.read(line1); reader.read(line2); reader.read(line3); reader.read(line4); assertThat(line1.getDuplicationList()).containsExactly(1, 2); assertThat(line2.getDuplicationList()).containsExactly(2, 3); assertThat(line3.getDuplicationList()).containsExactly(4); assertThat(line4.getDuplicationList()).containsExactly(4); }
@Test public void read_duplication_with_duplicates_on_other_file() { DuplicationLineReader reader = duplicationLineReader( duplication( 1, 2, new InProjectDuplicate(fileComponent(1).build(), new TextBlock(3, 4)))); reader.read(line1); reader.read(line2); reader.read(line3); reader.read(line4); assertThat(line1.getDuplicationList()).containsExactly(1); assertThat(line2.getDuplicationList()).containsExactly(1); assertThat(line3.getDuplicationList()).isEmpty(); assertThat(line4.getDuplicationList()).isEmpty(); }
@Test public void read_nothing() { DuplicationLineReader reader = new DuplicationLineReader(Collections.<Duplication>emptySet()); reader.read(line1); assertThat(line1.getDuplicationList()).isEmpty(); }
@Test public void read_duplication_with_duplicates_on_other_file_from_other_project() { DuplicationLineReader reader = duplicationLineReader( duplication( 1, 2, new CrossProjectDuplicate( "other-component-key-from-another-project", new TextBlock(3, 4)))); reader.read(line1); reader.read(line2); reader.read(line3); reader.read(line4); assertThat(line1.getDuplicationList()).containsExactly(1); assertThat(line2.getDuplicationList()).containsExactly(1); assertThat(line3.getDuplicationList()).isEmpty(); assertThat(line4.getDuplicationList()).isEmpty(); }