aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src/test/java/org/sonar/api
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-plugin-api/src/test/java/org/sonar/api
parentaa640be9e2b9cfa2c027ef0768940b31ebb5536c (diff)
downloadsonarqube-3f9445c25962f914ccdd889c002ddd8e19b0cf89.tar.gz
sonarqube-3f9445c25962f914ccdd889c002ddd8e19b0cf89.zip
Improve code quality
Diffstat (limited to 'sonar-plugin-api/src/test/java/org/sonar/api')
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/scm/BlameLineTest.java4
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/ce/measure/test/TestComponentTest.java14
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/config/EmailSettingsTest.java2
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionsTest.java26
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/database/model/UserTest.java2
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/measures/MetricTest.java2
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/resources/AbstractLanguageTest.java5
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceTypeTest.java2
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/rule/RuleKeyTest.java13
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/security/ExternalGroupsProviderTest.java3
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/security/UserDetailsTest.java6
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/server/debt/DefaultDebtRemediationFunctionTest.java20
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/server/profile/BuiltInQualityProfilesDefinitionTest.java5
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RuleParamTypeTest.java6
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/server/ws/RequestTest.java19
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/task/TaskDefinitionTest.java17
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/utils/DurationTest.java2
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/utils/KeyValueFormatTest.java20
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/utils/ManifestUtilsTest.java6
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/utils/PagingTest.java2
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/utils/VersionTest.java6
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/utils/command/CommandTest.java2
22 files changed, 90 insertions, 94 deletions
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/scm/BlameLineTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/scm/BlameLineTest.java
index 50feaeccbb7..c8da8e1374e 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/scm/BlameLineTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/scm/BlameLineTest.java
@@ -19,11 +19,9 @@
*/
package org.sonar.api.batch.scm;
-import java.util.Calendar;
import org.junit.Test;
import java.util.Date;
-import org.junit.jupiter.api.Assertions;
import static org.assertj.core.api.Assertions.assertThat;
@@ -52,7 +50,7 @@ public class BlameLineTest {
assertThat(line1)
.isEqualTo(line1)
- .isNotEqualTo(null)
+ .isNotNull()
.isEqualTo(line2)
.isNotEqualTo(line3)
.hasSameHashCodeAs(line2);
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/ce/measure/test/TestComponentTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/ce/measure/test/TestComponentTest.java
index 653a4bab15b..d4b3d0c6b37 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/ce/measure/test/TestComponentTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/ce/measure/test/TestComponentTest.java
@@ -96,13 +96,13 @@ public class TestComponentTest {
TestComponent sameComponent = new TestComponent("Project1", Component.Type.PROJECT, null);
TestComponent anotherComponent = new TestComponent("Project2", Component.Type.PROJECT, null);
- assertThat(component).isEqualTo(component);
- assertThat(component).isEqualTo(sameComponent);
- assertThat(component).isNotEqualTo(anotherComponent);
- assertThat(component).isNotEqualTo(null);
-
- assertThat(component.hashCode()).isEqualTo(component.hashCode());
- assertThat(component.hashCode()).isEqualTo(sameComponent.hashCode());
+ assertThat(component)
+ .isEqualTo(component)
+ .isEqualTo(sameComponent)
+ .isNotEqualTo(anotherComponent)
+ .isNotNull()
+ .hasSameHashCodeAs(component)
+ .hasSameHashCodeAs(sameComponent);
assertThat(component.hashCode()).isNotEqualTo(anotherComponent.hashCode());
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/EmailSettingsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/EmailSettingsTest.java
index 5aed83ef381..c7d1c8d131a 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/config/EmailSettingsTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/config/EmailSettingsTest.java
@@ -36,7 +36,7 @@ public class EmailSettingsTest {
@Test
public void should_return_default_values() {
- assertThat(underTest.getSmtpHost()).isEqualTo("");
+ assertThat(underTest.getSmtpHost()).isEmpty();
assertThat(underTest.getSmtpPort()).isEqualTo(25);
assertThat(underTest.getSmtpUsername()).isEmpty();
assertThat(underTest.getSmtpPassword()).isEmpty();
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionsTest.java
index 82d3b378255..e792fcddb79 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionsTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionsTest.java
@@ -89,7 +89,7 @@ public class PropertyDefinitionsTest {
PropertyDefinitions def = new PropertyDefinitions(System2.INSTANCE, Categories.class);
assertThat(def.getCategory("inCateg")).isEqualTo("categ");
- assertThat(def.getCategory("noCateg")).isEqualTo("");
+ assertThat(def.getCategory("noCateg")).isEmpty();
}
@Test
@@ -114,11 +114,11 @@ public class PropertyDefinitionsTest {
public void should_return_special_categories() {
PropertyDefinitions def = new PropertyDefinitions(System2.INSTANCE);
- assertThat(def.propertiesByCategory(null).get(new Category("general")).keySet()).containsOnly(new SubCategory("email"));
+ assertThat(def.propertiesByCategory(null).get(new Category("general"))).containsOnlyKeys(new SubCategory("email"));
assertThat(def.propertiesByCategory(null).get(new Category("general")).keySet().iterator().next().isSpecial()).isTrue();
- assertThat(def.propertiesByCategory(null).get(new Category("security")).keySet()).containsOnly(new SubCategory("encryption"));
+ assertThat(def.propertiesByCategory(null).get(new Category("security"))).containsOnlyKeys(new SubCategory("encryption"));
assertThat(def.propertiesByCategory(null).get(new Category("security")).keySet().iterator().next().isSpecial()).isTrue();
- assertThat(def.propertiesByCategory(null).get(new Category("licenses")).keySet()).containsOnly(new SubCategory("server_id"));
+ assertThat(def.propertiesByCategory(null).get(new Category("licenses"))).containsOnlyKeys(new SubCategory("server_id"));
assertThat(def.propertiesByCategory(null).get(new Category("licenses")).keySet().iterator().next().isSpecial()).isTrue();
}
@@ -134,10 +134,10 @@ public class PropertyDefinitionsTest {
PropertyDefinition.builder("app").name("Application").category("catApp").onlyOnQualifiers(Qualifiers.APP).build());
assertThat(def.propertiesByCategory(null).keySet()).contains(new Category("catGlobal1"), new Category("catGlobal2"));
- assertThat(def.propertiesByCategory(Qualifiers.PROJECT).keySet()).containsOnly(new Category("catProject"));
- assertThat(def.propertiesByCategory(Qualifiers.MODULE).keySet()).containsOnly(new Category("catModule"));
- assertThat(def.propertiesByCategory(Qualifiers.VIEW).keySet()).containsOnly(new Category("catView"));
- assertThat(def.propertiesByCategory(Qualifiers.APP).keySet()).containsOnly(new Category("catApp"));
+ assertThat(def.propertiesByCategory(Qualifiers.PROJECT)).containsOnlyKeys(new Category("catProject"));
+ assertThat(def.propertiesByCategory(Qualifiers.MODULE)).containsOnlyKeys(new Category("catModule"));
+ assertThat(def.propertiesByCategory(Qualifiers.VIEW)).containsOnlyKeys(new Category("catView"));
+ assertThat(def.propertiesByCategory(Qualifiers.APP)).containsOnlyKeys(new Category("catApp"));
assertThat(def.propertiesByCategory("Unkown").keySet()).isEmpty();
}
@@ -149,9 +149,9 @@ public class PropertyDefinitionsTest {
PropertyDefinition.builder("global3").name("Global3").category("catGlobal1").build(),
PropertyDefinition.builder("global4").name("Global4").category("catGlobal2").build());
- assertThat(def.propertiesByCategory(null).get(new Category("catGlobal1")).keySet()).containsOnly(new SubCategory("catGlobal1"), new SubCategory("sub1"),
+ assertThat(def.propertiesByCategory(null).get(new Category("catGlobal1"))).containsOnlyKeys(new SubCategory("catGlobal1"), new SubCategory("sub1"),
new SubCategory("sub2"));
- assertThat(def.propertiesByCategory(null).get(new Category("catGlobal2")).keySet()).containsOnly(new SubCategory("catGlobal2"));
+ assertThat(def.propertiesByCategory(null).get(new Category("catGlobal2"))).containsOnlyKeys(new SubCategory("catGlobal2"));
}
@Test
@@ -159,8 +159,8 @@ public class PropertyDefinitionsTest {
PropertyDefinitions def = new PropertyDefinitions(System2.INSTANCE, ByCategory.class);
assertThat(def.propertiesByCategory(null).keySet()).contains(new Category("catglobal1"), new Category("catglobal2"));
- assertThat(def.propertiesByCategory(Qualifiers.PROJECT).keySet()).containsOnly(new Category("catproject"));
- assertThat(def.propertiesByCategory(Qualifiers.MODULE).keySet()).containsOnly(new Category("catmodule"));
+ assertThat(def.propertiesByCategory(Qualifiers.PROJECT)).containsOnlyKeys(new Category("catproject"));
+ assertThat(def.propertiesByCategory(Qualifiers.MODULE)).containsOnlyKeys(new Category("catmodule"));
}
private void assertProperties(PropertyDefinitions definitions) {
@@ -172,7 +172,7 @@ public class PropertyDefinitionsTest {
assertThat(definitions.getDefaultValue("foo")).isNull();
assertThat(definitions.getDefaultValue("two")).isEqualTo("2");
- assertThat(definitions.getAll().size()).isEqualTo(3);
+ assertThat(definitions.getAll()).hasSize(3);
}
@Test
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/database/model/UserTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/database/model/UserTest.java
index e712c56e55f..242b74add09 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/database/model/UserTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/database/model/UserTest.java
@@ -50,6 +50,6 @@ public class UserTest {
assertThat(one.equals(new User().setLogin("one"))).isTrue();
assertThat(one.equals(two)).isFalse();
- assertThat(one.hashCode()).isEqualTo(new User().setLogin("one").hashCode());
+ assertThat(one).hasSameHashCodeAs(new User().setLogin("one"));
}
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/measures/MetricTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/measures/MetricTest.java
index b321ec2add9..9f913d79c26 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/measures/MetricTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/measures/MetricTest.java
@@ -97,7 +97,7 @@ public class MetricTest {
public void default_decimal_scale_is_1() {
Metric metric = new Metric.Builder("foo", "Foo", Metric.ValueType.FLOAT)
.create();
- assertThat(metric.getDecimalScale()).isEqualTo(1);
+ assertThat(metric.getDecimalScale()).isOne();
}
@Test
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/AbstractLanguageTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/resources/AbstractLanguageTest.java
index 5f5a58cc2f8..d1fd1d782de 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/AbstractLanguageTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/resources/AbstractLanguageTest.java
@@ -54,8 +54,9 @@ public class AbstractLanguageTest {
}
})).isTrue();
- assertThat(lang1.hashCode()).isEqualTo(lang1.hashCode());
- assertThat(lang1.hashCode()).isEqualTo(new Language1Too().hashCode());
+ assertThat(lang1)
+ .hasSameHashCodeAs(lang1)
+ .hasSameHashCodeAs(new Language1Too());
}
@Test
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceTypeTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceTypeTest.java
index d5bffb66bad..5662332ac70 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceTypeTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceTypeTest.java
@@ -64,7 +64,7 @@ public class ResourceTypeTest {
assertThat(foo1.equals(foo2)).isTrue();
assertThat(foo1.equals(bar)).isFalse();
- assertThat(foo1.hashCode()).isEqualTo(foo1.hashCode());
+ assertThat(foo1).hasSameHashCodeAs(foo1);
}
@Test
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/rule/RuleKeyTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/rule/RuleKeyTest.java
index c6ae3f964cd..d0a48b647d0 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/rule/RuleKeyTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/rule/RuleKeyTest.java
@@ -114,12 +114,13 @@ public class RuleKeyTest {
RuleKey key2 = RuleKey.of("squid", "NullDeref");
RuleKey key3 = RuleKey.of("squid", "Other");
- assertThat(key1).isEqualTo(key1);
- assertThat(key1).isEqualTo(key2);
- assertThat(key1).isNotEqualTo(key3);
- assertThat(key1).isNotEqualTo(null);
- assertThat(key1.hashCode()).isEqualTo(key1.hashCode());
- assertThat(key1.hashCode()).isEqualTo(key2.hashCode());
+ assertThat(key1)
+ .isEqualTo(key1)
+ .isEqualTo(key2)
+ .isNotEqualTo(key3)
+ .isNotNull()
+ .hasSameHashCodeAs(key1)
+ .hasSameHashCodeAs(key2);
}
@Test
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/security/ExternalGroupsProviderTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/security/ExternalGroupsProviderTest.java
index bd1bc4c722f..bec30c145ef 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/security/ExternalGroupsProviderTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/security/ExternalGroupsProviderTest.java
@@ -81,8 +81,7 @@ public class ExternalGroupsProviderTest {
private static void addUserGroupMapping(Map<String, Collection<String>> userGroupsMap, String user, @Nullable String[] groups) {
Collection<String> groupsCollection = null;
if (groups != null) {
- groupsCollection = new ArrayList<>();
- groupsCollection.addAll(Arrays.asList(groups));
+ groupsCollection = Arrays.asList(groups);
}
userGroupsMap.put(user, groupsCollection);
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/security/UserDetailsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/security/UserDetailsTest.java
index f8d3ef158c1..ec4d1796716 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/security/UserDetailsTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/security/UserDetailsTest.java
@@ -38,7 +38,7 @@ public class UserDetailsTest {
assertThat(userDetails.getName()).isNull();
userDetails.setName("");
- assertThat(userDetails.getName()).isEqualTo("");
+ assertThat(userDetails.getName()).isEmpty();
userDetails.setName("foo");
assertThat(userDetails.getName()).isEqualTo("foo");
@@ -50,7 +50,7 @@ public class UserDetailsTest {
assertThat(userDetails.getEmail()).isNull();
userDetails.setEmail("");
- assertThat(userDetails.getEmail()).isEqualTo("");
+ assertThat(userDetails.getEmail()).isEmpty();
userDetails.setEmail("foo@example.com");
assertThat(userDetails.getEmail()).isEqualTo("foo@example.com");
@@ -62,7 +62,7 @@ public class UserDetailsTest {
assertThat(userDetails.getUserId()).isNull();
userDetails.setUserId("");
- assertThat(userDetails.getUserId()).isEqualTo("");
+ assertThat(userDetails.getUserId()).isEmpty();
userDetails.setUserId("foo@example");
assertThat(userDetails.getUserId()).isEqualTo("foo@example");
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/server/debt/DefaultDebtRemediationFunctionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/server/debt/DefaultDebtRemediationFunctionTest.java
index 28b527dd471..ca9bedfe942 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/server/debt/DefaultDebtRemediationFunctionTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/server/debt/DefaultDebtRemediationFunctionTest.java
@@ -135,17 +135,15 @@ public class DefaultDebtRemediationFunctionTest {
DebtRemediationFunction functionWithSameValue = new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET, "10h", "5min");
DebtRemediationFunction functionWithDifferentType = new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.CONSTANT_ISSUE, null, "5min");
- assertThat(function).isEqualTo(function);
- assertThat(function).isEqualTo(functionWithSameValue);
- assertThat(function).isNotEqualTo(functionWithDifferentType);
-
- assertThat(function).isNotEqualTo(new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET, "11h", "5min"));
- assertThat(function).isNotEqualTo(new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET, "10h", "6min"));
- assertThat(function).isNotEqualTo(new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.LINEAR, "10h", null));
- assertThat(function).isNotEqualTo(new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.CONSTANT_ISSUE, null, "6min"));
-
- assertThat(function.hashCode()).isEqualTo(function.hashCode());
- assertThat(function.hashCode()).isEqualTo(functionWithSameValue.hashCode());
+ assertThat(function).isEqualTo(function)
+ .isEqualTo(functionWithSameValue)
+ .isNotEqualTo(functionWithDifferentType)
+ .isNotEqualTo(new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET, "11h", "5min"))
+ .isNotEqualTo(new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET, "10h", "6min"))
+ .isNotEqualTo(new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.LINEAR, "10h", null))
+ .isNotEqualTo(new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.CONSTANT_ISSUE, null, "6min"))
+ .hasSameHashCodeAs(function)
+ .hasSameHashCodeAs(functionWithSameValue);
assertThat(function.hashCode()).isNotEqualTo(functionWithDifferentType.hashCode());
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/server/profile/BuiltInQualityProfilesDefinitionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/server/profile/BuiltInQualityProfilesDefinitionTest.java
index 947980d6d8f..5786b7564b5 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/server/profile/BuiltInQualityProfilesDefinitionTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/server/profile/BuiltInQualityProfilesDefinitionTest.java
@@ -22,6 +22,7 @@ package org.sonar.api.server.profile;
import java.util.Map;
import java.util.function.Consumer;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.BuiltInQualityProfile;
import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInActiveRule;
@@ -41,9 +42,7 @@ public class BuiltInQualityProfilesDefinitionTest {
@Test
public void createEmptyProfile() {
- Map<String, Map<String, BuiltInQualityProfile>> profiles = define(c -> {
- c.createBuiltInQualityProfile("Foo", "xoo").done();
- });
+ Map<String, Map<String, BuiltInQualityProfile>> profiles = define(c -> c.createBuiltInQualityProfile("Foo", "xoo").done());
assertThat(profiles).containsOnlyKeys("xoo");
assertThat(profiles.get("xoo")).containsOnlyKeys("Foo");
BuiltInQualityProfile profile = profiles.get("xoo").get("Foo");
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RuleParamTypeTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RuleParamTypeTest.java
index 12407c279f4..18dbd684629 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RuleParamTypeTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RuleParamTypeTest.java
@@ -36,19 +36,19 @@ public class RuleParamTypeTest {
.isNotEqualTo(RuleParamType.STRING)
.isNotEqualTo("INTEGER")
.isNotEqualTo(withOptions1)
- .isNotEqualTo(null);
+ .isNotNull();
assertThat(withOptions1)
.isEqualTo(withOptions1)
.isNotEqualTo(noOptions)
.isNotEqualTo(withOptions2)
.isNotEqualTo("SINGLE_SELECT_LIST,values=one,two,")
- .isNotEqualTo(null);
+ .isNotNull();
}
@Test
public void testHashCode() {
- assertThat(RuleParamType.INTEGER.hashCode()).isEqualTo(RuleParamType.INTEGER.hashCode());
+ assertThat(RuleParamType.INTEGER).hasSameHashCodeAs(RuleParamType.INTEGER);
}
@Test
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/RequestTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/RequestTest.java
index b5409eb8173..fb0c5c48eb5 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/RequestTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/RequestTest.java
@@ -333,8 +333,8 @@ public class RequestTest {
assertThat(stringParam.isPresent()).isTrue();
expectSupplierCanNotBeNullNPE(() -> stringParam.or(null));
- assertThat(stringParam.or(() -> "foo")).isEqualTo("");
- assertThat(stringParam.getValue()).isEqualTo("");
+ assertThat(stringParam.or(() -> "foo")).isEmpty();
+ assertThat(stringParam.getValue()).isEmpty();
Request.StringParam emptyAsNull = stringParam.emptyAsNull();
assertThat(emptyAsNull).isNotSameAs(stringParam);
@@ -370,7 +370,7 @@ public class RequestTest {
Request.StringParam stringParam = underTest.getParam("a_string", (str) -> calls.incrementAndGet());
- assertThat(calls.get()).isEqualTo(1);
+ assertThat(calls.get()).isOne();
assertThat(stringParam.isPresent()).isTrue();
expectSupplierCanNotBeNullNPE(() -> stringParam.or(null));
assertThat(stringParam.or(() -> "foo")).isEqualTo("sorry");
@@ -391,11 +391,11 @@ public class RequestTest {
Request.StringParam stringParam = underTest.getParam("a_string", (str) -> calls.incrementAndGet());
- assertThat(calls.get()).isEqualTo(1);
+ assertThat(calls.get()).isOne();
assertThat(stringParam.isPresent()).isTrue();
expectSupplierCanNotBeNullNPE(() -> stringParam.or(null));
- assertThat(stringParam.or(() -> "foo")).isEqualTo("");
- assertThat(stringParam.getValue()).isEqualTo("");
+ assertThat(stringParam.or(() -> "foo")).isEmpty();
+ assertThat(stringParam.getValue()).isEmpty();
Request.StringParam emptyAsNull = stringParam.emptyAsNull();
assertThat(emptyAsNull).isNotSameAs(stringParam);
@@ -639,7 +639,7 @@ public class RequestTest {
@Override
public boolean hasParam(String key) {
- return params.keySet().contains(key);
+ return params.containsKey(key);
}
@Override
@@ -698,11 +698,6 @@ public class RequestTest {
public Optional<String> header(String name) {
return Optional.ofNullable(headers.get(name));
}
-
- public FakeRequest setHeader(String name, String value) {
- headers.put(name, value);
- return this;
- }
}
private static class FakeWs implements WebService {
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/task/TaskDefinitionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/task/TaskDefinitionTest.java
index a844a754c67..6106a51bb12 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/task/TaskDefinitionTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/task/TaskDefinitionTest.java
@@ -41,14 +41,17 @@ public class TaskDefinitionTest {
TaskDefinition def1bis = TaskDefinition.builder().key("one").taskClass(FooTask.class).description("Foo").build();
TaskDefinition def2 = TaskDefinition.builder().key("two").taskClass(FooTask.class).description("Foo").build();
- assertThat(def1).isEqualTo(def1);
- assertThat(def1).isEqualTo(def1bis);
- assertThat(def2).isNotEqualTo(def1);
- assertThat(def2).isNotEqualTo("one");
- assertThat(def2).isNotEqualTo(null);
+ assertThat(def1)
+ .isEqualTo(def1)
+ .isEqualTo(def1bis);
+ assertThat(def2)
+ .isNotEqualTo(def1)
+ .isNotEqualTo("one")
+ .isNotNull();
- assertThat(def1.hashCode()).isEqualTo(def1.hashCode());
- assertThat(def1.hashCode()).isEqualTo(def1bis.hashCode());
+ assertThat(def1)
+ .hasSameHashCodeAs(def1)
+ .hasSameHashCodeAs(def1bis);
}
@Test
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/DurationTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/DurationTest.java
index 28b86d006f7..9b56669d10d 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/DurationTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/DurationTest.java
@@ -133,7 +133,7 @@ public class DurationTest {
.isEqualTo(duration)
.isEqualTo(durationWithSameValue)
.isNotEqualTo(durationWithDifferentValue)
- .isNotEqualTo(null)
+ .isNotNull()
.hasSameHashCodeAs(duration);
assertThat(durationWithSameValue).hasSameHashCodeAs(duration);
assertThat(durationWithDifferentValue.hashCode()).isNotEqualTo(duration.hashCode());
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/KeyValueFormatTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/KeyValueFormatTest.java
index 34d68a1e16a..9a94cbbe534 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/KeyValueFormatTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/KeyValueFormatTest.java
@@ -52,7 +52,7 @@ public class KeyValueFormatTest {
reader = new KeyValueFormat.FieldParser("abc=;ghi=jkl");
assertThat(reader.nextKey()).isEqualTo("abc");
- assertThat(reader.nextVal()).isEqualTo("");
+ assertThat(reader.nextVal()).isEmpty();
assertThat(reader.nextKey()).isEqualTo("ghi");
assertThat(reader.nextVal()).isEqualTo("jkl");
assertThat(reader.nextKey()).isNull();
@@ -86,7 +86,7 @@ public class KeyValueFormatTest {
reader = new KeyValueFormat.FieldParser("abc=;def=");
assertThat(reader.nextKey()).isEqualTo("abc");
- assertThat(reader.nextVal()).isEqualTo("");
+ assertThat(reader.nextVal()).isEmpty();
assertThat(reader.nextKey()).isEqualTo("def");
assertThat(reader.nextVal()).isNull();
@@ -138,7 +138,7 @@ public class KeyValueFormatTest {
public void shouldFormatBlank() {
Map<Integer, String> map = new TreeMap<>();
String s = KeyValueFormat.formatIntString(map);
- assertThat(s).isEqualTo("");
+ assertThat(s).isEmpty();
}
@Test
@@ -155,8 +155,9 @@ public class KeyValueFormatTest {
public void shouldParseStrings() {
Map<String, String> map = KeyValueFormat.parse("one=un;two=deux");
assertThat(map.size()).isEqualTo(2);
- assertThat(map.get("one")).isEqualTo("un");
- assertThat(map.get("two")).isEqualTo("deux");
+ assertThat(map)
+ .containsEntry("one", "un")
+ .containsEntry("two", "deux");
assertThat(map.keySet().iterator().next()).isEqualTo("one");// same order as in string
}
@@ -207,7 +208,7 @@ public class KeyValueFormatTest {
@Test
public void convert_deprecated_priority() {
assertThat(KeyValueFormat.newPriorityConverter().format(RulePriority.BLOCKER)).isEqualTo("BLOCKER");
- assertThat(KeyValueFormat.newPriorityConverter().format(null)).isEqualTo("");
+ assertThat(KeyValueFormat.newPriorityConverter().format(null)).isEmpty();
assertThat(KeyValueFormat.newPriorityConverter().parse("MAJOR")).isEqualTo(RulePriority.MAJOR);
assertThat(KeyValueFormat.newPriorityConverter().parse("")).isNull();
@@ -223,9 +224,10 @@ public class KeyValueFormatTest {
assertThat(csv).isEqualTo("foo=\"a=b=c\";bar=\"a;b;c\";baz=double\"quote");
Map<String, String> output = KeyValueFormat.parse(csv);
- assertThat(output.get("foo")).isEqualTo("a=b=c");
- assertThat(output.get("bar")).isEqualTo("a;b;c");
- assertThat(output.get("baz")).isEqualTo("double\"quote");
+ assertThat(output)
+ .containsEntry("foo", "a=b=c")
+ .containsEntry("bar", "a;b;c")
+ .containsEntry("baz", "double\"quote");
}
@Test
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/ManifestUtilsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/ManifestUtilsTest.java
index 86613fd0677..5f5a3552872 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/ManifestUtilsTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/ManifestUtilsTest.java
@@ -46,7 +46,7 @@ public class ManifestUtilsTest {
Manifest mf = new Manifest();
File jar = createJar(mf, "emptyManifest.jar");
- URLClassLoader classloader = new URLClassLoader(FileUtils.toURLs(new File[]{jar}));
+ URLClassLoader classloader = new URLClassLoader(FileUtils.toURLs(jar));
assertThat(ManifestUtils.getPropertyValues(classloader, "foo")).isEmpty();
}
@@ -57,7 +57,7 @@ public class ManifestUtilsTest {
mf.getMainAttributes().putValue("other", "value");
File jar = createJar(mf, "singleManifest.jar");
- URLClassLoader classloader = new URLClassLoader(FileUtils.toURLs(new File[]{jar}));
+ URLClassLoader classloader = new URLClassLoader(FileUtils.toURLs(jar));
List<String> values = ManifestUtils.getPropertyValues(classloader, "foo");
assertThat(values).containsOnly("bar");
}
@@ -72,7 +72,7 @@ public class ManifestUtilsTest {
mf2.getMainAttributes().putValue("foo", "otherbar");
File jar2 = createJar(mf2, "manyManifests-two.jar");
- URLClassLoader classloader = new URLClassLoader(FileUtils.toURLs(new File[]{jar1, jar2}));
+ URLClassLoader classloader = new URLClassLoader(FileUtils.toURLs(jar1, jar2));
List<String> values = ManifestUtils.getPropertyValues(classloader, "foo");
assertThat(values).containsOnly("bar", "otherbar");
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/PagingTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/PagingTest.java
index c761ffb58fe..11e1279f65c 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/PagingTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/PagingTest.java
@@ -32,7 +32,7 @@ public class PagingTest {
Paging paging = forPageIndex(1).withPageSize(5).andTotal(20);
assertThat(paging.pageSize()).isEqualTo(5);
- assertThat(paging.pageIndex()).isEqualTo(1);
+ assertThat(paging.pageIndex()).isOne();
assertThat(paging.total()).isEqualTo(20);
assertThat(paging.offset()).isZero();
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/VersionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/VersionTest.java
index ed2907cd713..ce2d101c97b 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/VersionTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/VersionTest.java
@@ -65,9 +65,9 @@ public class VersionTest {
@Test
public void test_hashCode() {
- assertThat(parse("1").hashCode()).isEqualTo(parse("1").hashCode());
- assertThat(parse("1").hashCode()).isEqualTo(parse("1.0.0").hashCode());
- assertThat(parse("1.2.3-beta1").hashCode()).isEqualTo(parse("1.2.3").hashCode());
+ assertThat(parse("1")).hasSameHashCodeAs(parse("1"));
+ assertThat(parse("1")).hasSameHashCodeAs(parse("1.0.0"));
+ assertThat(parse("1.2.3-beta1")).hasSameHashCodeAs(parse("1.2.3"));
}
@Test
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/command/CommandTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/command/CommandTest.java
index dff18017318..c0255718b63 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/command/CommandTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/command/CommandTest.java
@@ -97,7 +97,7 @@ public class CommandTest {
Command command = new Command("java", system);
command.setEnvironmentVariable("JAVA_HOME", "/new/path/to/java");
- assertThat(command.getEnvironmentVariables().get("JAVA_HOME")).isEqualTo("/new/path/to/java");
+ assertThat(command.getEnvironmentVariables()).containsEntry("JAVA_HOME", "/new/path/to/java");
}
@Test