aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-duplications
diff options
context:
space:
mode:
authorDavid Gageot <david@gageot.net>2012-05-23 08:19:35 +0200
committerDavid Gageot <david@gageot.net>2012-05-23 08:19:35 +0200
commitd7d95106d0e46906477da9c7f93be156823d7bce (patch)
treec127910d4f0ded6168c0bbfefdfc59b05593997a /sonar-duplications
parent67b5de980cb96e1a500f87db8997fee49ba1556d (diff)
downloadsonarqube-d7d95106d0e46906477da9c7f93be156823d7bce.tar.gz
sonarqube-d7d95106d0e46906477da9c7f93be156823d7bce.zip
Remove warnings
Diffstat (limited to 'sonar-duplications')
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/detector/DetectorTestCase.java41
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/detector/original/OriginalCloneDetectionAlgorithmTest.java5
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/detector/suffixtree/SuffixTreeCloneDetectionAlgorithmTest.java36
3 files changed, 40 insertions, 42 deletions
diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/detector/DetectorTestCase.java b/sonar-duplications/src/test/java/org/sonar/duplications/detector/DetectorTestCase.java
index 7a216b12c95..d973c0207d6 100644
--- a/sonar-duplications/src/test/java/org/sonar/duplications/detector/DetectorTestCase.java
+++ b/sonar-duplications/src/test/java/org/sonar/duplications/detector/DetectorTestCase.java
@@ -62,7 +62,7 @@ public abstract class DetectorTestCase {
return new ClonePart(resourceId, unitStart, unitStart, unitStart + cloneUnitLength + LINES_PER_BLOCK - 1);
}
- protected abstract List<CloneGroup> detect(CloneIndex index, List<Block> fileBlocks);
+ protected abstract List<CloneGroup> detect(CloneIndex index, Block[] fileBlocks);
/**
* Given:
@@ -82,7 +82,7 @@ public abstract class DetectorTestCase {
CloneIndex index = createIndex(
newBlocks("y", "2 3 4 5"),
newBlocks("z", "3 4"));
- List<Block> fileBlocks = newBlocks("x", "1 2 3 4 5 6");
+ Block[] fileBlocks = newBlocks("x", "1 2 3 4 5 6");
List<CloneGroup> result = detect(index, fileBlocks);
print(result);
@@ -116,7 +116,7 @@ public abstract class DetectorTestCase {
CloneIndex cloneIndex = createIndex(
newBlocks("a", "2 3 4 5"),
newBlocks("b", "3 4"));
- List<Block> fileBlocks = newBlocks("c", "1 2 3 4 5 6");
+ Block[] fileBlocks = newBlocks("c", "1 2 3 4 5 6");
List<CloneGroup> clones = detect(cloneIndex, fileBlocks);
print(clones);
@@ -151,7 +151,7 @@ public abstract class DetectorTestCase {
CloneIndex index = createIndex(
newBlocks("b", "3 4 5 6"),
newBlocks("c", "5 6 7"));
- List<Block> fileBlocks = newBlocks("a", "1 2 3 4 5 6 7 8 9");
+ Block[] fileBlocks = newBlocks("a", "1 2 3 4 5 6 7 8 9");
List<CloneGroup> result = detect(index, fileBlocks);
print(result);
@@ -188,7 +188,7 @@ public abstract class DetectorTestCase {
CloneIndex index = createIndex(
newBlocks("b", "1 2 3 4 1 2 3 4 1 2 3 4"),
newBlocks("c", "1 2 3 4"));
- List<Block> fileBlocks = newBlocks("a", "1 2 3 5");
+ Block[] fileBlocks = newBlocks("a", "1 2 3 5");
List<CloneGroup> result = detect(index, fileBlocks);
print(result);
@@ -216,7 +216,7 @@ public abstract class DetectorTestCase {
@Test
public void clonesInFileItself() {
CloneIndex index = createIndex();
- List<Block> fileBlocks = newBlocks("a", "1 2 3 1 2 4");
+ Block[] fileBlocks = newBlocks("a", "1 2 3 1 2 4");
List<CloneGroup> result = detect(index, fileBlocks);
print(result);
@@ -244,7 +244,7 @@ public abstract class DetectorTestCase {
public void covered() {
CloneIndex index = createIndex(
newBlocks("b", "1 2 1 2"));
- List<Block> fileBlocks = newBlocks("a", "1 2 1");
+ Block[] fileBlocks = newBlocks("a", "1 2 1");
List<CloneGroup> result = detect(index, fileBlocks);
print(result);
@@ -276,7 +276,7 @@ public abstract class DetectorTestCase {
public void problemWithNestedCloneGroups() {
CloneIndex index = createIndex(
newBlocks("b", "1 2 1 2 1 2 1"));
- List<Block> fileBlocks = newBlocks("a", "1 2 1 2 1 2");
+ Block[] fileBlocks = newBlocks("a", "1 2 1 2 1 2");
List<CloneGroup> result = detect(index, fileBlocks);
print(result);
@@ -310,7 +310,7 @@ public abstract class DetectorTestCase {
newBlocks("a", "1 2 3"),
newBlocks("b", "1 2 4"));
// Note about blocks with hashes "3", "4" and "5": those blocks here in order to not face another problem - with EOF (see separate test)
- List<Block> fileBlocks = newBlocks("a", "1 2 5");
+ Block[] fileBlocks = newBlocks("a", "1 2 5");
List<CloneGroup> result = detect(index, fileBlocks);
print(result);
@@ -328,7 +328,7 @@ public abstract class DetectorTestCase {
@Test
public void only_one_query_of_index_for_each_unique_hash() {
CloneIndex index = spy(createIndex());
- List<Block> fileBlocks = newBlocks("a", "1 2 1 2");
+ Block[] fileBlocks = newBlocks("a", "1 2 1 2");
detect(index, fileBlocks);
verify(index).getBySequenceHash(new ByteArray("01"));
@@ -342,7 +342,7 @@ public abstract class DetectorTestCase {
*/
@Test
public void shouldReturnEmptyListWhenNoBlocksForFile() {
- List<CloneGroup> result = detect(null, new ArrayList<Block>());
+ List<CloneGroup> result = detect(null, new Block[0]);
assertThat(result, sameInstance(Collections.EMPTY_LIST));
}
@@ -361,7 +361,7 @@ public abstract class DetectorTestCase {
public void problemWithEndOfFile() {
CloneIndex cloneIndex = createIndex(
newBlocks("b", "1 2 3 4"));
- List<Block> fileBlocks =
+ Block[] fileBlocks =
newBlocks("a", "1 2 3");
List<CloneGroup> clones = detect(cloneIndex, fileBlocks);
@@ -393,10 +393,11 @@ public abstract class DetectorTestCase {
Block.Builder block = Block.builder()
.setResourceId("a")
.setLines(0, 1);
- List<Block> fileBlocks = Arrays.asList(
- block.setBlockHash(new ByteArray("1".getBytes())).setIndexInFile(0).build(),
- block.setBlockHash(new ByteArray("2".getBytes())).setIndexInFile(1).build(),
- block.setBlockHash(new ByteArray("1".getBytes())).setIndexInFile(2).build());
+ Block[] fileBlocks = new Block[] {
+ block.setBlockHash(new ByteArray("1".getBytes())).setIndexInFile(0).build(),
+ block.setBlockHash(new ByteArray("2".getBytes())).setIndexInFile(1).build(),
+ block.setBlockHash(new ByteArray("1".getBytes())).setIndexInFile(2).build()
+ };
List<CloneGroup> clones = detect(cloneIndex, fileBlocks);
print(clones);
@@ -418,7 +419,7 @@ public abstract class DetectorTestCase {
System.out.println();
}
- protected static List<Block> newBlocks(String resourceId, String hashes) {
+ protected static Block[] newBlocks(String resourceId, String hashes) {
List<Block> result = Lists.newArrayList();
int indexInFile = 0;
for (int i = 0; i < hashes.length(); i += 2) {
@@ -426,12 +427,12 @@ public abstract class DetectorTestCase {
result.add(block);
indexInFile++;
}
- return result;
+ return result.toArray(new Block[result.size()]);
}
- protected static CloneIndex createIndex(List<Block>... blocks) {
+ protected static CloneIndex createIndex(Block[]... blocks) {
CloneIndex cloneIndex = new MemoryCloneIndex();
- for (List<Block> b : blocks) {
+ for (Block[] b : blocks) {
for (Block block : b) {
cloneIndex.insert(block);
}
diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/detector/original/OriginalCloneDetectionAlgorithmTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/detector/original/OriginalCloneDetectionAlgorithmTest.java
index 957a89de13a..78369d4d300 100644
--- a/sonar-duplications/src/test/java/org/sonar/duplications/detector/original/OriginalCloneDetectionAlgorithmTest.java
+++ b/sonar-duplications/src/test/java/org/sonar/duplications/detector/original/OriginalCloneDetectionAlgorithmTest.java
@@ -19,6 +19,7 @@
*/
package org.sonar.duplications.detector.original;
+import java.util.Arrays;
import java.util.List;
import org.sonar.duplications.block.Block;
@@ -29,8 +30,8 @@ import org.sonar.duplications.index.CloneIndex;
public class OriginalCloneDetectionAlgorithmTest extends DetectorTestCase {
@Override
- protected List<CloneGroup> detect(CloneIndex index, List<Block> fileBlocks) {
- return OriginalCloneDetectionAlgorithm.detect(index, fileBlocks);
+ protected List<CloneGroup> detect(CloneIndex index, Block[] fileBlocks) {
+ return OriginalCloneDetectionAlgorithm.detect(index, Arrays.asList(fileBlocks));
}
}
diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/detector/suffixtree/SuffixTreeCloneDetectionAlgorithmTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/detector/suffixtree/SuffixTreeCloneDetectionAlgorithmTest.java
index 996c22a96c7..dc1caa9db6a 100644
--- a/sonar-duplications/src/test/java/org/sonar/duplications/detector/suffixtree/SuffixTreeCloneDetectionAlgorithmTest.java
+++ b/sonar-duplications/src/test/java/org/sonar/duplications/detector/suffixtree/SuffixTreeCloneDetectionAlgorithmTest.java
@@ -19,14 +19,6 @@
*/
package org.sonar.duplications.detector.suffixtree;
-import static org.hamcrest.Matchers.sameInstance;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-import static org.sonar.duplications.detector.CloneGroupMatcher.hasCloneGroup;
-
-import java.util.Collections;
-import java.util.List;
-
import org.junit.Test;
import org.sonar.duplications.block.Block;
import org.sonar.duplications.block.ByteArray;
@@ -34,7 +26,14 @@ import org.sonar.duplications.detector.DetectorTestCase;
import org.sonar.duplications.index.CloneGroup;
import org.sonar.duplications.index.CloneIndex;
-import com.google.common.collect.Lists;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.hamcrest.Matchers.sameInstance;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.sonar.duplications.detector.CloneGroupMatcher.hasCloneGroup;
public class SuffixTreeCloneDetectionAlgorithmTest extends DetectorTestCase {
@@ -45,7 +44,7 @@ public class SuffixTreeCloneDetectionAlgorithmTest extends DetectorTestCase {
@Test
public void noDuplications() {
CloneIndex index = createIndex();
- List<Block> fileBlocks = newBlocks("a", "1 2 3");
+ Block[] fileBlocks = newBlocks("a", "1 2 3");
List<CloneGroup> result = detect(index, fileBlocks);
assertThat(result, sameInstance(Collections.EMPTY_LIST));
}
@@ -65,12 +64,9 @@ public class SuffixTreeCloneDetectionAlgorithmTest extends DetectorTestCase {
@Test
public void huge() {
CloneIndex index = createIndex();
- List<Block> fileBlocks = Lists.newArrayList();
- int indexInFile = 0;
+ Block[] fileBlocks = new Block[5000];
for (int i = 0; i < 5000; i++) {
- Block block = newBlock("x", new ByteArray("01"), indexInFile);
- fileBlocks.add(block);
- indexInFile++;
+ fileBlocks[i] = newBlock("x", new ByteArray("01"), i);
}
List<CloneGroup> result = detect(index, fileBlocks);
@@ -92,7 +88,7 @@ public class SuffixTreeCloneDetectionAlgorithmTest extends DetectorTestCase {
@Test
public void myTest() {
CloneIndex index = createIndex();
- List<Block> fileBlocks = newBlocks("x", "a 2 b 2 c 2 2 2");
+ Block[] fileBlocks = newBlocks("x", "a 2 b 2 c 2 2 2");
List<CloneGroup> result = detect(index, fileBlocks);
print(result);
@@ -128,7 +124,7 @@ public class SuffixTreeCloneDetectionAlgorithmTest extends DetectorTestCase {
@Test
public void myTest2() {
CloneIndex index = createIndex();
- List<Block> fileBlocks = newBlocks("x", "a 2 3 b 2 3 c 2 3 d 2 3 2 3 2 3");
+ Block[] fileBlocks = newBlocks("x", "a 2 3 b 2 3 c 2 3 d 2 3 2 3 2 3");
List<CloneGroup> result = detect(index, fileBlocks);
print(result);
@@ -171,7 +167,7 @@ public class SuffixTreeCloneDetectionAlgorithmTest extends DetectorTestCase {
newBlocks("b", "4 3 2"),
newBlocks("c", "4 3 1")
);
- List<Block> fileBlocks = newBlocks("a", "1 2 3 4");
+ Block[] fileBlocks = newBlocks("a", "1 2 3 4");
List<CloneGroup> result = detect(index, fileBlocks);
print(result);
@@ -197,8 +193,8 @@ public class SuffixTreeCloneDetectionAlgorithmTest extends DetectorTestCase {
}
@Override
- protected List<CloneGroup> detect(CloneIndex index, List<Block> fileBlocks) {
- return SuffixTreeCloneDetectionAlgorithm.detect(index, fileBlocks);
+ protected List<CloneGroup> detect(CloneIndex index, Block[] fileBlocks) {
+ return SuffixTreeCloneDetectionAlgorithm.detect(index, Arrays.asList(fileBlocks));
}
}