diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-12-21 13:54:14 +0100 |
---|---|---|
committer | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-12-21 14:37:03 +0100 |
commit | d1e303f8412f61f426a6c746cc2ac10b584940bd (patch) | |
tree | b68693cc8caced2aeee5b06a3590b3e1392e8011 /sonar-duplications/src/test/java/org/sonar | |
parent | 6fe8b0cd64c4b4e2386d994016b465b0386ed09c (diff) | |
download | sonarqube-d1e303f8412f61f426a6c746cc2ac10b584940bd.tar.gz sonarqube-d1e303f8412f61f426a6c746cc2ac10b584940bd.zip |
SONAR-2867 Standard copy-paste detection should happen within a project, not only within a module
Diffstat (limited to 'sonar-duplications/src/test/java/org/sonar')
-rw-r--r-- | sonar-duplications/src/test/java/org/sonar/duplications/index/PackedMemoryCloneIndexTest.java | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/index/PackedMemoryCloneIndexTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/index/PackedMemoryCloneIndexTest.java index cb91fe37b6f..0812e1eb767 100644 --- a/sonar-duplications/src/test/java/org/sonar/duplications/index/PackedMemoryCloneIndexTest.java +++ b/sonar-duplications/src/test/java/org/sonar/duplications/index/PackedMemoryCloneIndexTest.java @@ -23,9 +23,13 @@ import org.junit.Before; import org.junit.Test; import org.sonar.duplications.block.Block; import org.sonar.duplications.block.ByteArray; +import org.sonar.duplications.index.PackedMemoryCloneIndex.ResourceBlocks; +import java.util.ArrayList; import java.util.Collection; +import java.util.Iterator; +import static org.assertj.core.api.Assertions.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.sameInstance; import static org.junit.Assert.assertThat; @@ -76,6 +80,34 @@ public class PackedMemoryCloneIndexTest { assertThat(block.getBlockHash(), sameInstance(requestedHash)); } } + + @Test + public void iterate() { + index.insert(newBlock("a", 1)); + index.insert(newBlock("c", 1)); + index.insert(newBlock("b", 1)); + index.insert(newBlock("c", 2)); + index.insert(newBlock("a", 2)); + + Iterator<ResourceBlocks> it = index.iterator(); + + ArrayList<ResourceBlocks> resourcesBlocks = new ArrayList<>(); + + while(it.hasNext()) { + resourcesBlocks.add(it.next()); + } + + assertThat(resourcesBlocks).hasSize(3); + + assertThat(resourcesBlocks.get(0).resourceId()).isEqualTo("a"); + assertThat(resourcesBlocks.get(1).resourceId()).isEqualTo("b"); + assertThat(resourcesBlocks.get(2).resourceId()).isEqualTo("c"); + + assertThat(resourcesBlocks.get(0).blocks()).hasSize(2); + assertThat(resourcesBlocks.get(1).blocks()).hasSize(1); + assertThat(resourcesBlocks.get(2).blocks()).hasSize(2); + + } /** * Given: index with initial capacity 1. |