aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-duplications
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2021-11-18 16:45:02 -0600
committersonartech <sonartech@sonarsource.com>2021-11-20 20:03:51 +0000
commit3f9445c25962f914ccdd889c002ddd8e19b0cf89 (patch)
treeeb4f34a62b7164a71fd0bbe34d6f59621a687d8d /sonar-duplications
parentaa640be9e2b9cfa2c027ef0768940b31ebb5536c (diff)
downloadsonarqube-3f9445c25962f914ccdd889c002ddd8e19b0cf89.tar.gz
sonarqube-3f9445c25962f914ccdd889c002ddd8e19b0cf89.zip
Improve code quality
Diffstat (limited to 'sonar-duplications')
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/PmdBridgeTest.java6
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/java/JavaStatementBuilderTest.java10
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/token/BlackHoleTokenChannelTest.java2
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/utils/FastStringComparatorTest.java6
4 files changed, 12 insertions, 12 deletions
diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/PmdBridgeTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/PmdBridgeTest.java
index 8c61216c74d..0fb6cfcd450 100644
--- a/sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/PmdBridgeTest.java
+++ b/sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/PmdBridgeTest.java
@@ -54,11 +54,11 @@ public class PmdBridgeTest {
addToIndex(file);
List<CloneGroup> duplications = detect(file);
- assertThat(duplications.size()).isEqualTo(1);
+ assertThat(duplications.size()).isOne();
CloneGroup duplication = duplications.get(0);
assertThat(duplication.getOriginPart().getResourceId()).isEqualTo(file.getAbsolutePath());
- assertThat(duplication.getCloneParts().size()).isEqualTo(2);
+ assertThat(duplication.getCloneParts()).hasSize(2);
assertThat(duplication.getLengthInUnits()).as("length in tokens").isEqualTo(157);
ClonePart part = duplication.getCloneParts().get(0);
@@ -75,7 +75,7 @@ public class PmdBridgeTest {
addToIndex(file2);
List<CloneGroup> duplications = detect(file1);
- assertThat(duplications.size()).isEqualTo(1);
+ assertThat(duplications.size()).isOne();
CloneGroup duplication = duplications.get(0);
assertThat(duplication.getOriginPart().getResourceId()).isEqualTo(file1.getAbsolutePath());
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 29fa86507ed..3d5ac6b95a3 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
@@ -109,7 +109,7 @@ public class JavaStatementBuilderTest {
assertThat(statements.get(1).getValue()).isEqualTo("something()");
statements = chunk("while (true);");
- assertThat(statements.size()).isEqualTo(1);
+ assertThat(statements.size()).isOne();
assertThat(statements.get(0).getValue()).isEqualTo("while(true)");
}
@@ -324,7 +324,7 @@ public class JavaStatementBuilderTest {
public void shouldHandleLambda() {
List<Statement> statements;
statements = chunk("List<String> result = lines.stream().filter(line -> !\"mkyong\".equals(line)).collect(Collectors.toList());");
- assertThat(statements.size()).isEqualTo(1);
+ assertThat(statements.size()).isOne();
assertThat(statements).extracting(Statement::getValue).containsExactly("List<String>result=lines.stream().filter(line->!$CHARS.equals(line)).collect(Collectors.toList())");
statements = chunk("items.forEach((k,v)->{System.out.println(\"Item : \" + k + \" Count : \" + v); if(\"E\".equals(k)) { System.out.println(\"Hello E\");}});");
@@ -358,14 +358,14 @@ public class JavaStatementBuilderTest {
public void shouldHandleVar() {
List<Statement> statements;
statements = chunk("IFunc f = (@NonNull var x, final var y) -> Foo.foo(x, y);");
- assertThat(statements.size()).isEqualTo(1);
+ assertThat(statements.size()).isOne();
assertThat(statements).extracting(Statement::getValue).containsExactly("IFuncf=(@NonNullvarx,finalvary)->Foo.foo(x,y)");
}
@Test
public void realExamples() {
- assertThat(chunk(DuplicationsTestUtil.findFile("/java/MessageResources.java")).size()).isGreaterThan(0);
- assertThat(chunk(DuplicationsTestUtil.findFile("/java/RequestUtils.java")).size()).isGreaterThan(0);
+ assertThat(chunk(DuplicationsTestUtil.findFile("/java/MessageResources.java")).size()).isPositive();
+ assertThat(chunk(DuplicationsTestUtil.findFile("/java/RequestUtils.java")).size()).isPositive();
}
private List<Statement> chunk(File file) {
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 bf5e5fa5d92..3395d8ce50c 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
@@ -35,7 +35,7 @@ public class BlackHoleTokenChannelTest {
CodeReader codeReader = new CodeReader("ABCD");
assertThat(channel.consume(codeReader, output)).isTrue();
- assertThat(codeReader.getLinePosition()).isEqualTo(1);
+ assertThat(codeReader.getLinePosition()).isOne();
assertThat(codeReader.getColumnPosition()).isEqualTo(3);
verifyZeroInteractions(output);
}
diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/utils/FastStringComparatorTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/utils/FastStringComparatorTest.java
index 1540bfcf323..72d33faf891 100644
--- a/sonar-duplications/src/test/java/org/sonar/duplications/utils/FastStringComparatorTest.java
+++ b/sonar-duplications/src/test/java/org/sonar/duplications/utils/FastStringComparatorTest.java
@@ -34,9 +34,9 @@ public class FastStringComparatorTest {
String s1 = "Od";
String s2 = "PE";
- assertThat(s1.hashCode()).isEqualTo(s2.hashCode());
+ assertThat(s1).hasSameHashCodeAs(s2);
assertThat(compare(s1, s2)).isLessThan(0);
- assertThat(compare(s2, s1)).isGreaterThan(0);
+ assertThat(compare(s2, s1)).isPositive();
}
@Test
@@ -46,7 +46,7 @@ public class FastStringComparatorTest {
assertThat(s1.hashCode()).isNotEqualTo(s2.hashCode());
assertThat(compare(s1, s2)).isEqualTo(-1);
- assertThat(compare(s2, s1)).isEqualTo(1);
+ assertThat(compare(s2, s1)).isOne();
}
@Test