aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2019-12-09 09:34:43 -0600
committerSonarTech <sonartech@sonarsource.com>2019-12-10 20:46:09 +0100
commitd1fd889554bccbb50122550899dbb66b90b04f78 (patch)
tree9cad838366292ee79b77ac3513403f7489b06355 /sonar-plugin-api
parentf86a1094588e4e47b3abf612891af0431653cd0e (diff)
downloadsonarqube-d1fd889554bccbb50122550899dbb66b90b04f78.tar.gz
sonarqube-d1fd889554bccbb50122550899dbb66b90b04f78.zip
Fix code quality issues and reduce dependency on Guava
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/CoverageType.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/ce/measure/test/TestMeasure.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java4
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RuleParamType.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/utils/Duration.java6
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/utils/Durations.java10
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/utils/log/DefaultProfiler.java3
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/ce/measure/test/TestComponentTest.java20
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/ce/measure/test/TestIssueTest.java26
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/ce/measure/test/TestMeasureComputerContextTest.java42
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/ce/measure/test/TestMeasureTest.java20
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/ce/measure/test/TestSettingsTest.java4
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/ce/posttask/PostProjectAnalysisTaskTest.java7
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/config/ConfigurationTest.java6
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/profiles/AnnotationProfileParserTest.java19
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileParserTest.java2
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileSerializerTest.java2
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/resources/AbstractLanguageTest.java2
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/server/profile/BuiltInQualityProfilesDefinitionTest.java2
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RuleParamTypeTest.java10
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RuleTagsToTypeConverterTest.java2
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionXmlLoaderTest.java5
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/server/rule/internal/DefaultRepositoryTest.java3
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/user/UserGroupValidationTest.java10
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/user/UserQueryTest.java6
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/utils/FieldUtils2Test.java20
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/utils/System2Test.java9
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/utils/ZipUtilsTest.java2
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/utils/log/DefaultProfilerTest.java2
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/utils/log/LogbackLoggerTest.java1
31 files changed, 113 insertions, 140 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/CoverageType.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/CoverageType.java
index c63f94ce6eb..982bdd51026 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/CoverageType.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/CoverageType.java
@@ -30,6 +30,6 @@ public enum CoverageType {
UNIT,
IT,
- OVERALL;
+ OVERALL
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/ce/measure/test/TestMeasure.java b/sonar-plugin-api/src/main/java/org/sonar/api/ce/measure/test/TestMeasure.java
index 5454dce79e4..16dd1c5e0d7 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/ce/measure/test/TestMeasure.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/ce/measure/test/TestMeasure.java
@@ -60,7 +60,7 @@ public class TestMeasure implements Measure {
public static TestMeasure createMeasure(boolean booleanValue) {
TestMeasure measure = new TestMeasure();
- measure.booleanValue = requireNonNull(booleanValue, "Value cannot be null");
+ measure.booleanValue = booleanValue;
return measure;
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java
index ce894f30de9..eddd2c1bc7f 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java
@@ -344,7 +344,7 @@ public final class PropertyDefinition {
public static final class Result {
private static final Result SUCCESS = new Result(null);
- private String errorKey = null;
+ private String errorKey;
@Nullable
private Result(@Nullable String errorKey) {
@@ -532,7 +532,7 @@ public final class PropertyDefinition {
public Builder options(String first, String... rest) {
this.options.add(first);
- stream(rest).forEach(o -> options.add(o));
+ options.addAll(asList(rest));
return this;
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RuleParamType.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RuleParamType.java
index dc03c136617..b90ac71b386 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RuleParamType.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RuleParamType.java
@@ -64,7 +64,7 @@ public final class RuleParamType {
if (multiple) {
sb.append(OPTION_SEPARATOR);
sb.append(MULTIPLE_PARAM + PARAMETER_SEPARATOR);
- sb.append(Boolean.toString(multiple));
+ sb.append(multiple);
}
if (values.length > 0) {
sb.append(OPTION_SEPARATOR);
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java
index 2fdd1ba58b8..24f629447b6 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java
@@ -499,7 +499,7 @@ public interface RulesDefinition {
}
enum OwaspTop10 {
- A1, A2, A3, A4, A5, A6, A7, A8, A9, A10;
+ A1, A2, A3, A4, A5, A6, A7, A8, A9, A10
}
interface ExtendedRepository {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/Duration.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/Duration.java
index b15337a4a44..3c47010e53a 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/Duration.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/Duration.java
@@ -104,10 +104,10 @@ public class Duration implements Serializable {
*/
public String encode(int hoursInDay) {
int days = ((Double) ((double) durationInMinutes / hoursInDay / MINUTES_IN_ONE_HOUR)).intValue();
- Long remainingDuration = durationInMinutes - (days * hoursInDay * MINUTES_IN_ONE_HOUR);
- int hours = ((Double) (remainingDuration.doubleValue() / MINUTES_IN_ONE_HOUR)).intValue();
+ long remainingDuration = durationInMinutes - (days * hoursInDay * MINUTES_IN_ONE_HOUR);
+ int hours = ((Double) ((double) remainingDuration / MINUTES_IN_ONE_HOUR)).intValue();
remainingDuration = remainingDuration - (hours * MINUTES_IN_ONE_HOUR);
- int minutes = remainingDuration.intValue();
+ int minutes = (int) remainingDuration;
StringBuilder stringBuilder = new StringBuilder();
if (days > 0) {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/Durations.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/Durations.java
index 88c057937a4..3b4618fdabe 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/Durations.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/Durations.java
@@ -104,18 +104,18 @@ public class Durations {
*
*/
public String format(Duration duration) {
- Long durationInMinutes = duration.toMinutes();
+ long durationInMinutes = duration.toMinutes();
if (durationInMinutes == 0) {
return "0";
}
boolean isNegative = durationInMinutes < 0;
- Long absDuration = Math.abs(durationInMinutes);
+ long absDuration = Math.abs(durationInMinutes);
int days = ((Double) ((double) absDuration / HOURS_IN_DAY / 60)).intValue();
- Long remainingDuration = absDuration - (days * HOURS_IN_DAY * 60);
- int hours = ((Double) (remainingDuration.doubleValue() / 60)).intValue();
+ long remainingDuration = absDuration - (days * HOURS_IN_DAY * 60);
+ int hours = ((Double) ((double) remainingDuration / 60)).intValue();
remainingDuration = remainingDuration - (hours * 60);
- int minutes = remainingDuration.intValue();
+ int minutes = (int) remainingDuration;
return format(days, hours, minutes, isNegative);
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/DefaultProfiler.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/DefaultProfiler.java
index 6b62138ed6b..67884ff598e 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/DefaultProfiler.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/DefaultProfiler.java
@@ -25,7 +25,6 @@ import org.sonar.api.utils.System2;
import javax.annotation.Nullable;
import java.util.LinkedHashMap;
import java.util.Map;
-import java.util.Objects;
class DefaultProfiler extends Profiler {
@@ -165,7 +164,7 @@ class DefaultProfiler extends Profiler {
if (sb.length() > 0) {
sb.append(CONTEXT_SEPARATOR);
}
- sb.append(entry.getKey()).append("=").append(Objects.toString(entry.getValue()));
+ sb.append(entry.getKey()).append("=").append(entry.getValue());
}
}
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 2b7cf2f123a..8a63e99b5ca 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
@@ -32,7 +32,7 @@ public class TestComponentTest {
public ExpectedException thrown = ExpectedException.none();
@Test
- public void create_project() throws Exception {
+ public void create_project() {
TestComponent component = new TestComponent("Project", Component.Type.PROJECT, null);
assertThat(component.getKey()).isEqualTo("Project");
@@ -40,7 +40,7 @@ public class TestComponentTest {
}
@Test
- public void create_source_file() throws Exception {
+ public void create_source_file() {
TestComponent component = new TestComponent("File", Component.Type.FILE, new TestComponent.FileAttributesImpl("xoo", false));
assertThat(component.getType()).isEqualTo(Component.Type.FILE);
@@ -49,7 +49,7 @@ public class TestComponentTest {
}
@Test
- public void create_test_file() throws Exception {
+ public void create_test_file() {
TestComponent component = new TestComponent("File", Component.Type.FILE, new TestComponent.FileAttributesImpl(null, true));
assertThat(component.getType()).isEqualTo(Component.Type.FILE);
@@ -58,7 +58,7 @@ public class TestComponentTest {
}
@Test
- public void fail_with_ISE_when_calling_get_file_attributes_on_not_file() throws Exception {
+ public void fail_with_ISE_when_calling_get_file_attributes_on_not_file() {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("Only component of type FILE have a FileAttributes object");
@@ -67,7 +67,7 @@ public class TestComponentTest {
}
@Test
- public void fail_with_IAE_when_trying_to_create_a_file_without_file_attributes() throws Exception {
+ public void fail_with_IAE_when_trying_to_create_a_file_without_file_attributes() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("omponent of type FILE must have a FileAttributes object");
@@ -75,7 +75,7 @@ public class TestComponentTest {
}
@Test
- public void fail_with_IAE_when_trying_to_create_not_a_file_with_file_attributes() throws Exception {
+ public void fail_with_IAE_when_trying_to_create_not_a_file_with_file_attributes() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Only component of type FILE have a FileAttributes object");
@@ -83,7 +83,7 @@ public class TestComponentTest {
}
@Test
- public void fail_with_NPE_when_creating_component_without_key() throws Exception {
+ public void fail_with_NPE_when_creating_component_without_key() {
thrown.expect(NullPointerException.class);
thrown.expectMessage("Key cannot be null");
@@ -91,7 +91,7 @@ public class TestComponentTest {
}
@Test
- public void fail_with_NPE_when_creating_component_without_type() throws Exception {
+ public void fail_with_NPE_when_creating_component_without_type() {
thrown.expect(NullPointerException.class);
thrown.expectMessage("Type cannot be null");
@@ -99,7 +99,7 @@ public class TestComponentTest {
}
@Test
- public void test_equals_and_hashcode() throws Exception {
+ public void test_equals_and_hashcode() {
TestComponent component = new TestComponent("Project1", Component.Type.PROJECT, null);
TestComponent sameComponent = new TestComponent("Project1", Component.Type.PROJECT, null);
TestComponent anotherComponent = new TestComponent("Project2", Component.Type.PROJECT, null);
@@ -115,7 +115,7 @@ public class TestComponentTest {
}
@Test
- public void test_to_string() throws Exception {
+ public void test_to_string() {
assertThat(new TestComponent("File", Component.Type.FILE, new TestComponent.FileAttributesImpl("xoo", true)).toString())
.isEqualTo("ComponentImpl{key=File, type='FILE', fileAttributes=FileAttributesImpl{languageKey='xoo', unitTest=true}}");
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/ce/measure/test/TestIssueTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/ce/measure/test/TestIssueTest.java
index c81d395990c..aeb7ce0a88e 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/ce/measure/test/TestIssueTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/ce/measure/test/TestIssueTest.java
@@ -36,7 +36,7 @@ public class TestIssueTest {
public ExpectedException thrown = ExpectedException.none();
@Test
- public void create_issue() throws Exception {
+ public void create_issue() {
Issue issue = new TestIssue.Builder()
.setKey("ABCD")
.setRuleKey(RuleKey.of("xoo", "S01"))
@@ -56,7 +56,7 @@ public class TestIssueTest {
}
@Test
- public void create_issue_with_minimal_fields() throws Exception {
+ public void create_issue_with_minimal_fields() {
Issue issue = new TestIssue.Builder()
.setKey("ABCD")
.setRuleKey(RuleKey.of("xoo", "S01"))
@@ -70,7 +70,7 @@ public class TestIssueTest {
}
@Test
- public void fail_with_NPE_when_building_issue_without_key() throws Exception {
+ public void fail_with_NPE_when_building_issue_without_key() {
thrown.expect(NullPointerException.class);
thrown.expectMessage("key cannot be null");
@@ -84,7 +84,7 @@ public class TestIssueTest {
}
@Test
- public void fail_with_NPE_when_creating_issue_with_null_key() throws Exception {
+ public void fail_with_NPE_when_creating_issue_with_null_key() {
thrown.expect(NullPointerException.class);
thrown.expectMessage("key cannot be null");
@@ -92,7 +92,7 @@ public class TestIssueTest {
}
@Test
- public void fail_with_NPE_when_building_issue_without_rule_key() throws Exception {
+ public void fail_with_NPE_when_building_issue_without_rule_key() {
thrown.expect(NullPointerException.class);
thrown.expectMessage("ruleKey cannot be null");
@@ -106,7 +106,7 @@ public class TestIssueTest {
}
@Test
- public void fail_with_NPE_when_creating_issue_with_null_rule_key() throws Exception {
+ public void fail_with_NPE_when_creating_issue_with_null_rule_key() {
thrown.expect(NullPointerException.class);
thrown.expectMessage("ruleKey cannot be null");
@@ -114,7 +114,7 @@ public class TestIssueTest {
}
@Test
- public void fail_with_IAE_when_building_issue_with_invalid_resolution() throws Exception {
+ public void fail_with_IAE_when_building_issue_with_invalid_resolution() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("resolution 'unknown' is invalid");
@@ -129,7 +129,7 @@ public class TestIssueTest {
}
@Test
- public void fail_with_NPE_when_building_issue_without_severity() throws Exception {
+ public void fail_with_NPE_when_building_issue_without_severity() {
thrown.expect(NullPointerException.class);
thrown.expectMessage("severity cannot be null");
@@ -143,7 +143,7 @@ public class TestIssueTest {
}
@Test
- public void fail_with_NPE_when_creating_issue_with_null_severity() throws Exception {
+ public void fail_with_NPE_when_creating_issue_with_null_severity() {
thrown.expect(NullPointerException.class);
thrown.expectMessage("severity cannot be null");
@@ -151,7 +151,7 @@ public class TestIssueTest {
}
@Test
- public void fail_with_IAE_when_building_issue_with_invalid_severity() throws Exception {
+ public void fail_with_IAE_when_building_issue_with_invalid_severity() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("severity 'unknown' is invalid");
@@ -166,7 +166,7 @@ public class TestIssueTest {
}
@Test
- public void fail_with_NPE_when_building_issue_without_status() throws Exception {
+ public void fail_with_NPE_when_building_issue_without_status() {
thrown.expect(NullPointerException.class);
thrown.expectMessage("status cannot be null");
@@ -180,7 +180,7 @@ public class TestIssueTest {
}
@Test
- public void fail_with_NPE_when_creating_issue_with_null_status() throws Exception {
+ public void fail_with_NPE_when_creating_issue_with_null_status() {
thrown.expect(NullPointerException.class);
thrown.expectMessage("status cannot be null");
@@ -188,7 +188,7 @@ public class TestIssueTest {
}
@Test
- public void fail_with_IAE_when_building_issue_with_invalid_status() throws Exception {
+ public void fail_with_IAE_when_building_issue_with_invalid_status() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("status 'unknown' is invalid");
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/ce/measure/test/TestMeasureComputerContextTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/ce/measure/test/TestMeasureComputerContextTest.java
index a79f1820d4e..fa0658905e3 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/ce/measure/test/TestMeasureComputerContextTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/ce/measure/test/TestMeasureComputerContextTest.java
@@ -54,52 +54,52 @@ public class TestMeasureComputerContextTest {
TestMeasureComputerContext underTest = new TestMeasureComputerContext(PROJECT, settings, DEFINITION);
@Test
- public void get_component() throws Exception {
+ public void get_component() {
assertThat(underTest.getComponent()).isEqualTo(PROJECT);
}
@Test
- public void get_settings() throws Exception {
+ public void get_settings() {
assertThat(underTest.getSettings()).isEqualTo(settings);
}
@Test
- public void get_int_measure() throws Exception {
+ public void get_int_measure() {
underTest.addInputMeasure(INPUT_METRIC, 10);
assertThat(underTest.getMeasure(INPUT_METRIC).getIntValue()).isEqualTo(10);
}
@Test
- public void get_double_measure() throws Exception {
+ public void get_double_measure() {
underTest.addInputMeasure(INPUT_METRIC, 10d);
assertThat(underTest.getMeasure(INPUT_METRIC).getDoubleValue()).isEqualTo(10d);
}
@Test
- public void get_long_measure() throws Exception {
+ public void get_long_measure() {
underTest.addInputMeasure(INPUT_METRIC, 10L);
assertThat(underTest.getMeasure(INPUT_METRIC).getLongValue()).isEqualTo(10L);
}
@Test
- public void get_string_measure() throws Exception {
+ public void get_string_measure() {
underTest.addInputMeasure(INPUT_METRIC, "text");
assertThat(underTest.getMeasure(INPUT_METRIC).getStringValue()).isEqualTo("text");
}
@Test
- public void get_boolean_measure() throws Exception {
+ public void get_boolean_measure() {
underTest.addInputMeasure(INPUT_METRIC, true);
assertThat(underTest.getMeasure(INPUT_METRIC).getBooleanValue()).isTrue();
}
@Test
- public void fail_with_IAE_when_trying_to_get_measure_on_unknown_metric() throws Exception {
+ public void fail_with_IAE_when_trying_to_get_measure_on_unknown_metric() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Only metrics in [INPUT_METRIC] can be used to load measures");
@@ -107,35 +107,35 @@ public class TestMeasureComputerContextTest {
}
@Test
- public void get_int_children_measures() throws Exception {
+ public void get_int_children_measures() {
underTest.addChildrenMeasures(INPUT_METRIC, 10, 20);
assertThat(underTest.getChildrenMeasures(INPUT_METRIC)).hasSize(2);
}
@Test
- public void get_doublet_children_measures() throws Exception {
+ public void get_doublet_children_measures() {
underTest.addChildrenMeasures(INPUT_METRIC, 10d, 20d);
assertThat(underTest.getChildrenMeasures(INPUT_METRIC)).hasSize(2);
}
@Test
- public void get_long_children_measures() throws Exception {
+ public void get_long_children_measures() {
underTest.addChildrenMeasures(INPUT_METRIC, 10L, 20L);
assertThat(underTest.getChildrenMeasures(INPUT_METRIC)).hasSize(2);
}
@Test
- public void get_string_children_measures() throws Exception {
+ public void get_string_children_measures() {
underTest.addChildrenMeasures(INPUT_METRIC, "value1", "value2");
assertThat(underTest.getChildrenMeasures(INPUT_METRIC)).hasSize(2);
}
@Test
- public void fail_with_IAE_when_trying_to_get_children_measures_on_unknown_metric() throws Exception {
+ public void fail_with_IAE_when_trying_to_get_children_measures_on_unknown_metric() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Only metrics in [INPUT_METRIC] can be used to load measures");
@@ -143,35 +143,35 @@ public class TestMeasureComputerContextTest {
}
@Test
- public void add_int_measure() throws Exception {
+ public void add_int_measure() {
underTest.addMeasure(OUTPUT_METRIC, 10);
assertThat(underTest.getMeasure(OUTPUT_METRIC).getIntValue()).isEqualTo(10);
}
@Test
- public void add_double_measure() throws Exception {
+ public void add_double_measure() {
underTest.addMeasure(OUTPUT_METRIC, 10d);
assertThat(underTest.getMeasure(OUTPUT_METRIC).getDoubleValue()).isEqualTo(10d);
}
@Test
- public void add_long_measure() throws Exception {
+ public void add_long_measure() {
underTest.addMeasure(OUTPUT_METRIC, 10L);
assertThat(underTest.getMeasure(OUTPUT_METRIC).getLongValue()).isEqualTo(10L);
}
@Test
- public void add_string_measure() throws Exception {
+ public void add_string_measure() {
underTest.addMeasure(OUTPUT_METRIC, "text");
assertThat(underTest.getMeasure(OUTPUT_METRIC).getStringValue()).isEqualTo("text");
}
@Test
- public void fail_with_IAE_when_trying_to_add_measure_on_unknown_metric() throws Exception {
+ public void fail_with_IAE_when_trying_to_add_measure_on_unknown_metric() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Only metrics in [OUTPUT_METRIC] can be used to add measures. Metric 'unknown' is not allowed");
@@ -179,7 +179,7 @@ public class TestMeasureComputerContextTest {
}
@Test
- public void fail_with_IAE_when_trying_to_add_measure_on_input_metric() throws Exception {
+ public void fail_with_IAE_when_trying_to_add_measure_on_input_metric() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Only metrics in [OUTPUT_METRIC] can be used to add measures. Metric 'INPUT_METRIC' is not allowed");
@@ -187,7 +187,7 @@ public class TestMeasureComputerContextTest {
}
@Test
- public void fail_with_UOE_when_trying_to_add_same_measures_twice() throws Exception {
+ public void fail_with_UOE_when_trying_to_add_same_measures_twice() {
thrown.expect(UnsupportedOperationException.class);
thrown.expectMessage("A measure on metric 'OUTPUT_METRIC' already exists");
@@ -196,7 +196,7 @@ public class TestMeasureComputerContextTest {
}
@Test
- public void get_issues() throws Exception {
+ public void get_issues() {
Issue issue = new TestIssue.Builder()
.setKey("ABCD")
.setRuleKey(RuleKey.of("xoo", "S01"))
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/ce/measure/test/TestMeasureTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/ce/measure/test/TestMeasureTest.java
index dfc85e07014..664ade7c22d 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/ce/measure/test/TestMeasureTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/ce/measure/test/TestMeasureTest.java
@@ -31,32 +31,32 @@ public class TestMeasureTest {
public ExpectedException thrown = ExpectedException.none();
@Test
- public void create_double_measure() throws Exception {
+ public void create_double_measure() {
assertThat(TestMeasure.createMeasure(10d).getDoubleValue()).isEqualTo(10d);
}
@Test
- public void create_int_measure() throws Exception {
+ public void create_int_measure() {
assertThat(TestMeasure.createMeasure(10).getIntValue()).isEqualTo(10);
}
@Test
- public void create_long_measure() throws Exception {
+ public void create_long_measure() {
assertThat(TestMeasure.createMeasure(10L).getLongValue()).isEqualTo(10L);
}
@Test
- public void create_string_measure() throws Exception {
+ public void create_string_measure() {
assertThat(TestMeasure.createMeasure("value").getStringValue()).isEqualTo("value");
}
@Test
- public void create_boolean_measure() throws Exception {
+ public void create_boolean_measure() {
assertThat(TestMeasure.createMeasure(true).getBooleanValue()).isTrue();
}
@Test
- public void getDoubleValue_fails_with_ISE_when_not_a_double() throws Exception {
+ public void getDoubleValue_fails_with_ISE_when_not_a_double() {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("Not a double measure");
@@ -64,7 +64,7 @@ public class TestMeasureTest {
}
@Test
- public void getIntValue_fails_with_ISE_when_not_an_int() throws Exception {
+ public void getIntValue_fails_with_ISE_when_not_an_int() {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("Not an integer measure");
@@ -72,7 +72,7 @@ public class TestMeasureTest {
}
@Test
- public void getLongValue_fails_with_ISE_when_not_a_long() throws Exception {
+ public void getLongValue_fails_with_ISE_when_not_a_long() {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("Not a long measure");
@@ -80,7 +80,7 @@ public class TestMeasureTest {
}
@Test
- public void getStringValue_fails_with_ISE_when_not_a_string() throws Exception {
+ public void getStringValue_fails_with_ISE_when_not_a_string() {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("Not a string measure");
@@ -88,7 +88,7 @@ public class TestMeasureTest {
}
@Test
- public void getBooleanValue_fails_with_ISE_when_not_a_boolean() throws Exception {
+ public void getBooleanValue_fails_with_ISE_when_not_a_boolean() {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("Not a boolean measure");
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/ce/measure/test/TestSettingsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/ce/measure/test/TestSettingsTest.java
index c58a7e0287f..250960d8759 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/ce/measure/test/TestSettingsTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/ce/measure/test/TestSettingsTest.java
@@ -28,7 +28,7 @@ public class TestSettingsTest {
TestSettings underTest = new TestSettings();
@Test
- public void get_string_value() throws Exception {
+ public void get_string_value() {
underTest.setValue("key", "value");
assertThat(underTest.getString("key")).isEqualTo("value");
@@ -36,7 +36,7 @@ public class TestSettingsTest {
}
@Test
- public void get_string_array_value() throws Exception {
+ public void get_string_array_value() {
underTest.setValue("key", "value1,value2");
assertThat(underTest.getStringArray("key")).containsOnly("value1", "value2");
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/ce/posttask/PostProjectAnalysisTaskTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/ce/posttask/PostProjectAnalysisTaskTest.java
index 0a0573fa145..d3e0be87ae2 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/ce/posttask/PostProjectAnalysisTaskTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/ce/posttask/PostProjectAnalysisTaskTest.java
@@ -36,11 +36,8 @@ public class PostProjectAnalysisTaskTest {
@Test
public void default_implementation_of_finished_ProjectAnalysis_throws_ISE() {
- PostProjectAnalysisTask underTest = new PostProjectAnalysisTask() {
- @Override
- public String getDescription() {
- throw new UnsupportedOperationException("getDescription not implemented");
- }
+ PostProjectAnalysisTask underTest = () -> {
+ throw new UnsupportedOperationException("getDescription not implemented");
};
try {
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/ConfigurationTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/ConfigurationTest.java
index d351bdcf9ad..fc01bf2d43f 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/config/ConfigurationTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/config/ConfigurationTest.java
@@ -104,9 +104,9 @@ public class ConfigurationTest {
String randomKey = RandomStringUtils.randomAlphabetic(3);
String randomNumberOfWhitespaces = StringUtils.repeat(" ", 1 + new Random().nextInt(10));
- assertThat(t.apply(underTest.put(randomKey, randomNumberOfWhitespaces + String.valueOf(value)), randomKey)).isEqualTo(Optional.of(value));
- assertThat(t.apply(underTest.put(randomKey, String.valueOf(value) + randomNumberOfWhitespaces), randomKey)).isEqualTo(Optional.of(value));
- assertThat(t.apply(underTest.put(randomKey, randomNumberOfWhitespaces + String.valueOf(value) + randomNumberOfWhitespaces), randomKey)).isEqualTo(Optional.of(value));
+ assertThat(t.apply(underTest.put(randomKey, randomNumberOfWhitespaces + value), randomKey)).isEqualTo(Optional.of(value));
+ assertThat(t.apply(underTest.put(randomKey, value + randomNumberOfWhitespaces), randomKey)).isEqualTo(Optional.of(value));
+ assertThat(t.apply(underTest.put(randomKey, randomNumberOfWhitespaces + value + randomNumberOfWhitespaces), randomKey)).isEqualTo(Optional.of(value));
}
private static class DumpMapConfiguration implements Configuration {
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/profiles/AnnotationProfileParserTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/profiles/AnnotationProfileParserTest.java
index 0822ab1fa6d..9b6e7a4e913 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/profiles/AnnotationProfileParserTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/profiles/AnnotationProfileParserTest.java
@@ -21,7 +21,6 @@ package org.sonar.api.profiles;
import com.google.common.collect.Lists;
import org.junit.Test;
-import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RuleFinder;
@@ -40,14 +39,11 @@ public class AnnotationProfileParserTest {
@Test
public void shouldParseAnnotatedClasses() {
RuleFinder ruleFinder = mock(RuleFinder.class);
- when(ruleFinder.findByKey(anyString(), anyString())).thenAnswer(new Answer<Rule>() {
- public Rule answer(InvocationOnMock iom) throws Throwable {
- return Rule.create((String) iom.getArguments()[0], (String) iom.getArguments()[1], (String) iom.getArguments()[1]);
- }
- });
+ when(ruleFinder.findByKey(anyString(), anyString())).thenAnswer(
+ (Answer) iom -> Rule.create((String) iom.getArguments()[0], (String) iom.getArguments()[1], (String) iom.getArguments()[1]));
ValidationMessages messages = ValidationMessages.create();
- RulesProfile profile = new AnnotationProfileParser(ruleFinder).parse("squid", "Foo way", "java", Lists.<Class>newArrayList(FakeRule.class), messages);
+ RulesProfile profile = new AnnotationProfileParser(ruleFinder).parse("squid", "Foo way", "java", Lists.newArrayList(FakeRule.class), messages);
assertThat(profile.getName()).isEqualTo("Foo way");
assertThat(profile.getLanguage()).isEqualTo("java");
@@ -58,14 +54,11 @@ public class AnnotationProfileParserTest {
@Test
public void shouldParseOnlyWantedProfile() {
RuleFinder ruleFinder = mock(RuleFinder.class);
- when(ruleFinder.findByKey(anyString(), anyString())).thenAnswer(new Answer<Rule>() {
- public Rule answer(InvocationOnMock iom) throws Throwable {
- return Rule.create((String) iom.getArguments()[0], (String) iom.getArguments()[1], (String) iom.getArguments()[1]);
- }
- });
+ when(ruleFinder.findByKey(anyString(), anyString())).thenAnswer(
+ (Answer<Rule>) iom -> Rule.create((String) iom.getArguments()[0], (String) iom.getArguments()[1], (String) iom.getArguments()[1]));
ValidationMessages messages = ValidationMessages.create();
- RulesProfile profile = new AnnotationProfileParser(ruleFinder).parse("squid", "Foo way", "java", Lists.<Class>newArrayList(FakeRule.class, RuleOnOtherProfile.class), messages);
+ RulesProfile profile = new AnnotationProfileParser(ruleFinder).parse("squid", "Foo way", "java", Lists.newArrayList(FakeRule.class, RuleOnOtherProfile.class), messages);
assertThat(profile.getActiveRule("squid", "fake")).isNotNull();
assertThat(profile.getActiveRule("squid", "other")).isNull();
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileParserTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileParserTest.java
index ad0da0d7af0..b8716632ad1 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileParserTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileParserTest.java
@@ -92,7 +92,7 @@ public class XMLProfileParserTest {
private RuleFinder newRuleFinder() {
RuleFinder ruleFinder = mock(RuleFinder.class);
when(ruleFinder.findByKey(anyString(), anyString())).thenAnswer(new Answer<Rule>() {
- public Rule answer(InvocationOnMock iom) throws Throwable {
+ public Rule answer(InvocationOnMock iom) {
Rule rule = Rule.create((String) iom.getArguments()[0], (String) iom.getArguments()[1], (String) iom.getArguments()[1]);
rule.createParameter("format");
rule.createParameter("message");
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileSerializerTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileSerializerTest.java
index 10628f7d167..4945fe5159a 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileSerializerTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileSerializerTest.java
@@ -70,7 +70,7 @@ public class XMLProfileSerializerTest {
assertSimilarXml("exportRuleParameters.xml", writer.toString());
}
- private void assertSimilarXml(String fileWithExpectedXml, String xml) throws IOException, SAXException {
+ private void assertSimilarXml(String fileWithExpectedXml, String xml) throws IOException {
String pathToExpectedXml = "XMLProfileSerializerTest/" + fileWithExpectedXml;
assertThat(xml).isXmlEqualTo(IOUtils.toString(getClass().getResource(pathToExpectedXml)));
}
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 60ae4bf9de9..cd10a007b68 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
@@ -69,7 +69,7 @@ public class AbstractLanguageTest {
new TooLongKeyLanguage();
}
- class TooLongKeyLanguage extends AbstractLanguage {
+ static class TooLongKeyLanguage extends AbstractLanguage {
public TooLongKeyLanguage() {
super("aKeyWhichIsVeryVeryVeryVeryVeryLong");
}
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 8a39a8eb93f..d0f9e059611 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
@@ -158,7 +158,7 @@ public class BuiltInQualityProfilesDefinitionTest {
return context.profilesByLanguageAndName();
}
- private class FakeProfile implements BuiltInQualityProfilesDefinition {
+ private static class FakeProfile implements BuiltInQualityProfilesDefinition {
private Consumer<Context> consumer;
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 22563a49e4d..284c24ed79c 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
@@ -26,7 +26,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class RuleParamTypeTest {
@Test
- public void testEquals() throws Exception {
+ public void testEquals() {
RuleParamType noOptions = RuleParamType.INTEGER;
RuleParamType withOptions1 = RuleParamType.singleListOfValues("one", "two");
RuleParamType withOptions2 = RuleParamType.singleListOfValues("three", "four");
@@ -47,12 +47,12 @@ public class RuleParamTypeTest {
}
@Test
- public void testHashCode() throws Exception {
+ public void testHashCode() {
assertThat(RuleParamType.INTEGER.hashCode()).isEqualTo(RuleParamType.INTEGER.hashCode());
}
@Test
- public void testInteger() throws Exception {
+ public void testInteger() {
RuleParamType type = RuleParamType.INTEGER;
assertThat(type.toString()).isEqualTo("INTEGER");
assertThat(RuleParamType.parse(type.toString()).type()).isEqualTo("INTEGER");
@@ -61,7 +61,7 @@ public class RuleParamTypeTest {
}
@Test
- public void testListOfValues() throws Exception {
+ public void testListOfValues() {
RuleParamType selectList = RuleParamType.parse("SINGLE_SELECT_LIST,values=\"foo,bar\",");
assertThat(selectList.type()).isEqualTo("SINGLE_SELECT_LIST");
assertThat(selectList.values()).containsOnly("foo", "bar");
@@ -89,7 +89,7 @@ public class RuleParamTypeTest {
}
@Test
- public void testMultipleListOfValues() throws Exception {
+ public void testMultipleListOfValues() {
RuleParamType selectList = RuleParamType.parse("SINGLE_SELECT_LIST,values=\"foo,bar\",multiple=true");
assertThat(selectList.type()).isEqualTo("SINGLE_SELECT_LIST");
assertThat(selectList.values()).containsOnly("foo", "bar");
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RuleTagsToTypeConverterTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RuleTagsToTypeConverterTest.java
index ac20d1742d6..224147a7e54 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RuleTagsToTypeConverterTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RuleTagsToTypeConverterTest.java
@@ -45,7 +45,7 @@ public class RuleTagsToTypeConverterTest {
@Test
public void default_is_code_smell() {
assertThat(convert(asList("clumsy", "spring"))).isEqualTo(RuleType.CODE_SMELL);
- assertThat(convert(Collections.<String>emptyList())).isEqualTo(RuleType.CODE_SMELL);
+ assertThat(convert(Collections.emptyList())).isEqualTo(RuleType.CODE_SMELL);
}
@Test
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionXmlLoaderTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionXmlLoaderTest.java
index 37a06e8f645..23870ccdf3e 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionXmlLoaderTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionXmlLoaderTest.java
@@ -21,7 +21,6 @@ package org.sonar.api.server.rule;
import java.io.InputStream;
import java.io.StringReader;
-import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
@@ -103,7 +102,7 @@ public class RulesDefinitionXmlLoaderTest {
}
@Test
- public void test_utf8_encoding() throws UnsupportedEncodingException {
+ public void test_utf8_encoding() {
InputStream input = getClass().getResourceAsStream("RulesDefinitionXmlLoaderTest/utf8.xml");
RulesDefinition.Repository repository = load(input, StandardCharsets.UTF_8.name());
@@ -132,7 +131,7 @@ public class RulesDefinitionXmlLoaderTest {
}
@Test
- public void test_linear_remediation_function() throws Exception {
+ public void test_linear_remediation_function() {
String xml = "" +
"<rules>" +
" <rule>" +
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/internal/DefaultRepositoryTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/internal/DefaultRepositoryTest.java
index c6f443ceb55..e3be29a4e3c 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/internal/DefaultRepositoryTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/internal/DefaultRepositoryTest.java
@@ -21,6 +21,7 @@ package org.sonar.api.server.rule.internal;
import org.junit.Test;
import org.sonar.api.impl.server.RulesDefinitionContext;
+import org.sonar.api.server.rule.RulesDefinition;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@@ -41,7 +42,7 @@ public class DefaultRepositoryTest {
assertThat(repo.language()).isEqualTo("lang");
assertThat(repo.isExternal()).isFalse();
assertThat(repo.name()).isEqualTo("name");
- assertThat(repo.rules()).extracting(r -> r.key()).containsOnly("rule1");
+ assertThat(repo.rules()).extracting(RulesDefinition.Rule::key).containsOnly("rule1");
}
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/user/UserGroupValidationTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/user/UserGroupValidationTest.java
index 027e7cf820b..5cf2eaeec14 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/user/UserGroupValidationTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/user/UserGroupValidationTest.java
@@ -30,7 +30,7 @@ public class UserGroupValidationTest {
public ExpectedException thrown = ExpectedException.none();
@Test
- public void fail_when_group_name_is_Anyone() throws Exception {
+ public void fail_when_group_name_is_Anyone() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Anyone group cannot be used");
@@ -38,7 +38,7 @@ public class UserGroupValidationTest {
}
@Test
- public void fail_when_group_name_is_empty() throws Exception {
+ public void fail_when_group_name_is_empty() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Group name cannot be empty");
@@ -46,7 +46,7 @@ public class UserGroupValidationTest {
}
@Test
- public void fail_when_group_name_contains_only_blank() throws Exception {
+ public void fail_when_group_name_contains_only_blank() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Group name cannot be empty");
@@ -54,7 +54,7 @@ public class UserGroupValidationTest {
}
@Test
- public void fail_when_group_name_is_too_big() throws Exception {
+ public void fail_when_group_name_is_too_big() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Group name cannot be longer than 255 characters");
@@ -62,7 +62,7 @@ public class UserGroupValidationTest {
}
@Test
- public void fail_when_group_name_is_null() throws Exception {
+ public void fail_when_group_name_is_null() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Group name cannot be empty");
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/user/UserQueryTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/user/UserQueryTest.java
index e97edbc5e77..eb57720a9dd 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/user/UserQueryTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/user/UserQueryTest.java
@@ -30,7 +30,7 @@ import static org.junit.Assert.fail;
public class UserQueryTest {
@Test
- public void test_all_actives() throws Exception {
+ public void test_all_actives() {
assertThat(UserQuery.ALL_ACTIVES.includeDeactivated()).isFalse();
assertThat(UserQuery.ALL_ACTIVES.logins()).isNull();
assertThat(UserQuery.ALL_ACTIVES.searchText()).isNull();
@@ -38,14 +38,14 @@ public class UserQueryTest {
}
@Test
- public void test_all() throws Exception {
+ public void test_all() {
UserQuery all = UserQuery.builder().includeDeactivated().build();
assertThat(all.includeDeactivated()).isTrue();
assertThat(all.logins()).isNull();
}
@Test
- public void test_logins() throws Exception {
+ public void test_logins() {
UserQuery query = UserQuery.builder().logins("simon", "loic").build();
assertThat(query.includeDeactivated()).isFalse();
assertThat(query.logins()).containsOnly("simon", "loic");
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/FieldUtils2Test.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/FieldUtils2Test.java
index a8bb1f612cc..944fd8e1aac 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/FieldUtils2Test.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/FieldUtils2Test.java
@@ -19,16 +19,11 @@
*/
package org.sonar.api.utils;
-import com.google.common.base.Function;
-import com.google.common.collect.Iterables;
-import org.junit.Test;
-
-import javax.annotation.Nullable;
-
import java.lang.reflect.Field;
import java.util.List;
+import java.util.stream.Collectors;
+import org.junit.Test;
-import static com.google.common.collect.Lists.newArrayList;
import static org.assertj.core.api.Assertions.assertThat;
public class FieldUtils2Test {
@@ -82,16 +77,11 @@ public class FieldUtils2Test {
assertThat(fields).contains("INTERFACE_FIELD");
}
- private static List<String> fieldsName(List<Field> fields){
- return newArrayList(Iterables.transform(fields, new Function<Field, String>() {
- @Override
- public String apply(@Nullable Field input) {
- return input != null ? input.getName() : null;
- }
- }));
+ private static List<String> fieldsName(List<Field> fields) {
+ return fields.stream().map(f -> f != null ? f.getName() : null).collect(Collectors.toList());
}
- static interface InterfaceWithFields {
+ interface InterfaceWithFields {
String INTERFACE_FIELD = "foo";
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/System2Test.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/System2Test.java
index ec4d0aac177..9210b27b40f 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/System2Test.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/System2Test.java
@@ -111,7 +111,7 @@ public class System2Test {
boolean isClosed = false;
@Override
- public void close() throws IOException {
+ public void close() {
isClosed = true;
}
}
@@ -123,11 +123,8 @@ public class System2Test {
@Test
public void close_throws_exception_on_error() {
- Closeable closeable = new Closeable() {
- @Override
- public void close() throws IOException {
- throw new IOException("expected");
- }
+ Closeable closeable = () -> {
+ throw new IOException("expected");
};
try {
System2.INSTANCE.close(closeable);
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/ZipUtilsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/ZipUtilsTest.java
index b3c24c13c01..0e7add40c45 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/ZipUtilsTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/ZipUtilsTest.java
@@ -19,7 +19,6 @@
*/
package org.sonar.api.utils;
-import com.google.common.collect.Iterators;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@@ -27,7 +26,6 @@ import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Iterator;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.apache.commons.io.FileUtils;
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/log/DefaultProfilerTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/log/DefaultProfilerTest.java
index 38843fdf122..f5ae62ee079 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/log/DefaultProfilerTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/log/DefaultProfilerTest.java
@@ -33,7 +33,7 @@ public class DefaultProfilerTest {
Profiler underTest = Profiler.create(Loggers.get("DefaultProfilerTest"));
@Test
- public void test_levels() throws Exception {
+ public void test_levels() {
// info by default
assertThat(underTest.isDebugEnabled()).isFalse();
assertThat(underTest.isTraceEnabled()).isFalse();
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/log/LogbackLoggerTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/log/LogbackLoggerTest.java
index 99f8e7edd59..3257055e2b7 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/log/LogbackLoggerTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/log/LogbackLoggerTest.java
@@ -25,7 +25,6 @@ import org.junit.Test;
import org.slf4j.LoggerFactory;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.fail;
public class LogbackLoggerTest {