aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-duplications/src/test/java/org/sonar
diff options
context:
space:
mode:
authorKlaudio Sinani <klaudio.sinani@sonarsource.com>2022-10-26 15:16:57 +0200
committersonartech <sonartech@sonarsource.com>2022-10-28 20:03:23 +0000
commitce409098feab4f5f5ca8168cd995775e1fa32cbb (patch)
treea04c7bf89c2b7792dbed6895b6f3db0fd3171cb1 /sonar-duplications/src/test/java/org/sonar
parent84dfd8b586f0c458d324e815f8b09ce3b395c044 (diff)
downloadsonarqube-ce409098feab4f5f5ca8168cd995775e1fa32cbb.tar.gz
sonarqube-ce409098feab4f5f5ca8168cd995775e1fa32cbb.zip
[NO-JIRA] Fix reported code smells & bugs
Diffstat (limited to 'sonar-duplications/src/test/java/org/sonar')
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/detector/suffixtree/TextSetTest.java38
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/index/CloneGroupTest.java52
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/index/ClonePartTest.java42
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/statement/StatementTest.java21
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/token/TokenTest.java33
5 files changed, 161 insertions, 25 deletions
diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/detector/suffixtree/TextSetTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/detector/suffixtree/TextSetTest.java
new file mode 100644
index 00000000000..1c19aac6de2
--- /dev/null
+++ b/sonar-duplications/src/test/java/org/sonar/duplications/detector/suffixtree/TextSetTest.java
@@ -0,0 +1,38 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.duplications.detector.suffixtree;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class TextSetTest {
+
+ @Test
+ public void test_terminator_equals() {
+ TextSet.Terminator terminator = new TextSet.Terminator(1);
+
+ assertThat(terminator)
+ .isEqualTo(terminator)
+ .isNotEqualTo(null)
+ .isNotEqualTo(new TextSet.Terminator(0))
+ .isEqualTo(new TextSet.Terminator(1));
+ }
+}
diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/index/CloneGroupTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/index/CloneGroupTest.java
new file mode 100644
index 00000000000..54deaf3e479
--- /dev/null
+++ b/sonar-duplications/src/test/java/org/sonar/duplications/index/CloneGroupTest.java
@@ -0,0 +1,52 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.duplications.index;
+
+import java.util.List;
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class CloneGroupTest {
+
+ @Test
+ public void test_equals() {
+ ClonePart clone = new ClonePart("id", 1, 1, 2);
+ CloneGroup group = composeGroup(1, 1, clone, List.of(clone));
+
+ assertThat(group)
+ .isEqualTo(group)
+ .isNotEqualTo(null)
+ .isNotEqualTo(new Object())
+ .isNotEqualTo(composeGroup(1, 1, clone, List.of()))
+ .isNotEqualTo(composeGroup(1, 1, new ClonePart("", 1, 1, 2), List.of(clone)))
+ .isNotEqualTo(composeGroup(0, 1, clone, List.of(clone)))
+ .isEqualTo(composeGroup(1, 1, clone, List.of(new ClonePart("id", 1, 1, 2))));
+ }
+
+ private static CloneGroup composeGroup(int length, int lengthInUnits, ClonePart origin, List<ClonePart> parts) {
+ return CloneGroup.builder()
+ .setLength(length)
+ .setLengthInUnits(lengthInUnits)
+ .setOrigin(origin)
+ .setParts(parts)
+ .build();
+ }
+}
diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/index/ClonePartTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/index/ClonePartTest.java
new file mode 100644
index 00000000000..a004d014352
--- /dev/null
+++ b/sonar-duplications/src/test/java/org/sonar/duplications/index/ClonePartTest.java
@@ -0,0 +1,42 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.duplications.index;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ClonePartTest {
+
+ @Test
+ public void test_equals() {
+ ClonePart part = new ClonePart("id_1", 1, 2, 3);
+
+ assertThat(part)
+ .isEqualTo(part)
+ .isNotEqualTo(null)
+ .isNotEqualTo(new Object())
+ .isNotEqualTo(new ClonePart("id_1", 1, 2, 0))
+ .isNotEqualTo(new ClonePart("id_1", 1, 0, 3))
+ .isNotEqualTo(new ClonePart("id_1", 0, 2, 3))
+ .isNotEqualTo(new ClonePart("id_2", 1, 2, 3))
+ .isEqualTo(new ClonePart("id_1", 1, 2, 3));
+ }
+}
diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/statement/StatementTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/statement/StatementTest.java
index c25f565894e..20517537537 100644
--- a/sonar-duplications/src/test/java/org/sonar/duplications/statement/StatementTest.java
+++ b/sonar-duplications/src/test/java/org/sonar/duplications/statement/StatementTest.java
@@ -19,15 +19,15 @@
*/
package org.sonar.duplications.statement;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
import java.util.ArrayList;
import java.util.Arrays;
-
import org.junit.Test;
import org.sonar.duplications.token.Token;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
public class StatementTest {
@Test(expected = IllegalArgumentException.class)
@@ -48,4 +48,17 @@ public class StatementTest {
assertThat(statement.getEndLine(), is(2));
}
+ @Test
+ public void test_equals() {
+ Statement statement = new Statement(1, 2, "value_1");
+
+ assertThat(statement)
+ .isEqualTo(statement)
+ .isNotEqualTo(null)
+ .isNotEqualTo(new Object())
+ .isNotEqualTo(new Statement(1, 2, "value_2"))
+ .isNotEqualTo(new Statement(1, 0, "value_1"))
+ .isNotEqualTo(new Statement(0, 2, "value_1"))
+ .isEqualTo(new Statement(1, 2, "value_1"));
+ }
}
diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/token/TokenTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/token/TokenTest.java
index 21e22d7c317..3419864be98 100644
--- a/sonar-duplications/src/test/java/org/sonar/duplications/token/TokenTest.java
+++ b/sonar-duplications/src/test/java/org/sonar/duplications/token/TokenTest.java
@@ -19,31 +19,22 @@
*/
package org.sonar.duplications.token;
+import org.assertj.core.api.Assertions;
import org.junit.Test;
-import static org.junit.Assert.assertThat;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.not;
-
public class TokenTest {
@Test
- public void shouldBeEqual() {
- Token firstToken = new Token("MyValue", 1, 3);
- Token secondToken = new Token("MyValue", 1, 3);
-
- assertThat(firstToken, is(secondToken));
+ public void test_equals() {
+ Token token = new Token("value_1", 1, 2);
+
+ Assertions.assertThat(token)
+ .isEqualTo(token)
+ .isNotEqualTo(null)
+ .isNotEqualTo(new Object())
+ .isNotEqualTo(new Token("value_1", 1, 0))
+ .isNotEqualTo(new Token("value_1", 0, 2))
+ .isNotEqualTo(new Token("value_2", 1, 2))
+ .isEqualTo(new Token("value_1", 1, 2));
}
-
- @Test
- public void shouldNotBeEqual() {
- Token firstToken = new Token("MyValue", 1, 3);
- Token secondToken = new Token("MySecondValue", 1, 3);
- Token thirdToken = new Token("MyValue", 3, 3);
-
- assertThat(firstToken, not(is(secondToken)));
- assertThat(firstToken, not(is(thirdToken)));
- }
-
}