diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2019-12-09 09:34:43 -0600 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2019-12-10 20:46:09 +0100 |
commit | d1fd889554bccbb50122550899dbb66b90b04f78 (patch) | |
tree | 9cad838366292ee79b77ac3513403f7489b06355 /sonar-plugin-api-impl/src/test | |
parent | f86a1094588e4e47b3abf612891af0431653cd0e (diff) | |
download | sonarqube-d1fd889554bccbb50122550899dbb66b90b04f78.tar.gz sonarqube-d1fd889554bccbb50122550899dbb66b90b04f78.zip |
Fix code quality issues and reduce dependency on Guava
Diffstat (limited to 'sonar-plugin-api-impl/src/test')
8 files changed, 19 insertions, 22 deletions
diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/fs/DefaultFileSystemTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/fs/DefaultFileSystemTest.java index 8038cbad3ba..37eaef51f90 100644 --- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/fs/DefaultFileSystemTest.java +++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/fs/DefaultFileSystemTest.java @@ -20,7 +20,7 @@ package org.sonar.api.batch.fs.internal.fs; import java.io.File; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -62,8 +62,8 @@ public class DefaultFileSystemTest { @Test public void test_encoding() throws Exception { - fs.setEncoding(Charset.forName("ISO-8859-1")); - assertThat(fs.encoding()).isEqualTo(Charset.forName("ISO-8859-1")); + fs.setEncoding(StandardCharsets.ISO_8859_1); + assertThat(fs.encoding()).isEqualTo(StandardCharsets.ISO_8859_1); } @Test diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/fs/DefaultInputDirTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/fs/DefaultInputDirTest.java index 531f611bf0e..a17826aaf4a 100644 --- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/fs/DefaultInputDirTest.java +++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/fs/DefaultInputDirTest.java @@ -47,7 +47,7 @@ public class DefaultInputDirTest { } @Test - public void testEqualsAndHashCode() throws Exception { + public void testEqualsAndHashCode() { DefaultInputDir inputDir1 = new DefaultInputDir("ABCDE", "src"); DefaultInputDir inputDir2 = new DefaultInputDir("ABCDE", "src"); diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/fs/DefaultInputFileTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/fs/DefaultInputFileTest.java index 06e341a40b0..605e736f723 100644 --- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/fs/DefaultInputFileTest.java +++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/fs/DefaultInputFileTest.java @@ -33,7 +33,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; -import java.util.function.Consumer; import java.util.stream.Collectors; import org.junit.Before; import org.junit.Rule; @@ -50,7 +49,6 @@ import org.sonar.api.batch.fs.internal.SensorStrategy; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; public class DefaultInputFileTest { @@ -74,7 +72,7 @@ public class DefaultInputFileTest { } @Test - public void test() throws Exception { + public void test() { Metadata metadata = new Metadata(42, 42, "", new int[0], new int[0], 10); DefaultInputFile inputFile = new DefaultInputFile(indexedFile, (f) -> f.setMetadata(metadata)) @@ -152,7 +150,7 @@ public class DefaultInputFileTest { } @Test - public void test_equals_and_hashcode() throws Exception { + public void test_equals_and_hashcode() { DefaultInputFile f1 = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), (f) -> mock(Metadata.class)); DefaultInputFile f1a = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), (f) -> mock(Metadata.class)); DefaultInputFile f2 = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), "src/Bar.php", null), (f) -> mock(Metadata.class)); @@ -168,7 +166,7 @@ public class DefaultInputFileTest { } @Test - public void test_toString() throws Exception { + public void test_toString() { DefaultInputFile file = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), (f) -> mock(Metadata.class)); assertThat(file.toString()).isEqualTo(MODULE_RELATIVE_PATH); } diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/fs/PathPatternTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/fs/PathPatternTest.java index 312e908a700..c20082c1049 100644 --- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/fs/PathPatternTest.java +++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/fs/PathPatternTest.java @@ -59,7 +59,7 @@ public class PathPatternTest { } @Test - public void match_relative_path_and_insensitive_file_extension() throws Exception { + public void match_relative_path_and_insensitive_file_extension() { PathPattern pattern = PathPattern.create("**/*Foo.java"); IndexedFile indexedFile = new DefaultIndexedFile("ABCDE", baseDir, "src/main/java/org/MyFoo.JAVA", null); @@ -70,7 +70,7 @@ public class PathPatternTest { } @Test - public void match_absolute_path() throws Exception { + public void match_absolute_path() { PathPattern pattern = PathPattern.create("file:**/src/main/**Foo.java"); assertThat(pattern.toString()).isEqualTo("file:**/src/main/**Foo.java"); @@ -86,7 +86,7 @@ public class PathPatternTest { } @Test - public void match_absolute_path_and_insensitive_file_extension() throws Exception { + public void match_absolute_path_and_insensitive_file_extension() { PathPattern pattern = PathPattern.create("file:**/src/main/**Foo.java"); assertThat(pattern.toString()).isEqualTo("file:**/src/main/**Foo.java"); diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/predicates/DefaultFilePredicatesTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/predicates/DefaultFilePredicatesTest.java index e47bd8abf1f..d55320b73f4 100644 --- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/predicates/DefaultFilePredicatesTest.java +++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/predicates/DefaultFilePredicatesTest.java @@ -166,7 +166,7 @@ public class DefaultFilePredicatesTest { public void has_languages() { assertThat(predicates.hasLanguages(Arrays.asList("java", "php")).apply(javaFile)).isTrue(); assertThat(predicates.hasLanguages(Arrays.asList("cobol", "php")).apply(javaFile)).isFalse(); - assertThat(predicates.hasLanguages(Collections.<String>emptyList()).apply(javaFile)).isTrue(); + assertThat(predicates.hasLanguages(Collections.emptyList()).apply(javaFile)).isTrue(); } @Test @@ -193,7 +193,7 @@ public class DefaultFilePredicatesTest { // empty assertThat(predicates.and().apply(javaFile)).isTrue(); assertThat(predicates.and(new FilePredicate[0]).apply(javaFile)).isTrue(); - assertThat(predicates.and(Collections.<FilePredicate>emptyList()).apply(javaFile)).isTrue(); + assertThat(predicates.and(Collections.emptyList()).apply(javaFile)).isTrue(); // two arguments assertThat(predicates.and(predicates.all(), predicates.all()).apply(javaFile)).isTrue(); @@ -214,7 +214,7 @@ public class DefaultFilePredicatesTest { // empty assertThat(predicates.or().apply(javaFile)).isTrue(); assertThat(predicates.or(new FilePredicate[0]).apply(javaFile)).isTrue(); - assertThat(predicates.or(Collections.<FilePredicate>emptyList()).apply(javaFile)).isTrue(); + assertThat(predicates.or(Collections.emptyList()).apply(javaFile)).isTrue(); // two arguments assertThat(predicates.or(predicates.all(), predicates.all()).apply(javaFile)).isTrue(); diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/predicates/FilenamePredicateTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/predicates/FilenamePredicateTest.java index 2ec9b1b44b6..1cddd2302f2 100644 --- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/predicates/FilenamePredicateTest.java +++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/predicates/FilenamePredicateTest.java @@ -19,7 +19,6 @@ */ package org.sonar.api.batch.fs.internal.predicates; -import java.io.IOException; import java.util.Collections; import org.junit.Test; import org.sonar.api.batch.fs.FileSystem; @@ -31,7 +30,7 @@ import static org.mockito.Mockito.when; public class FilenamePredicateTest { @Test - public void should_match_file_by_filename() throws IOException { + public void should_match_file_by_filename() { String filename = "some name"; InputFile inputFile = mock(InputFile.class); when(inputFile.filename()).thenReturn(filename); @@ -40,7 +39,7 @@ public class FilenamePredicateTest { } @Test - public void should_not_match_file_by_different_filename() throws IOException { + public void should_not_match_file_by_different_filename() { String filename = "some name"; InputFile inputFile = mock(InputFile.class); when(inputFile.filename()).thenReturn(filename + "x"); @@ -49,7 +48,7 @@ public class FilenamePredicateTest { } @Test - public void should_find_matching_file_in_index() throws IOException { + public void should_find_matching_file_in_index() { String filename = "some name"; InputFile inputFile = mock(InputFile.class); when(inputFile.filename()).thenReturn(filename); diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/impl/utils/ScannerUtilsTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/impl/utils/ScannerUtilsTest.java index 0390d1faf90..13edac978e0 100644 --- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/impl/utils/ScannerUtilsTest.java +++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/impl/utils/ScannerUtilsTest.java @@ -43,7 +43,7 @@ public class ScannerUtilsTest { assertThat(ScannerUtils.describe(new TestClass())).isEqualTo("overridden"); } - class TestClass { + static class TestClass { @Override public String toString() { return "overridden"; diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/impl/utils/WorkDurationTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/impl/utils/WorkDurationTest.java index 3c1e2f971ff..710e3c84bbb 100644 --- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/impl/utils/WorkDurationTest.java +++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/impl/utils/WorkDurationTest.java @@ -178,7 +178,7 @@ public class WorkDurationTest { } @Test - public void test_equals_and_hashcode() throws Exception { + public void test_equals_and_hashcode() { WorkDuration duration = WorkDuration.createFromLong(28800, HOURS_IN_DAY); WorkDuration durationWithSameValue = WorkDuration.createFromLong(28800, HOURS_IN_DAY); WorkDuration durationWithDifferentValue = WorkDuration.createFromLong(14400, HOURS_IN_DAY); @@ -194,7 +194,7 @@ public class WorkDurationTest { } @Test - public void test_toString() throws Exception { + public void test_toString() { assertThat(WorkDuration.createFromLong(28800, HOURS_IN_DAY).toString()).isNotNull(); } } |