aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-duplications
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-duplications')
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/DuplicationPredicatesTest.java9
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/block/BlockChunkerTestCase.java2
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/detector/DetectorTestCase.java132
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/detector/original/BlocksGroupTest.java2
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/TokenizerBridgeTest.java2
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/java/JavaDuplicationsFunctionalTest.java2
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/java/JavaStatementBuilderTest.java276
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/java/JavaTokenProducerTest.java2
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/statement/StatementChannelTest.java2
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/token/BlackHoleTokenChannelTest.java15
10 files changed, 223 insertions, 221 deletions
diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/DuplicationPredicatesTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/DuplicationPredicatesTest.java
index 6262929bbb2..146106b3442 100644
--- a/sonar-duplications/src/test/java/org/sonar/duplications/DuplicationPredicatesTest.java
+++ b/sonar-duplications/src/test/java/org/sonar/duplications/DuplicationPredicatesTest.java
@@ -23,17 +23,16 @@ import com.google.common.base.Predicate;
import org.junit.Test;
import org.sonar.duplications.index.CloneGroup;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
+import static org.fest.assertions.Assertions.assertThat;
public class DuplicationPredicatesTest {
@Test
public void testNumberOfUnitsNotLessThan() {
Predicate<CloneGroup> predicate = DuplicationPredicates.numberOfUnitsNotLessThan(5);
- assertThat(predicate.apply(CloneGroup.builder().setLengthInUnits(6).build()), is(true));
- assertThat(predicate.apply(CloneGroup.builder().setLengthInUnits(5).build()), is(true));
- assertThat(predicate.apply(CloneGroup.builder().setLengthInUnits(4).build()), is(false));
+ assertThat(predicate.apply(CloneGroup.builder().setLengthInUnits(6).build())).isTrue();
+ assertThat(predicate.apply(CloneGroup.builder().setLengthInUnits(5).build())).isTrue();
+ assertThat(predicate.apply(CloneGroup.builder().setLengthInUnits(4).build())).isFalse();
}
}
diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/block/BlockChunkerTestCase.java b/sonar-duplications/src/test/java/org/sonar/duplications/block/BlockChunkerTestCase.java
index 5b6481b5ef4..93d8068b088 100644
--- a/sonar-duplications/src/test/java/org/sonar/duplications/block/BlockChunkerTestCase.java
+++ b/sonar-duplications/src/test/java/org/sonar/duplications/block/BlockChunkerTestCase.java
@@ -26,7 +26,7 @@ import org.sonar.duplications.statement.Statement;
import java.util.Collections;
import java.util.List;
-import static org.hamcrest.Matchers.*;
+import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
/**
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 6a26def7e81..b44ded89664 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
@@ -30,12 +30,18 @@ import org.sonar.duplications.index.ClonePart;
import org.sonar.duplications.index.MemoryCloneIndex;
import org.sonar.duplications.junit.TestNamePrinter;
-import java.util.*;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
-import static org.hamcrest.Matchers.*;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.sameInstance;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.*;
+import static org.junit.matchers.JUnitMatchers.hasItem;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.sonar.duplications.detector.CloneGroupMatcher.hasCloneGroup;
public abstract class DetectorTestCase {
@@ -51,11 +57,11 @@ public abstract class DetectorTestCase {
*/
protected static Block newBlock(String resourceId, ByteArray hash, int index) {
return Block.builder()
- .setResourceId(resourceId)
- .setBlockHash(hash)
- .setIndexInFile(index)
- .setLines(index, index + LINES_PER_BLOCK)
- .build();
+ .setResourceId(resourceId)
+ .setBlockHash(hash)
+ .setIndexInFile(index)
+ .setLines(index, index + LINES_PER_BLOCK)
+ .build();
}
protected static ClonePart newClonePart(String resourceId, int unitStart, int cloneUnitLength) {
@@ -80,8 +86,8 @@ public abstract class DetectorTestCase {
@Test
public void exampleFromPaper() {
CloneIndex index = createIndex(
- newBlocks("y", "2 3 4 5"),
- newBlocks("z", "3 4"));
+ newBlocks("y", "2 3 4 5"),
+ newBlocks("z", "3 4"));
Block[] fileBlocks = newBlocks("x", "1 2 3 4 5 6");
List<CloneGroup> result = detect(index, fileBlocks);
@@ -89,13 +95,13 @@ public abstract class DetectorTestCase {
assertEquals(2, result.size());
assertThat(result, hasCloneGroup(4,
- newClonePart("x", 1, 4),
- newClonePart("y", 0, 4)));
+ newClonePart("x", 1, 4),
+ newClonePart("y", 0, 4)));
assertThat(result, hasCloneGroup(2,
- newClonePart("x", 2, 2),
- newClonePart("y", 1, 2),
- newClonePart("z", 0, 2)));
+ newClonePart("x", 2, 2),
+ newClonePart("y", 1, 2),
+ newClonePart("z", 0, 2)));
}
/**
@@ -114,8 +120,8 @@ public abstract class DetectorTestCase {
@Test
public void exampleFromPaperWithModifiedResourceIds() {
CloneIndex cloneIndex = createIndex(
- newBlocks("a", "2 3 4 5"),
- newBlocks("b", "3 4"));
+ newBlocks("a", "2 3 4 5"),
+ newBlocks("b", "3 4"));
Block[] fileBlocks = newBlocks("c", "1 2 3 4 5 6");
List<CloneGroup> clones = detect(cloneIndex, fileBlocks);
@@ -123,13 +129,13 @@ public abstract class DetectorTestCase {
assertThat(clones.size(), is(2));
assertThat(clones, hasCloneGroup(4,
- newClonePart("c", 1, 4),
- newClonePart("a", 0, 4)));
+ newClonePart("c", 1, 4),
+ newClonePart("a", 0, 4)));
assertThat(clones, hasCloneGroup(2,
- newClonePart("c", 2, 2),
- newClonePart("a", 1, 2),
- newClonePart("b", 0, 2)));
+ newClonePart("c", 2, 2),
+ newClonePart("a", 1, 2),
+ newClonePart("b", 0, 2)));
}
/**
@@ -149,8 +155,8 @@ public abstract class DetectorTestCase {
@Test
public void example1() {
CloneIndex index = createIndex(
- newBlocks("b", "3 4 5 6"),
- newBlocks("c", "5 6 7"));
+ newBlocks("b", "3 4 5 6"),
+ newBlocks("c", "5 6 7"));
Block[] fileBlocks = newBlocks("a", "1 2 3 4 5 6 7 8 9");
List<CloneGroup> result = detect(index, fileBlocks);
@@ -158,17 +164,17 @@ public abstract class DetectorTestCase {
assertThat(result.size(), is(3));
assertThat(result, hasCloneGroup(4,
- newClonePart("a", 2, 4),
- newClonePart("b", 0, 4)));
+ newClonePart("a", 2, 4),
+ newClonePart("b", 0, 4)));
assertThat(result, hasCloneGroup(3,
- newClonePart("a", 4, 3),
- newClonePart("c", 0, 3)));
+ newClonePart("a", 4, 3),
+ newClonePart("c", 0, 3)));
assertThat(result, hasCloneGroup(2,
- newClonePart("a", 4, 2),
- newClonePart("b", 2, 2),
- newClonePart("c", 0, 2)));
+ newClonePart("a", 4, 2),
+ newClonePart("b", 2, 2),
+ newClonePart("c", 0, 2)));
}
/**
@@ -186,8 +192,8 @@ public abstract class DetectorTestCase {
@Test
public void example2() {
CloneIndex index = createIndex(
- newBlocks("b", "1 2 3 4 1 2 3 4 1 2 3 4"),
- newBlocks("c", "1 2 3 4"));
+ newBlocks("b", "1 2 3 4 1 2 3 4 1 2 3 4"),
+ newBlocks("c", "1 2 3 4"));
Block[] fileBlocks = newBlocks("a", "1 2 3 5");
List<CloneGroup> result = detect(index, fileBlocks);
@@ -195,11 +201,11 @@ public abstract class DetectorTestCase {
assertThat(result.size(), is(1));
assertThat(result, hasCloneGroup(3,
- newClonePart("a", 0, 3),
- newClonePart("b", 0, 3),
- newClonePart("b", 4, 3),
- newClonePart("b", 8, 3),
- newClonePart("c", 0, 3)));
+ newClonePart("a", 0, 3),
+ newClonePart("b", 0, 3),
+ newClonePart("b", 4, 3),
+ newClonePart("b", 8, 3),
+ newClonePart("c", 0, 3)));
}
/**
@@ -223,8 +229,8 @@ public abstract class DetectorTestCase {
assertThat(result.size(), is(1));
assertThat(result, hasCloneGroup(2,
- newClonePart("a", 0, 2),
- newClonePart("a", 3, 2)));
+ newClonePart("a", 0, 2),
+ newClonePart("a", 3, 2)));
}
/**
@@ -243,7 +249,7 @@ public abstract class DetectorTestCase {
@Test
public void covered() {
CloneIndex index = createIndex(
- newBlocks("b", "1 2 1 2"));
+ newBlocks("b", "1 2 1 2"));
Block[] fileBlocks = newBlocks("a", "1 2 1");
List<CloneGroup> result = detect(index, fileBlocks);
@@ -251,13 +257,13 @@ public abstract class DetectorTestCase {
assertThat(result.size(), is(2));
assertThat(result, hasCloneGroup(3,
- newClonePart("a", 0, 3),
- newClonePart("b", 0, 3)));
+ newClonePart("a", 0, 3),
+ newClonePart("b", 0, 3)));
assertThat(result, hasCloneGroup(2,
- newClonePart("a", 0, 2),
- newClonePart("b", 0, 2),
- newClonePart("b", 2, 2)));
+ newClonePart("a", 0, 2),
+ newClonePart("b", 0, 2),
+ newClonePart("b", 2, 2)));
}
/**
@@ -275,7 +281,7 @@ public abstract class DetectorTestCase {
@Test
public void problemWithNestedCloneGroups() {
CloneIndex index = createIndex(
- newBlocks("b", "1 2 1 2 1 2 1"));
+ newBlocks("b", "1 2 1 2 1 2 1"));
Block[] fileBlocks = newBlocks("a", "1 2 1 2 1 2");
List<CloneGroup> result = detect(index, fileBlocks);
@@ -283,13 +289,13 @@ public abstract class DetectorTestCase {
assertThat(result.size(), is(2));
assertThat(result, hasCloneGroup(6,
- newClonePart("a", 0, 6),
- newClonePart("b", 0, 6)));
+ newClonePart("a", 0, 6),
+ newClonePart("b", 0, 6)));
assertThat(result, hasCloneGroup(5,
- newClonePart("a", 0, 5),
- newClonePart("b", 0, 5),
- newClonePart("b", 2, 5)));
+ newClonePart("a", 0, 5),
+ newClonePart("b", 0, 5),
+ newClonePart("b", 2, 5)));
}
/**
@@ -307,8 +313,8 @@ public abstract class DetectorTestCase {
@Test
public void fileAlreadyInIndex() {
CloneIndex index = createIndex(
- newBlocks("a", "1 2 3"),
- newBlocks("b", "1 2 4"));
+ 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)
Block[] fileBlocks = newBlocks("a", "1 2 5");
List<CloneGroup> result = detect(index, fileBlocks);
@@ -317,8 +323,8 @@ public abstract class DetectorTestCase {
assertThat(result.size(), is(1));
assertThat(result, hasCloneGroup(2,
- newClonePart("a", 0, 2),
- newClonePart("b", 0, 2)));
+ newClonePart("a", 0, 2),
+ newClonePart("b", 0, 2)));
}
/**
@@ -360,17 +366,17 @@ public abstract class DetectorTestCase {
@Test
public void problemWithEndOfFile() {
CloneIndex cloneIndex = createIndex(
- newBlocks("b", "1 2 3 4"));
+ newBlocks("b", "1 2 3 4"));
Block[] fileBlocks =
- newBlocks("a", "1 2 3");
+ newBlocks("a", "1 2 3");
List<CloneGroup> clones = detect(cloneIndex, fileBlocks);
print(clones);
assertThat(clones.size(), is(1));
assertThat(clones, hasCloneGroup(3,
- newClonePart("a", 0, 3),
- newClonePart("b", 0, 3)));
+ newClonePart("a", 0, 3),
+ newClonePart("b", 0, 3)));
}
/**
@@ -391,9 +397,9 @@ public abstract class DetectorTestCase {
public void same_lines_but_different_indexes() {
CloneIndex cloneIndex = createIndex();
Block.Builder block = Block.builder()
- .setResourceId("a")
- .setLines(0, 1);
- Block[] fileBlocks = new Block[] {
+ .setResourceId("a")
+ .setLines(0, 1);
+ 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()
diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/detector/original/BlocksGroupTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/detector/original/BlocksGroupTest.java
index 4b63abc419e..9831f4531cb 100644
--- a/sonar-duplications/src/test/java/org/sonar/duplications/detector/original/BlocksGroupTest.java
+++ b/sonar-duplications/src/test/java/org/sonar/duplications/detector/original/BlocksGroupTest.java
@@ -22,7 +22,7 @@ package org.sonar.duplications.detector.original;
import org.junit.Test;
import org.sonar.duplications.block.Block;
-import static org.hamcrest.Matchers.is;
+import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
public class BlocksGroupTest {
diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/TokenizerBridgeTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/TokenizerBridgeTest.java
index ea16c856685..8c11dc4ebae 100644
--- a/sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/TokenizerBridgeTest.java
+++ b/sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/TokenizerBridgeTest.java
@@ -29,7 +29,7 @@ import org.junit.Test;
import java.io.IOException;
import java.util.List;
-import static org.hamcrest.Matchers.is;
+import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
public class TokenizerBridgeTest {
diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaDuplicationsFunctionalTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaDuplicationsFunctionalTest.java
index 66fa6dc8294..96818f66752 100644
--- a/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaDuplicationsFunctionalTest.java
+++ b/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaDuplicationsFunctionalTest.java
@@ -35,7 +35,7 @@ import org.sonar.duplications.token.TokenChunker;
import java.util.Collection;
import java.util.List;
-import static org.hamcrest.Matchers.is;
+import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
/**
diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaStatementBuilderTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaStatementBuilderTest.java
index bd0e07d598c..5995290c307 100644
--- a/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaStatementBuilderTest.java
+++ b/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaStatementBuilderTest.java
@@ -34,9 +34,7 @@ import java.io.InputStreamReader;
import java.io.Reader;
import java.util.List;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.number.OrderingComparisons.greaterThan;
-import static org.junit.Assert.assertThat;
+import static org.fest.assertions.Assertions.assertThat;
public class JavaStatementBuilderTest {
@@ -49,12 +47,12 @@ public class JavaStatementBuilderTest {
@Test
public void shouldIgnoreImportStatement() {
- assertThat(chunk("import org.sonar.duplications.java;").size(), is(0));
+ assertThat(chunk("import org.sonar.duplications.java;")).isEmpty();
}
@Test
public void shouldIgnorePackageStatement() {
- assertThat(chunk("package org.sonar.duplications.java;").size(), is(0));
+ assertThat(chunk("package org.sonar.duplications.java;")).isEmpty();
}
@Test
@@ -63,66 +61,66 @@ public class JavaStatementBuilderTest {
"@Entity" +
"@Table(name = \"properties\")" +
"@Column(updatable = true, nullable = true)");
- assertThat(statements.size(), is(3));
- assertThat(statements.get(0).getValue(), is("@Entity"));
- assertThat(statements.get(1).getValue(), is("@Table(name=$CHARS)"));
- assertThat(statements.get(2).getValue(), is("@Column(updatable=true,nullable=true)"));
+ assertThat(statements).hasSize(3);
+ assertThat(statements.get(0).getValue()).isEqualTo("@Entity");
+ assertThat(statements.get(1).getValue()).isEqualTo("@Table(name=$CHARS)");
+ assertThat(statements.get(2).getValue()).isEqualTo("@Column(updatable=true,nullable=true)");
}
@Test
public void shouldHandleIf() {
List<Statement> statements = chunk("if (a > b) { something(); }");
- assertThat(statements.size(), is(2));
- assertThat(statements.get(0).getValue(), is("if(a>b)"));
- assertThat(statements.get(1).getValue(), is("something()"));
+ assertThat(statements.size()).isEqualTo(2);
+ assertThat(statements.get(0).getValue()).isEqualTo("if(a>b)");
+ assertThat(statements.get(1).getValue()).isEqualTo("something()");
statements = chunk("if (a > b) { something(); } else { somethingOther(); }");
- assertThat(statements.size(), is(4));
- assertThat(statements.get(0).getValue(), is("if(a>b)"));
- assertThat(statements.get(1).getValue(), is("something()"));
- assertThat(statements.get(2).getValue(), is("else"));
- assertThat(statements.get(3).getValue(), is("somethingOther()"));
+ assertThat(statements.size()).isEqualTo(4);
+ assertThat(statements.get(0).getValue()).isEqualTo("if(a>b)");
+ assertThat(statements.get(1).getValue()).isEqualTo("something()");
+ assertThat(statements.get(2).getValue()).isEqualTo("else");
+ assertThat(statements.get(3).getValue()).isEqualTo("somethingOther()");
statements = chunk("if (a > 0) { something(); } else if (a == 0) { somethingOther(); }");
- assertThat(statements.size(), is(4));
- assertThat(statements.get(0).getValue(), is("if(a>$NUMBER)"));
- assertThat(statements.get(1).getValue(), is("something()"));
- assertThat(statements.get(2).getValue(), is("elseif(a==$NUMBER)"));
- assertThat(statements.get(3).getValue(), is("somethingOther()"));
+ assertThat(statements.size()).isEqualTo(4);
+ assertThat(statements.get(0).getValue()).isEqualTo("if(a>$NUMBER)");
+ assertThat(statements.get(1).getValue()).isEqualTo("something()");
+ assertThat(statements.get(2).getValue()).isEqualTo("elseif(a==$NUMBER)");
+ assertThat(statements.get(3).getValue()).isEqualTo("somethingOther()");
}
@Test
public void shouldHandleFor() {
List<Statement> statements = chunk("for (int i = 0; i < 10; i++) { something(); }");
- assertThat(statements.size(), is(2));
- assertThat(statements.get(0).getValue(), is("for(inti=$NUMBER;i<$NUMBER;i++)"));
- assertThat(statements.get(1).getValue(), is("something()"));
+ assertThat(statements.size()).isEqualTo(2);
+ assertThat(statements.get(0).getValue()).isEqualTo("for(inti=$NUMBER;i<$NUMBER;i++)");
+ assertThat(statements.get(1).getValue()).isEqualTo("something()");
statements = chunk("for (Item item : items) { something(); }");
- assertThat(statements.size(), is(2));
- assertThat(statements.get(0).getValue(), is("for(Itemitem:items)"));
- assertThat(statements.get(1).getValue(), is("something()"));
+ assertThat(statements.size()).isEqualTo(2);
+ assertThat(statements.get(0).getValue()).isEqualTo("for(Itemitem:items)");
+ assertThat(statements.get(1).getValue()).isEqualTo("something()");
}
@Test
public void shouldHandleWhile() {
List<Statement> statements = chunk("while (i < args.length) { something(); }");
- assertThat(statements.size(), is(2));
- assertThat(statements.get(0).getValue(), is("while(i<args.length)"));
- assertThat(statements.get(1).getValue(), is("something()"));
+ assertThat(statements.size()).isEqualTo(2);
+ assertThat(statements.get(0).getValue()).isEqualTo("while(i<args.length)");
+ assertThat(statements.get(1).getValue()).isEqualTo("something()");
statements = chunk("while (true);");
- assertThat(statements.size(), is(1));
- assertThat(statements.get(0).getValue(), is("while(true)"));
+ assertThat(statements.size()).isEqualTo(1);
+ assertThat(statements.get(0).getValue()).isEqualTo("while(true)");
}
@Test
public void shouldHandleDoWhile() {
List<Statement> statements = chunk("do { something(); } while (true);");
- assertThat(statements.size(), is(3));
- assertThat(statements.get(0).getValue(), is("do"));
- assertThat(statements.get(1).getValue(), is("something()"));
- assertThat(statements.get(2).getValue(), is("while(true)"));
+ assertThat(statements.size()).isEqualTo(3);
+ assertThat(statements.get(0).getValue()).isEqualTo("do");
+ assertThat(statements.get(1).getValue()).isEqualTo("something()");
+ assertThat(statements.get(2).getValue()).isEqualTo("while(true)");
}
@Test
@@ -133,13 +131,13 @@ public class JavaStatementBuilderTest {
" case 2 : monthString=\"February\"; break;" +
" default: monthString=\"Invalid\";" +
"}");
- assertThat(statements.size(), is(6));
- assertThat(statements.get(0).getValue(), is("switch(month)"));
- assertThat(statements.get(1).getValue(), is("case$NUMBER:monthString=$CHARS"));
- assertThat(statements.get(2).getValue(), is("break"));
- assertThat(statements.get(3).getValue(), is("case$NUMBER:monthString=$CHARS"));
- assertThat(statements.get(4).getValue(), is("break"));
- assertThat(statements.get(5).getValue(), is("default:monthString=$CHARS"));
+ assertThat(statements.size()).isEqualTo(6);
+ assertThat(statements.get(0).getValue()).isEqualTo("switch(month)");
+ assertThat(statements.get(1).getValue()).isEqualTo("case$NUMBER:monthString=$CHARS");
+ assertThat(statements.get(2).getValue()).isEqualTo("break");
+ assertThat(statements.get(3).getValue()).isEqualTo("case$NUMBER:monthString=$CHARS");
+ assertThat(statements.get(4).getValue()).isEqualTo("break");
+ assertThat(statements.get(5).getValue()).isEqualTo("default:monthString=$CHARS");
}
/**
@@ -152,20 +150,20 @@ public class JavaStatementBuilderTest {
" case 'a': case 'b': case 'c': something(); break;" +
" case 'd': case 'e': case 'f': somethingOther(); break;" +
"}");
- assertThat(statements.size(), is(5));
- assertThat(statements.get(0).getValue(), is("switch(a)"));
- assertThat(statements.get(1).getValue(), is("case$CHARS:case$CHARS:case$CHARS:something()"));
- assertThat(statements.get(2).getValue(), is("break"));
- assertThat(statements.get(3).getValue(), is("case$CHARS:case$CHARS:case$CHARS:somethingOther()"));
- assertThat(statements.get(4).getValue(), is("break"));
+ assertThat(statements.size()).isEqualTo(5);
+ assertThat(statements.get(0).getValue()).isEqualTo("switch(a)");
+ assertThat(statements.get(1).getValue()).isEqualTo("case$CHARS:case$CHARS:case$CHARS:something()");
+ assertThat(statements.get(2).getValue()).isEqualTo("break");
+ assertThat(statements.get(3).getValue()).isEqualTo("case$CHARS:case$CHARS:case$CHARS:somethingOther()");
+ assertThat(statements.get(4).getValue()).isEqualTo("break");
}
@Test
public void shouldHandleArray() {
List<Statement> statements = chunk("new Integer[] { 1, 2, 3, 4 };");
- assertThat(statements.size(), is(2));
- assertThat(statements.get(0).getValue(), is("newInteger[]"));
- assertThat(statements.get(1).getValue(), is("{$NUMBER,$NUMBER,$NUMBER,$NUMBER}"));
+ assertThat(statements.size()).isEqualTo(2);
+ assertThat(statements.get(0).getValue()).isEqualTo("newInteger[]");
+ assertThat(statements.get(1).getValue()).isEqualTo("{$NUMBER,$NUMBER,$NUMBER,$NUMBER}");
}
/**
@@ -174,95 +172,95 @@ public class JavaStatementBuilderTest {
@Test
public void shouldHandleMultidimensionalArray() {
List<Statement> statements = chunk("new Integer[][] { { 1, 2 }, {3, 4} };");
- assertThat(statements.size(), is(2));
- assertThat(statements.get(0).getValue(), is("newInteger[][]"));
- assertThat(statements.get(1).getValue(), is("{{$NUMBER,$NUMBER},{$NUMBER,$NUMBER}}"));
+ assertThat(statements.size()).isEqualTo(2);
+ assertThat(statements.get(0).getValue()).isEqualTo("newInteger[][]");
+ assertThat(statements.get(1).getValue()).isEqualTo("{{$NUMBER,$NUMBER},{$NUMBER,$NUMBER}}");
statements = chunk("new Integer[][] { null, {3, 4} };");
- assertThat(statements.size(), is(2));
- assertThat(statements.get(0).getValue(), is("newInteger[][]"));
- assertThat(statements.get(1).getValue(), is("{null,{$NUMBER,$NUMBER}}"));
+ assertThat(statements.size()).isEqualTo(2);
+ assertThat(statements.get(0).getValue()).isEqualTo("newInteger[][]");
+ assertThat(statements.get(1).getValue()).isEqualTo("{null,{$NUMBER,$NUMBER}}");
}
@Test
public void shouldHandleTryCatch() {
List<Statement> statements;
statements = chunk("try { } catch (Exception e) { }");
- assertThat(statements.size(), is(4));
- assertThat(statements.get(0).getValue(), is("try"));
- assertThat(statements.get(1).getValue(), is("{}"));
- assertThat(statements.get(2).getValue(), is("catch(Exceptione)"));
- assertThat(statements.get(3).getValue(), is("{}"));
+ assertThat(statements.size()).isEqualTo(4);
+ assertThat(statements.get(0).getValue()).isEqualTo("try");
+ assertThat(statements.get(1).getValue()).isEqualTo("{}");
+ assertThat(statements.get(2).getValue()).isEqualTo("catch(Exceptione)");
+ assertThat(statements.get(3).getValue()).isEqualTo("{}");
statements = chunk("try { something(); } catch (Exception e) { }");
- assertThat(statements.size(), is(4));
- assertThat(statements.get(0).getValue(), is("try"));
- assertThat(statements.get(1).getValue(), is("something()"));
- assertThat(statements.get(2).getValue(), is("catch(Exceptione)"));
- assertThat(statements.get(3).getValue(), is("{}"));
+ assertThat(statements.size()).isEqualTo(4);
+ assertThat(statements.get(0).getValue()).isEqualTo("try");
+ assertThat(statements.get(1).getValue()).isEqualTo("something()");
+ assertThat(statements.get(2).getValue()).isEqualTo("catch(Exceptione)");
+ assertThat(statements.get(3).getValue()).isEqualTo("{}");
statements = chunk("try { something(); } catch (Exception e) { onException(); }");
- assertThat(statements.size(), is(4));
- assertThat(statements.get(0).getValue(), is("try"));
- assertThat(statements.get(1).getValue(), is("something()"));
- assertThat(statements.get(2).getValue(), is("catch(Exceptione)"));
- assertThat(statements.get(3).getValue(), is("onException()"));
+ assertThat(statements.size()).isEqualTo(4);
+ assertThat(statements.get(0).getValue()).isEqualTo("try");
+ assertThat(statements.get(1).getValue()).isEqualTo("something()");
+ assertThat(statements.get(2).getValue()).isEqualTo("catch(Exceptione)");
+ assertThat(statements.get(3).getValue()).isEqualTo("onException()");
statements = chunk("try { something(); } catch (Exception1 e) { onException1(); } catch (Exception2 e) { onException2(); }");
- assertThat(statements.size(), is(6));
- assertThat(statements.get(0).getValue(), is("try"));
- assertThat(statements.get(1).getValue(), is("something()"));
- assertThat(statements.get(2).getValue(), is("catch(Exception1e)"));
- assertThat(statements.get(3).getValue(), is("onException1()"));
- assertThat(statements.get(4).getValue(), is("catch(Exception2e)"));
- assertThat(statements.get(5).getValue(), is("onException2()"));
+ assertThat(statements.size()).isEqualTo(6);
+ assertThat(statements.get(0).getValue()).isEqualTo("try");
+ assertThat(statements.get(1).getValue()).isEqualTo("something()");
+ assertThat(statements.get(2).getValue()).isEqualTo("catch(Exception1e)");
+ assertThat(statements.get(3).getValue()).isEqualTo("onException1()");
+ assertThat(statements.get(4).getValue()).isEqualTo("catch(Exception2e)");
+ assertThat(statements.get(5).getValue()).isEqualTo("onException2()");
}
@Test
public void shouldHandleTryFinnaly() {
List<Statement> statements;
statements = chunk("try { } finally { }");
- assertThat(statements.size(), is(4));
- assertThat(statements.get(0).getValue(), is("try"));
- assertThat(statements.get(1).getValue(), is("{}"));
- assertThat(statements.get(2).getValue(), is("finally"));
- assertThat(statements.get(3).getValue(), is("{}"));
+ assertThat(statements.size()).isEqualTo(4);
+ assertThat(statements.get(0).getValue()).isEqualTo("try");
+ assertThat(statements.get(1).getValue()).isEqualTo("{}");
+ assertThat(statements.get(2).getValue()).isEqualTo("finally");
+ assertThat(statements.get(3).getValue()).isEqualTo("{}");
statements = chunk("try { something(); } finally { }");
- assertThat(statements.size(), is(4));
- assertThat(statements.get(0).getValue(), is("try"));
- assertThat(statements.get(1).getValue(), is("something()"));
- assertThat(statements.get(2).getValue(), is("finally"));
- assertThat(statements.get(3).getValue(), is("{}"));
+ assertThat(statements.size()).isEqualTo(4);
+ assertThat(statements.get(0).getValue()).isEqualTo("try");
+ assertThat(statements.get(1).getValue()).isEqualTo("something()");
+ assertThat(statements.get(2).getValue()).isEqualTo("finally");
+ assertThat(statements.get(3).getValue()).isEqualTo("{}");
statements = chunk("try { something(); } finally { somethingOther(); }");
- assertThat(statements.size(), is(4));
- assertThat(statements.get(0).getValue(), is("try"));
- assertThat(statements.get(1).getValue(), is("something()"));
- assertThat(statements.get(2).getValue(), is("finally"));
- assertThat(statements.get(3).getValue(), is("somethingOther()"));
+ assertThat(statements.size()).isEqualTo(4);
+ assertThat(statements.get(0).getValue()).isEqualTo("try");
+ assertThat(statements.get(1).getValue()).isEqualTo("something()");
+ assertThat(statements.get(2).getValue()).isEqualTo("finally");
+ assertThat(statements.get(3).getValue()).isEqualTo("somethingOther()");
}
@Test
public void shouldHandleTryCatchFinally() {
List<Statement> statements;
statements = chunk("try { } catch (Exception e) {} finally { }");
- assertThat(statements.size(), is(6));
- assertThat(statements.get(0).getValue(), is("try"));
- assertThat(statements.get(1).getValue(), is("{}"));
- assertThat(statements.get(2).getValue(), is("catch(Exceptione)"));
- assertThat(statements.get(3).getValue(), is("{}"));
- assertThat(statements.get(4).getValue(), is("finally"));
- assertThat(statements.get(5).getValue(), is("{}"));
+ assertThat(statements.size()).isEqualTo(6);
+ assertThat(statements.get(0).getValue()).isEqualTo("try");
+ assertThat(statements.get(1).getValue()).isEqualTo("{}");
+ assertThat(statements.get(2).getValue()).isEqualTo("catch(Exceptione)");
+ assertThat(statements.get(3).getValue()).isEqualTo("{}");
+ assertThat(statements.get(4).getValue()).isEqualTo("finally");
+ assertThat(statements.get(5).getValue()).isEqualTo("{}");
statements = chunk("try { something(); } catch (Exception e) { onException(); } finally { somethingOther(); }");
- assertThat(statements.size(), is(6));
- assertThat(statements.get(0).getValue(), is("try"));
- assertThat(statements.get(1).getValue(), is("something()"));
- assertThat(statements.get(2).getValue(), is("catch(Exceptione)"));
- assertThat(statements.get(3).getValue(), is("onException()"));
- assertThat(statements.get(4).getValue(), is("finally"));
- assertThat(statements.get(5).getValue(), is("somethingOther()"));
+ assertThat(statements.size()).isEqualTo(6);
+ assertThat(statements.get(0).getValue()).isEqualTo("try");
+ assertThat(statements.get(1).getValue()).isEqualTo("something()");
+ assertThat(statements.get(2).getValue()).isEqualTo("catch(Exceptione)");
+ assertThat(statements.get(3).getValue()).isEqualTo("onException()");
+ assertThat(statements.get(4).getValue()).isEqualTo("finally");
+ assertThat(statements.get(5).getValue()).isEqualTo("somethingOther()");
}
/**
@@ -272,25 +270,25 @@ public class JavaStatementBuilderTest {
public void shouldHandleMultiCatch() {
List<Statement> statements;
statements = chunk("try { } catch (Exception1 | Exception2 e) { }");
- assertThat(statements.size(), is(4));
- assertThat(statements.get(0).getValue(), is("try"));
- assertThat(statements.get(1).getValue(), is("{}"));
- assertThat(statements.get(2).getValue(), is("catch(Exception1|Exception2e)"));
- assertThat(statements.get(3).getValue(), is("{}"));
+ assertThat(statements.size()).isEqualTo(4);
+ assertThat(statements.get(0).getValue()).isEqualTo("try");
+ assertThat(statements.get(1).getValue()).isEqualTo("{}");
+ assertThat(statements.get(2).getValue()).isEqualTo("catch(Exception1|Exception2e)");
+ assertThat(statements.get(3).getValue()).isEqualTo("{}");
statements = chunk("try { something(); } catch (Exception1 | Exception2 e) { }");
- assertThat(statements.size(), is(4));
- assertThat(statements.get(0).getValue(), is("try"));
- assertThat(statements.get(1).getValue(), is("something()"));
- assertThat(statements.get(2).getValue(), is("catch(Exception1|Exception2e)"));
- assertThat(statements.get(3).getValue(), is("{}"));
+ assertThat(statements.size()).isEqualTo(4);
+ assertThat(statements.get(0).getValue()).isEqualTo("try");
+ assertThat(statements.get(1).getValue()).isEqualTo("something()");
+ assertThat(statements.get(2).getValue()).isEqualTo("catch(Exception1|Exception2e)");
+ assertThat(statements.get(3).getValue()).isEqualTo("{}");
statements = chunk("try { something(); } catch (Exception1 | Exception2 e) { onException(); }");
- assertThat(statements.size(), is(4));
- assertThat(statements.get(0).getValue(), is("try"));
- assertThat(statements.get(1).getValue(), is("something()"));
- assertThat(statements.get(2).getValue(), is("catch(Exception1|Exception2e)"));
- assertThat(statements.get(3).getValue(), is("onException()"));
+ assertThat(statements.size()).isEqualTo(4);
+ assertThat(statements.get(0).getValue()).isEqualTo("try");
+ assertThat(statements.get(1).getValue()).isEqualTo("something()");
+ assertThat(statements.get(2).getValue()).isEqualTo("catch(Exception1|Exception2e)");
+ assertThat(statements.get(3).getValue()).isEqualTo("onException()");
}
/**
@@ -300,30 +298,30 @@ public class JavaStatementBuilderTest {
public void shouldHandleTryWithResource() {
List<Statement> statements;
statements = chunk("try (FileInputStream in = new FileInputStream()) {}");
- assertThat(statements.size(), is(2));
- assertThat(statements.get(0).getValue(), is("try(FileInputStreamin=newFileInputStream())"));
- assertThat(statements.get(1).getValue(), is("{}"));
+ assertThat(statements.size()).isEqualTo(2);
+ assertThat(statements.get(0).getValue()).isEqualTo("try(FileInputStreamin=newFileInputStream())");
+ assertThat(statements.get(1).getValue()).isEqualTo("{}");
statements = chunk("try (FileInputStream in = new FileInputStream(); FileOutputStream out = new FileOutputStream()) {}");
- assertThat(statements.size(), is(2));
- assertThat(statements.get(0).getValue(), is("try(FileInputStreamin=newFileInputStream();FileOutputStreamout=newFileOutputStream())"));
- assertThat(statements.get(1).getValue(), is("{}"));
+ assertThat(statements.size()).isEqualTo(2);
+ assertThat(statements.get(0).getValue()).isEqualTo("try(FileInputStreamin=newFileInputStream();FileOutputStreamout=newFileOutputStream())");
+ assertThat(statements.get(1).getValue()).isEqualTo("{}");
statements = chunk("try (FileInputStream in = new FileInputStream(); FileOutputStream out = new FileOutputStream();) {}");
- assertThat(statements.size(), is(2));
- assertThat(statements.get(0).getValue(), is("try(FileInputStreamin=newFileInputStream();FileOutputStreamout=newFileOutputStream();)"));
- assertThat(statements.get(1).getValue(), is("{}"));
+ assertThat(statements.size()).isEqualTo(2);
+ assertThat(statements.get(0).getValue()).isEqualTo("try(FileInputStreamin=newFileInputStream();FileOutputStreamout=newFileOutputStream();)");
+ assertThat(statements.get(1).getValue()).isEqualTo("{}");
statements = chunk("try (FileInputStream in = new FileInputStream()) { something(); }");
- assertThat(statements.size(), is(2));
- assertThat(statements.get(0).getValue(), is("try(FileInputStreamin=newFileInputStream())"));
- assertThat(statements.get(1).getValue(), is("something()"));
+ assertThat(statements.size()).isEqualTo(2);
+ assertThat(statements.get(0).getValue()).isEqualTo("try(FileInputStreamin=newFileInputStream())");
+ assertThat(statements.get(1).getValue()).isEqualTo("something()");
}
@Test
public void realExamples() {
- assertThat(chunk(DuplicationsTestUtil.findFile("/java/MessageResources.java")).size(), greaterThan(0));
- assertThat(chunk(DuplicationsTestUtil.findFile("/java/RequestUtils.java")).size(), greaterThan(0));
+ assertThat(chunk(DuplicationsTestUtil.findFile("/java/MessageResources.java")).size()).isGreaterThan(0);
+ assertThat(chunk(DuplicationsTestUtil.findFile("/java/RequestUtils.java")).size()).isGreaterThan(0);
}
private List<Statement> chunk(File file) {
diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaTokenProducerTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaTokenProducerTest.java
index 33bf33a0f0a..93ff6fc6c34 100644
--- a/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaTokenProducerTest.java
+++ b/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaTokenProducerTest.java
@@ -37,8 +37,8 @@ import java.io.Reader;
import java.util.Arrays;
import java.util.List;
+import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.is;
-import static org.hamcrest.number.OrderingComparisons.greaterThan;
import static org.junit.Assert.assertThat;
public class JavaTokenProducerTest {
diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/statement/StatementChannelTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/statement/StatementChannelTest.java
index c3f6e6450b8..12d89238fc0 100644
--- a/sonar-duplications/src/test/java/org/sonar/duplications/statement/StatementChannelTest.java
+++ b/sonar-duplications/src/test/java/org/sonar/duplications/statement/StatementChannelTest.java
@@ -19,7 +19,7 @@
*/
package org.sonar.duplications.statement;
-import static org.hamcrest.Matchers.is;
+import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/token/BlackHoleTokenChannelTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/token/BlackHoleTokenChannelTest.java
index 6cbeaeb0145..fa845303942 100644
--- a/sonar-duplications/src/test/java/org/sonar/duplications/token/BlackHoleTokenChannelTest.java
+++ b/sonar-duplications/src/test/java/org/sonar/duplications/token/BlackHoleTokenChannelTest.java
@@ -19,14 +19,13 @@
*/
package org.sonar.duplications.token;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verifyZeroInteractions;
-
import org.junit.Test;
import org.sonar.channel.CodeReader;
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verifyZeroInteractions;
+
public class BlackHoleTokenChannelTest {
@Test
@@ -35,9 +34,9 @@ public class BlackHoleTokenChannelTest {
TokenQueue output = mock(TokenQueue.class);
CodeReader codeReader = new CodeReader("ABCD");
- assertThat(channel.consume(codeReader, output), is(true));
- assertThat(codeReader.getLinePosition(), is(1));
- assertThat(codeReader.getColumnPosition(), is(3));
+ assertThat(channel.consume(codeReader, output)).isTrue();
+ assertThat(codeReader.getLinePosition()).isEqualTo(1);
+ assertThat(codeReader.getColumnPosition()).isEqualTo(3);
verifyZeroInteractions(output);
}