From a53ee332e87bc82a5bf284c9dab8c437cfa55e6e Mon Sep 17 00:00:00 2001 From: leonardo-pilastri-sonarsource <115481625+leonardo-pilastri-sonarsource@users.noreply.github.com> Date: Thu, 20 Jun 2024 11:18:49 +0200 Subject: [PATCH] [NO JIRA] Improve test code quality (#4824) Fix quality gate after more rules enabled on test code --- .../com/sonar/it/java/suite/JavaTest.java | 7 ++- .../sonar/it/java/suite/Struts139Test.java | 6 +- .../com/sonar/it/java/suite/TestUtils.java | 4 +- .../org/sonar/java/it/JavaRulingTest.java | 4 +- .../internal/CheckVerifierTestUtils.java | 2 +- .../ForLoopIncrementAndUpdateCheckTest.java | 2 +- .../SubClassStaticReferenceCheckTest.java | 4 +- .../checks/design/BrainMethodCheckTest.java | 16 +++--- .../checks/helpers/HashCacheTestHelper.java | 14 ++--- .../checks/tests/AssertionTypesCheckTest.java | 10 ++-- ...DefaultPackageClassAndMethodCheckTest.java | 6 +- .../model/ExpressionUtilsTestSample.java | 17 ++++++ .../model/expression/ClassWithConstants.java | 0 .../java/DefaultJavaResourceLocatorTest.java | 2 +- .../java/org/sonar/java/JavaFrontendTest.java | 36 ++++++------ .../sonar/java/ast/JavaAstScannerTest.java | 4 +- .../visitors/SonarSymbolTableVisitorTest.java | 3 - .../SyntaxHighlighterVisitorTest.java | 11 ---- .../test/java/org/sonar/java/cfg/CFGTest.java | 1 + .../sonar/java/model/ExpressionUtilsTest.java | 18 +----- .../sonar/java/model/JParserSemanticTest.java | 10 ++-- .../org/sonar/java/model/JParserTest.java | 2 +- .../java/org/sonar/java/model/JUtilsTest.java | 4 +- .../java/model/SyntacticEquivalenceTest.java | 1 - .../sonar/java/model/VisitorsBridgeTest.java | 4 +- .../AssessableExpressionTreeTest.java | 2 +- .../model/location/InternalRangeTest.java | 16 +++--- .../ContinueStatementTreeImplTest.java | 7 +-- .../org/sonar/java/regex/RegexCheckTest.java | 56 +++++++++---------- .../testing/VisitorsBridgeForTestsTest.java | 1 + .../model/SEExpressionUtilsTestSample.java | 24 ++++++++ .../java/model/SEExpressionUtilsTest.java | 23 +------- .../java/se/xproc/HappyPathYieldTest.java | 8 +-- .../java/se/xproc/MethodBehaviorTest.java | 4 +- 34 files changed, 160 insertions(+), 169 deletions(-) create mode 100644 java-frontend/src/test/files/model/ExpressionUtilsTestSample.java rename java-frontend/src/test/{java/org/sonar/java => files}/model/expression/ClassWithConstants.java (100%) create mode 100644 java-symbolic-execution/java-symbolic-execution-plugin/src/test/files/model/SEExpressionUtilsTestSample.java diff --git a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/JavaTest.java b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/JavaTest.java index 090e826fc85..316b72670b6 100644 --- a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/JavaTest.java +++ b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/JavaTest.java @@ -32,6 +32,7 @@ import org.junit.rules.TemporaryFolder; import org.sonarqube.ws.Components; import org.sonarqube.ws.Issues.Issue; + import static com.sonar.it.java.suite.JavaTestSuite.getComponent; import static com.sonar.it.java.suite.JavaTestSuite.getMeasureAsInteger; import static org.assertj.core.api.Assertions.assertThat; @@ -152,12 +153,12 @@ public void support_change_of_extension_property() { @Test public void should_execute_rule_on_test() throws Exception { - MavenLocation junit_4_11 = MavenLocation.of("junit", "junit", "4.11"); - orchestrator.getConfiguration().locators().copyToDirectory(junit_4_11, tmp.getRoot()); + MavenLocation junit411 = MavenLocation.of("junit", "junit", "4.11"); + orchestrator.getConfiguration().locators().copyToDirectory(junit411, tmp.getRoot()); MavenBuild build = MavenBuild.create() .setPom(TestUtils.projectPom("java-inner-classes")) .setProperty("sonar.java.test.binaries", "target/test-classes") - .setProperty("sonar.java.test.libraries", new File(tmp.getRoot(), junit_4_11.getFilename()).getAbsolutePath()) + .setProperty("sonar.java.test.libraries", new File(tmp.getRoot(), junit411.getFilename()).getAbsolutePath()) .setCleanPackageSonarGoals(); TestUtils.provisionProject(orchestrator, "org.sonarsource.it.projects:java-inner-classes", "java-inner-classes", "java", "ignored-test-check"); orchestrator.executeBuild(build); diff --git a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/Struts139Test.java b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/Struts139Test.java index 2fb2ddf077a..34c3cbaac86 100644 --- a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/Struts139Test.java +++ b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/Struts139Test.java @@ -84,9 +84,9 @@ public void unit_test_metrics() { public void complexity_metrics() { assertThat(getMeasureAsInteger(PROJECT_STRUTS, "complexity")).isEqualTo(5589); - int expected_statements = 12103; - expected_statements += 3; // empty statements in type declaration or member of classes in struts-1.3.9 - assertThat(getMeasureAsInteger(PROJECT_STRUTS, "statements")).isEqualTo(expected_statements); + int expectedStatements = 12103; + expectedStatements += 3; // empty statements in type declaration or member of classes in struts-1.3.9 + assertThat(getMeasureAsInteger(PROJECT_STRUTS, "statements")).isEqualTo(expectedStatements); } private static String componentKey(String path, String file) { diff --git a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/TestUtils.java b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/TestUtils.java index 36765603852..e85ae34d1a9 100644 --- a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/TestUtils.java +++ b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/TestUtils.java @@ -90,8 +90,8 @@ static WsClient newAdminWsClient(Orchestrator orchestrator) { .build()); } - public static void provisionProject(Orchestrator ORCHESTRATOR, String projectKey, String projectName, String languageKey, String profileName) { - Server server = ORCHESTRATOR.getServer(); + public static void provisionProject(Orchestrator orchestrator, String projectKey, String projectName, String languageKey, String profileName) { + Server server = orchestrator.getServer(); server.provisionProject(projectKey, projectName); server.associateProjectToQualityProfile(projectKey, languageKey, profileName); } diff --git a/its/ruling/src/test/java/org/sonar/java/it/JavaRulingTest.java b/its/ruling/src/test/java/org/sonar/java/it/JavaRulingTest.java index ac733fc4b25..388b42158c9 100644 --- a/its/ruling/src/test/java/org/sonar/java/it/JavaRulingTest.java +++ b/its/ruling/src/test/java/org/sonar/java/it/JavaRulingTest.java @@ -83,7 +83,7 @@ public class JavaRulingTest { ); @ClassRule - public static TemporaryFolder TMP_DUMP_OLD_FOLDER = new TemporaryFolder(); + public static TemporaryFolder tmpDumpOldFolder = new TemporaryFolder(); private static Path effectiveDumpOldFolder; @@ -159,7 +159,7 @@ private static void prepareDumpOldFolder() throws Exception { if (SUBSET_OF_ENABLED_RULES.isEmpty()) { effectiveDumpOldFolder = allRulesFolder.toAbsolutePath(); } else { - effectiveDumpOldFolder = TMP_DUMP_OLD_FOLDER.getRoot().toPath().toAbsolutePath(); + effectiveDumpOldFolder = tmpDumpOldFolder.getRoot().toPath().toAbsolutePath(); Files.list(allRulesFolder) .filter(p -> p.toFile().isDirectory()) .forEach(srcProjectDir -> copyDumpSubset(srcProjectDir, effectiveDumpOldFolder.resolve(srcProjectDir.getFileName()))); diff --git a/java-checks-testkit/src/test/java/org/sonar/java/checks/verifier/internal/CheckVerifierTestUtils.java b/java-checks-testkit/src/test/java/org/sonar/java/checks/verifier/internal/CheckVerifierTestUtils.java index 06a2d07dc6f..48208554ec2 100644 --- a/java-checks-testkit/src/test/java/org/sonar/java/checks/verifier/internal/CheckVerifierTestUtils.java +++ b/java-checks-testkit/src/test/java/org/sonar/java/checks/verifier/internal/CheckVerifierTestUtils.java @@ -68,7 +68,7 @@ public void scanFile(JavaFileScannerContext context) { } @Rule(key = "NoEffectCheck") - protected final static class NoEffectCheck implements JavaFileScanner { + protected static final class NoEffectCheck implements JavaFileScanner { @Override public void scanFile(JavaFileScannerContext context) { diff --git a/java-checks/src/test/java/org/sonar/java/checks/ForLoopIncrementAndUpdateCheckTest.java b/java-checks/src/test/java/org/sonar/java/checks/ForLoopIncrementAndUpdateCheckTest.java index c6651cc840b..8ec81bed9a3 100644 --- a/java-checks/src/test/java/org/sonar/java/checks/ForLoopIncrementAndUpdateCheckTest.java +++ b/java-checks/src/test/java/org/sonar/java/checks/ForLoopIncrementAndUpdateCheckTest.java @@ -23,7 +23,7 @@ import org.sonar.java.checks.verifier.CheckVerifier; import static org.sonar.java.checks.verifier.TestUtils.mainCodeSourcesPath; -import static org.sonar.java.checks.verifier.TestUtils.nonCompilingTestSourcesPath;; +import static org.sonar.java.checks.verifier.TestUtils.nonCompilingTestSourcesPath; class ForLoopIncrementAndUpdateCheckTest { diff --git a/java-checks/src/test/java/org/sonar/java/checks/SubClassStaticReferenceCheckTest.java b/java-checks/src/test/java/org/sonar/java/checks/SubClassStaticReferenceCheckTest.java index 50dbe729877..fdc9bdb7e45 100644 --- a/java-checks/src/test/java/org/sonar/java/checks/SubClassStaticReferenceCheckTest.java +++ b/java-checks/src/test/java/org/sonar/java/checks/SubClassStaticReferenceCheckTest.java @@ -26,12 +26,12 @@ class SubClassStaticReferenceCheckTest { - private static final String filename = mainCodeSourcesPath("checks/SubClassStaticReferenceCheckSample.java"); + private static final String FILENAME = mainCodeSourcesPath("checks/SubClassStaticReferenceCheckSample.java"); @Test void detected() { CheckVerifier.newVerifier() - .onFile(filename) + .onFile(FILENAME) .withCheck(new SubClassStaticReferenceCheck()) .verifyIssues(); } diff --git a/java-checks/src/test/java/org/sonar/java/checks/design/BrainMethodCheckTest.java b/java-checks/src/test/java/org/sonar/java/checks/design/BrainMethodCheckTest.java index e5efa525cc5..95932e268e0 100644 --- a/java-checks/src/test/java/org/sonar/java/checks/design/BrainMethodCheckTest.java +++ b/java-checks/src/test/java/org/sonar/java/checks/design/BrainMethodCheckTest.java @@ -26,14 +26,14 @@ class BrainMethodCheckTest { - private static final String highComplexityFilePath = mainCodeSourcesPath("checks/BrainMethodCheckSample.java"); - private static final String lowComplexityFilePath = mainCodeSourcesPath("checks/BrainMethodCheckLowerThresholds.java"); - private static final String subsetFilePath = mainCodeSourcesPath("checks/BrainMethodCheckSubsetOfIssues.java"); + private static final String HIGH_COMPLEXITY_FILE_PATH = mainCodeSourcesPath("checks/BrainMethodCheckSample.java"); + private static final String LOW_COMPLEXITY_FILE_PATH = mainCodeSourcesPath("checks/BrainMethodCheckLowerThresholds.java"); + private static final String SUBSET_FILE_PATH = mainCodeSourcesPath("checks/BrainMethodCheckSubsetOfIssues.java"); @Test void testHighComplexityFileWithDefaultThresholds() { CheckVerifier.newVerifier() - .onFile(highComplexityFilePath) + .onFile(HIGH_COMPLEXITY_FILE_PATH) .withChecks(new BrainMethodCheck()) .verifyIssues(); } @@ -48,7 +48,7 @@ void testHighComplexityFileWithHigherThresholds() { check.cyclomaticThreshold = 45; CheckVerifier.newVerifier() - .onFile(highComplexityFilePath) + .onFile(HIGH_COMPLEXITY_FILE_PATH) .withChecks(check) .verifyNoIssues(); } @@ -56,7 +56,7 @@ void testHighComplexityFileWithHigherThresholds() { @Test void testLowComplexityFileWithDefaultThresholds() { CheckVerifier.newVerifier() - .onFile(lowComplexityFilePath) + .onFile(LOW_COMPLEXITY_FILE_PATH) .withChecks(new BrainMethodCheck()) .verifyNoIssues(); } @@ -70,7 +70,7 @@ void testLowComplexityFileWithLowerThresholds() { check.cyclomaticThreshold = 5; CheckVerifier.newVerifier() - .onFile(lowComplexityFilePath) + .onFile(LOW_COMPLEXITY_FILE_PATH) .withChecks(check) .verifyIssues(); } @@ -87,7 +87,7 @@ void testSubsetOfIssuesWithLowerThresholds() { check.numberOfIssuesToReport = 1; CheckVerifier.newVerifier() - .onFile(subsetFilePath) + .onFile(SUBSET_FILE_PATH) .withChecks(check) .verifyIssues(); } diff --git a/java-checks/src/test/java/org/sonar/java/checks/helpers/HashCacheTestHelper.java b/java-checks/src/test/java/org/sonar/java/checks/helpers/HashCacheTestHelper.java index 5c8b2bcb964..6005c369735 100644 --- a/java-checks/src/test/java/org/sonar/java/checks/helpers/HashCacheTestHelper.java +++ b/java-checks/src/test/java/org/sonar/java/checks/helpers/HashCacheTestHelper.java @@ -19,17 +19,16 @@ */ package org.sonar.java.checks.helpers; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.sensor.cache.ReadCache; -import org.sonar.java.caching.FileHashingUtils; -import org.sonar.java.checks.verifier.internal.InternalInputFile; -import org.sonar.java.checks.verifier.internal.InternalReadCache; - import java.io.File; import java.io.IOException; import java.security.NoSuchAlgorithmException; import java.util.Arrays; import java.util.Collection; +import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.batch.sensor.cache.ReadCache; +import org.sonar.java.caching.FileHashingUtils; +import org.sonar.java.checks.verifier.internal.InternalInputFile; +import org.sonar.java.checks.verifier.internal.InternalReadCache; public class HashCacheTestHelper { @@ -49,8 +48,7 @@ public static String contentHashKey(InputFile inputFile) { public static ReadCache internalReadCacheFromFile(String path) throws NoSuchAlgorithmException, IOException { InputFile cachedFile = inputFileFromPath(path); byte[] cachedHash = FileHashingUtils.inputFileContentHash(cachedFile); - InternalReadCache localReadCache = new InternalReadCache().put(contentHashKey(cachedFile), cachedHash); - return localReadCache; + return new InternalReadCache().put(contentHashKey(cachedFile), cachedHash); } public static ReadCache internalReadCacheFromFiles(Collection paths) throws NoSuchAlgorithmException, IOException { diff --git a/java-checks/src/test/java/org/sonar/java/checks/tests/AssertionTypesCheckTest.java b/java-checks/src/test/java/org/sonar/java/checks/tests/AssertionTypesCheckTest.java index 2b66af9d760..a36c5a9f9ab 100644 --- a/java-checks/src/test/java/org/sonar/java/checks/tests/AssertionTypesCheckTest.java +++ b/java-checks/src/test/java/org/sonar/java/checks/tests/AssertionTypesCheckTest.java @@ -114,11 +114,11 @@ void arguments_of_unknown_method() { @Test void wrapper_type_with_invalid_primitive() { - Type invalid_primitive = mock(Type.class); - when(invalid_primitive.isPrimitive()).thenReturn(true); - when(invalid_primitive.fullyQualifiedName()).thenReturn("invalid_name"); - Type type = AssertionTypesCheck.wrapperType(invalid_primitive); - assertThat(type).isSameAs(invalid_primitive); + Type invalidPrimitive = mock(Type.class); + when(invalidPrimitive.isPrimitive()).thenReturn(true); + when(invalidPrimitive.fullyQualifiedName()).thenReturn("invalid_name"); + Type type = AssertionTypesCheck.wrapperType(invalidPrimitive); + assertThat(type).isSameAs(invalidPrimitive); } } diff --git a/java-checks/src/test/java/org/sonar/java/checks/tests/JUnit5DefaultPackageClassAndMethodCheckTest.java b/java-checks/src/test/java/org/sonar/java/checks/tests/JUnit5DefaultPackageClassAndMethodCheckTest.java index ef40a0f198c..2268864811d 100644 --- a/java-checks/src/test/java/org/sonar/java/checks/tests/JUnit5DefaultPackageClassAndMethodCheckTest.java +++ b/java-checks/src/test/java/org/sonar/java/checks/tests/JUnit5DefaultPackageClassAndMethodCheckTest.java @@ -26,12 +26,12 @@ class JUnit5DefaultPackageClassAndMethodCheckTest { - private static final String testSourcePath = testCodeSourcesPath("checks/tests/JUnit5DefaultPackageClassAndMethodCheckSample.java"); + private static final String TEST_SOURCE_PATH = testCodeSourcesPath("checks/tests/JUnit5DefaultPackageClassAndMethodCheckSample.java"); @Test void test() { CheckVerifier.newVerifier() - .onFile(testSourcePath) + .onFile(TEST_SOURCE_PATH) .withCheck(new JUnit5DefaultPackageClassAndMethodCheck()) .verifyIssues(); } @@ -39,7 +39,7 @@ void test() { @Test void test_without_semantic() { CheckVerifier.newVerifier() - .onFile(testSourcePath) + .onFile(TEST_SOURCE_PATH) .withCheck(new JUnit5DefaultPackageClassAndMethodCheck()) .withoutSemantic() .verifyNoIssues(); diff --git a/java-frontend/src/test/files/model/ExpressionUtilsTestSample.java b/java-frontend/src/test/files/model/ExpressionUtilsTestSample.java new file mode 100644 index 00000000000..f538b816769 --- /dev/null +++ b/java-frontend/src/test/files/model/ExpressionUtilsTestSample.java @@ -0,0 +1,17 @@ +class ExpressionUtilsTestSample { + + private boolean parenthesis(boolean b1, boolean b2) { + return (((b1 && (b2)))); + } + + private void simpleAssignment() { + int x; + x = 14; + (x) = 14; + x += 1; + + int[] y = new int[5]; + y[x] = 42; + } + +} diff --git a/java-frontend/src/test/java/org/sonar/java/model/expression/ClassWithConstants.java b/java-frontend/src/test/files/model/expression/ClassWithConstants.java similarity index 100% rename from java-frontend/src/test/java/org/sonar/java/model/expression/ClassWithConstants.java rename to java-frontend/src/test/files/model/expression/ClassWithConstants.java diff --git a/java-frontend/src/test/java/org/sonar/java/DefaultJavaResourceLocatorTest.java b/java-frontend/src/test/java/org/sonar/java/DefaultJavaResourceLocatorTest.java index 012feb3f92d..415a7c112de 100644 --- a/java-frontend/src/test/java/org/sonar/java/DefaultJavaResourceLocatorTest.java +++ b/java-frontend/src/test/java/org/sonar/java/DefaultJavaResourceLocatorTest.java @@ -133,7 +133,7 @@ class B { Object obj = new I() { @Override public void foo() { - + // empty implementation } }; } diff --git a/java-frontend/src/test/java/org/sonar/java/JavaFrontendTest.java b/java-frontend/src/test/java/org/sonar/java/JavaFrontendTest.java index 576522dbacb..67360924f43 100644 --- a/java-frontend/src/test/java/org/sonar/java/JavaFrontendTest.java +++ b/java-frontend/src/test/java/org/sonar/java/JavaFrontendTest.java @@ -735,35 +735,35 @@ void batch_generator_returns_batches_with_multiple_files_that_are_smaller_than_b sensorContext = SensorContextTester.create(baseDir); sensorContext.setSettings(new MapSettings()); } - InputFile A = addFile("class A { public void doSomething() {} }", sensorContext); - InputFile B = addFile("class B extends A {}", sensorContext); - InputFile C = addFile("class C {}", sensorContext); + InputFile fileA = addFile("class A { public void doSomething() {} }", sensorContext); + InputFile fileB = addFile("class B extends A {}", sensorContext); + InputFile fileC = addFile("class C {}", sensorContext); - long sizeofA = A.file().length() + 1; + long sizeofA = fileA.file().length() + 1; JavaFrontend.BatchGenerator generator = new JavaFrontend.BatchGenerator( - Arrays.asList(A, B, C).iterator(), sizeofA + Arrays.asList(fileA, fileB, fileC).iterator(), sizeofA ); assertThat(generator.hasNext()).isTrue(); - assertThat(generator.next()).hasSize(1).contains(A); + assertThat(generator.next()).hasSize(1).contains(fileA); assertThat(generator.hasNext()).isTrue(); List batchWithMultipleFiles = generator.next(); - assertThat(batchWithMultipleFiles).hasSize(2).contains(B).contains(C); + assertThat(batchWithMultipleFiles).hasSize(2).contains(fileB).contains(fileC); long batchSize = batchWithMultipleFiles.stream().map(i -> i.file().length()).reduce(0L, Long::sum); assertThat(batchSize).isLessThanOrEqualTo(sizeofA); assertThat(generator.hasNext()).isFalse(); assertThat(generator.next()).isEmpty(); - long sizeOfAPlusB = A.file().length() + B.file().length(); + long sizeOfAPlusB = fileA.file().length() + fileB.file().length(); generator = new JavaFrontend.BatchGenerator( - Arrays.asList(A, B, C).iterator(), sizeOfAPlusB + Arrays.asList(fileA, fileB, fileC).iterator(), sizeOfAPlusB ); assertThat(generator.hasNext()).isTrue(); batchWithMultipleFiles = generator.next(); - assertThat(batchWithMultipleFiles).hasSize(2).contains(A).contains(B); + assertThat(batchWithMultipleFiles).hasSize(2).contains(fileA).contains(fileB); batchSize = batchWithMultipleFiles.stream().map(i -> i.file().length()).reduce(0L, Long::sum); assertThat(batchSize).isLessThanOrEqualTo(sizeOfAPlusB); assertThat(generator.hasNext()).isTrue(); - assertThat(generator.next()).hasSize(1).contains(C); + assertThat(generator.next()).hasSize(1).contains(fileC); assertThat(generator.hasNext()).isFalse(); assertThat(generator.next()).isEmpty(); } @@ -775,18 +775,18 @@ void batch_generator_includes_file_excluded_from_previous_batch_into_next_batch( sensorContext = SensorContextTester.create(baseDir); sensorContext.setSettings(new MapSettings()); } - InputFile A = addFile("class A { public void doSomething() {} }", sensorContext); - InputFile B = addFile("class B extends A {}", sensorContext); - InputFile C = addFile("class C {}", sensorContext); + InputFile fileA = addFile("class A { public void doSomething() {} }", sensorContext); + InputFile fileB = addFile("class B extends A {}", sensorContext); + InputFile fileC = addFile("class C {}", sensorContext); JavaFrontend.BatchGenerator generator = new JavaFrontend.BatchGenerator( - Arrays.asList(A, C, B).iterator(), C.file().length() + Arrays.asList(fileA, fileC, fileB).iterator(), fileC.file().length() ); assertThat(generator.hasNext()).isTrue(); - assertThat(generator.next()).hasSize(1).contains(A); + assertThat(generator.next()).hasSize(1).contains(fileA); assertThat(generator.hasNext()).isTrue(); - assertThat(generator.next()).hasSize(1).contains(C); + assertThat(generator.next()).hasSize(1).contains(fileC); assertThat(generator.hasNext()).isTrue(); - assertThat(generator.next()).hasSize(1).contains(B); + assertThat(generator.next()).hasSize(1).contains(fileB); assertThat(generator.hasNext()).isFalse(); assertThat(generator.next()).isEmpty(); } diff --git a/java-frontend/src/test/java/org/sonar/java/ast/JavaAstScannerTest.java b/java-frontend/src/test/java/org/sonar/java/ast/JavaAstScannerTest.java index 3eac5806057..105319246d7 100644 --- a/java-frontend/src/test/java/org/sonar/java/ast/JavaAstScannerTest.java +++ b/java-frontend/src/test/java/org/sonar/java/ast/JavaAstScannerTest.java @@ -498,15 +498,17 @@ private static class FakeAuditListener implements JavaFileScanner, ExceptionHand @Override public void processRecognitionException(RecognitionException e) { + // empty implementation } @Override public void processException(Exception e) { + // empty implementation } @Override public void scanFile(JavaFileScannerContext context) { - + // empty implementation } } diff --git a/java-frontend/src/test/java/org/sonar/java/ast/visitors/SonarSymbolTableVisitorTest.java b/java-frontend/src/test/java/org/sonar/java/ast/visitors/SonarSymbolTableVisitorTest.java index d60a25cb59b..0c9b734b75e 100644 --- a/java-frontend/src/test/java/org/sonar/java/ast/visitors/SonarSymbolTableVisitorTest.java +++ b/java-frontend/src/test/java/org/sonar/java/ast/visitors/SonarSymbolTableVisitorTest.java @@ -19,9 +19,7 @@ */ package org.sonar.java.ast.visitors; -import com.google.common.io.Files; import java.io.File; -import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.Collections; import org.junit.Rule; @@ -52,7 +50,6 @@ class SonarSymbolTableVisitorTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); - private static final String EOL = "\n"; private SensorContextTester context; private SonarComponents sonarComponents; diff --git a/java-frontend/src/test/java/org/sonar/java/ast/visitors/SyntaxHighlighterVisitorTest.java b/java-frontend/src/test/java/org/sonar/java/ast/visitors/SyntaxHighlighterVisitorTest.java index dea09998bf6..23b99a5183f 100644 --- a/java-frontend/src/test/java/org/sonar/java/ast/visitors/SyntaxHighlighterVisitorTest.java +++ b/java-frontend/src/test/java/org/sonar/java/ast/visitors/SyntaxHighlighterVisitorTest.java @@ -62,8 +62,6 @@ class SyntaxHighlighterVisitorTest { private SyntaxHighlighterVisitor syntaxHighlighterVisitor; - private String eol; - @BeforeEach public void setUp() throws Exception { context = SensorContextTester.create(temp.getRoot()); @@ -85,7 +83,6 @@ void parse_error() throws Exception { @ParameterizedTest @ValueSource(strings = {"\n", "\r\n", "\r"}) void test_different_end_of_line(String eol) throws IOException { - this.eol = eol; InputFile inputFile = generateTestFile("src/test/files/highlighter/Example.java"); scan(inputFile); verifyHighlighting(inputFile); @@ -96,7 +93,6 @@ void test_different_end_of_line(String eol) throws IOException { */ @Test void test_restricted_keywords_within_module() throws Exception { - this.eol = "\n"; InputFile inputFile = generateTestFile("src/test/files/highlighter/module-info.java"); scan(inputFile); @@ -137,7 +133,6 @@ void test_restricted_keywords_within_module() throws Exception { @Test void test_restricted_keywords_outside_module() throws Exception { - this.eol = "\n"; InputFile inputFile = generateTestFile("src/test/files/highlighter/ExampleWithModuleKeywords.java"); scan(inputFile); @@ -168,7 +163,6 @@ void test_restricted_keywords_outside_module() throws Exception { @Test void test_java10_var() throws Exception { - this.eol = "\n"; InputFile inputFile = generateTestFile("src/test/files/highlighter/Java10Var.java"); scan(inputFile); @@ -184,7 +178,6 @@ void test_java10_var() throws Exception { @Test void text_block() throws Exception { - this.eol = "\n"; InputFile inputFile = generateTestFile("src/test/files/highlighter/TextBlock.java"); scan(inputFile); @@ -198,7 +191,6 @@ void text_block() throws Exception { */ @Test void switch_expression() throws Exception { - this.eol = "\n"; InputFile inputFile = generateTestFile("src/test/files/highlighter/SwitchExpression.java"); scan(inputFile); @@ -214,7 +206,6 @@ void switch_expression() throws Exception { */ @Test void switch_pattern_expression_with_when_keyword() throws Exception { - this.eol = "\n"; InputFile inputFile = generateTestFile("src/test/files/highlighter/SwitchPatternExpression.java"); scan(inputFile); @@ -233,7 +224,6 @@ void switch_pattern_expression_with_when_keyword() throws Exception { */ @Test void records() throws Exception { - this.eol = "\n"; InputFile inputFile = generateTestFile("src/test/files/highlighter/Records.java"); scan(inputFile); @@ -247,7 +237,6 @@ void records() throws Exception { */ @Test void sealed_classes() throws Exception { - this.eol = "\n"; InputFile inputFile = generateTestFile("src/test/files/highlighter/SealedClass.java"); scan(inputFile); diff --git a/java-frontend/src/test/java/org/sonar/java/cfg/CFGTest.java b/java-frontend/src/test/java/org/sonar/java/cfg/CFGTest.java index 204eaf88f4a..e3dc706cffc 100644 --- a/java-frontend/src/test/java/org/sonar/java/cfg/CFGTest.java +++ b/java-frontend/src/test/java/org/sonar/java/cfg/CFGTest.java @@ -448,6 +448,7 @@ public void check(final Tree element) { case RECORD: case ANNOTATION_TYPE: assertThat(((ClassTree) element).simpleName().name()).as("Type name").isEqualTo(name); + break; default: // No need to test any associated symbol for the other cases break; diff --git a/java-frontend/src/test/java/org/sonar/java/model/ExpressionUtilsTest.java b/java-frontend/src/test/java/org/sonar/java/model/ExpressionUtilsTest.java index 18447e387db..9395f5e636f 100644 --- a/java-frontend/src/test/java/org/sonar/java/model/ExpressionUtilsTest.java +++ b/java-frontend/src/test/java/org/sonar/java/model/ExpressionUtilsTest.java @@ -50,23 +50,9 @@ class ExpressionUtilsTest { - private boolean parenthesis(boolean b1, boolean b2) { - return (((b1 && (b2)))); - } - - private void simpleAssignment() { - int x; - x = 14; - (x) = 14; - x += 1; - - int[] y = new int[5]; - y[x] = 42; - } - @Test void test_skip_parenthesis() throws Exception { - File file = new File("src/test/java/org/sonar/java/model/ExpressionUtilsTest.java"); + File file = new File("src/test/files/model/ExpressionUtilsTestSample.java"); CompilationUnitTree tree = JParserTestUtils.parse(file); MethodTree methodTree = (MethodTree) ((ClassTree) tree.types().get(0)).members().get(0); ExpressionTree parenthesis = ((ReturnStatementTree) methodTree.block().body().get(0)).expression(); @@ -79,7 +65,7 @@ void test_skip_parenthesis() throws Exception { @Test void test_simple_assignments() throws Exception { - File file = new File("src/test/java/org/sonar/java/model/ExpressionUtilsTest.java"); + File file = new File("src/test/files/model/ExpressionUtilsTestSample.java"); CompilationUnitTree tree = JParserTestUtils.parse(file); MethodTree methodTree = (MethodTree) ((ClassTree) tree.types().get(0)).members().get(1); List assignments = findAssignmentExpressionTrees(methodTree); diff --git a/java-frontend/src/test/java/org/sonar/java/model/JParserSemanticTest.java b/java-frontend/src/test/java/org/sonar/java/model/JParserSemanticTest.java index 1bb0e22fc46..ffdcaf9bca6 100644 --- a/java-frontend/src/test/java/org/sonar/java/model/JParserSemanticTest.java +++ b/java-frontend/src/test/java/org/sonar/java/model/JParserSemanticTest.java @@ -737,12 +737,12 @@ void expression_super_method_invocation_interface() { MethodTreeImpl forEach = (MethodTreeImpl) c.members().get(0); ExpressionStatementTreeImpl e = (ExpressionStatementTreeImpl) forEach.block().body().get(0); MethodInvocationTreeImpl m = (MethodInvocationTreeImpl) e.expression(); - MemberSelectExpressionTreeImpl iterable_super_forEach = (MemberSelectExpressionTreeImpl) m.methodSelect(); - MemberSelectExpressionTreeImpl iterable_super = (MemberSelectExpressionTreeImpl) iterable_super_forEach.expression(); - IdentifierTreeImpl super_keyword = (IdentifierTreeImpl) iterable_super.identifier(); + MemberSelectExpressionTreeImpl iterableSuperForeach = (MemberSelectExpressionTreeImpl) m.methodSelect(); + MemberSelectExpressionTreeImpl iterableSuper = (MemberSelectExpressionTreeImpl) iterableSuperForeach.expression(); + IdentifierTreeImpl superKeyword = (IdentifierTreeImpl) iterableSuper.identifier(); - assertThat(super_keyword.typeBinding).isNotNull(); - assertThat(super_keyword.symbolType().fullyQualifiedName()).isEqualTo("java.lang.Iterable"); + assertThat(superKeyword.typeBinding).isNotNull(); + assertThat(superKeyword.symbolType().fullyQualifiedName()).isEqualTo("java.lang.Iterable"); } @Test diff --git a/java-frontend/src/test/java/org/sonar/java/model/JParserTest.java b/java-frontend/src/test/java/org/sonar/java/model/JParserTest.java index 28ff34dd0b1..d91bb1d9ed6 100644 --- a/java-frontend/src/test/java/org/sonar/java/model/JParserTest.java +++ b/java-frontend/src/test/java/org/sonar/java/model/JParserTest.java @@ -589,7 +589,7 @@ private static void add(File source, File baseDir, JarOutputStream target) { } target.closeEntry(); } catch (Exception ignored) { - + // ignored exception } finally { if (in != null) { try { diff --git a/java-frontend/src/test/java/org/sonar/java/model/JUtilsTest.java b/java-frontend/src/test/java/org/sonar/java/model/JUtilsTest.java index e7dfc8f388b..6d8d175f79c 100644 --- a/java-frontend/src/test/java/org/sonar/java/model/JUtilsTest.java +++ b/java-frontend/src/test/java/org/sonar/java/model/JUtilsTest.java @@ -99,8 +99,8 @@ void not_a_wrapper() { @Test void not_a_class() { - Type ObjectArrayType = SEMA.type(SEMA.resolveType("java.lang.Object[]")); - assertThat(ObjectArrayType.isPrimitiveWrapper()).isFalse(); + Type objectArrayType = SEMA.type(SEMA.resolveType("java.lang.Object[]")); + assertThat(objectArrayType.isPrimitiveWrapper()).isFalse(); } } diff --git a/java-frontend/src/test/java/org/sonar/java/model/SyntacticEquivalenceTest.java b/java-frontend/src/test/java/org/sonar/java/model/SyntacticEquivalenceTest.java index 1792b3e4ce9..e47a5d6b40c 100644 --- a/java-frontend/src/test/java/org/sonar/java/model/SyntacticEquivalenceTest.java +++ b/java-frontend/src/test/java/org/sonar/java/model/SyntacticEquivalenceTest.java @@ -258,7 +258,6 @@ private void assertAreNotEquivalent(String statement1, String statement2) { } private AbstractBooleanAssert getAssertion(List statement1, List statement2) { - ; CompilationUnitTree compilationUnitTree = compilationUnitTree("class A { void method1() { " + String.join(";", statement1) + ";} " + "void method2(){ " + String.join(";", statement2) + ";} }"); ClassTree classTree = ((ClassTree) compilationUnitTree.types().get(0)); diff --git a/java-frontend/src/test/java/org/sonar/java/model/VisitorsBridgeTest.java b/java-frontend/src/test/java/org/sonar/java/model/VisitorsBridgeTest.java index 3c133780af3..fb9e8ce62d7 100644 --- a/java-frontend/src/test/java/org/sonar/java/model/VisitorsBridgeTest.java +++ b/java-frontend/src/test/java/org/sonar/java/model/VisitorsBridgeTest.java @@ -39,7 +39,6 @@ import org.sonar.api.testfixtures.log.LogTesterJUnit5; import org.sonar.java.AnalysisException; import org.sonar.java.CheckFailureException; -import org.sonar.plugins.java.api.JavaVersionAwareVisitor; import org.sonar.java.SonarComponents; import org.sonar.java.TestUtils; import org.sonar.java.ast.visitors.SubscriptionVisitor; @@ -52,6 +51,7 @@ import org.sonar.plugins.java.api.JavaFileScanner; import org.sonar.plugins.java.api.JavaFileScannerContext; import org.sonar.plugins.java.api.JavaVersion; +import org.sonar.plugins.java.api.JavaVersionAwareVisitor; import org.sonar.plugins.java.api.ModuleScannerContext; import org.sonar.plugins.java.api.caching.CacheContext; import org.sonar.plugins.java.api.internal.EndOfAnalysis; @@ -236,6 +236,7 @@ void filter_scanner_by_java_version() { class RuleForAllJavaVersion implements JavaFileScanner, EndOfAnalysis { @Override public void scanFile(JavaFileScannerContext context) { + //empty implementation } @Override @@ -251,6 +252,7 @@ public boolean isCompatibleWithJavaVersion(JavaVersion version) { @Override public void scanFile(JavaFileScannerContext context) { + //empty implementation } @Override diff --git a/java-frontend/src/test/java/org/sonar/java/model/expression/AssessableExpressionTreeTest.java b/java-frontend/src/test/java/org/sonar/java/model/expression/AssessableExpressionTreeTest.java index 39bd548e9f9..0040a5f8126 100644 --- a/java-frontend/src/test/java/org/sonar/java/model/expression/AssessableExpressionTreeTest.java +++ b/java-frontend/src/test/java/org/sonar/java/model/expression/AssessableExpressionTreeTest.java @@ -102,7 +102,7 @@ private ExpressionTree expression(String expressionAsString) { } private ClassTree parse() { - File file = new File("src/test/java/org/sonar/java/model/expression/ClassWithConstants.java"); + File file = new File("src/test/files/model/expression/ClassWithConstants.java"); CompilationUnitTree tree = JParserTestUtils.parse(file); return (ClassTree) tree.types().get(0); } diff --git a/java-frontend/src/test/java/org/sonar/java/model/location/InternalRangeTest.java b/java-frontend/src/test/java/org/sonar/java/model/location/InternalRangeTest.java index d99273609ab..c28ca3edf86 100644 --- a/java-frontend/src/test/java/org/sonar/java/model/location/InternalRangeTest.java +++ b/java-frontend/src/test/java/org/sonar/java/model/location/InternalRangeTest.java @@ -61,16 +61,16 @@ void equals() { Position p2 = Position.at(43, 17); Position p3 = Position.at(44, 1); - Range range_1_3 = Range.at(p1, p3); + Range range1to3 = Range.at(p1, p3); - assertThat(range_1_3.equals(Range.at(p1, p3))).isTrue(); - assertThat(range_1_3).hasSameHashCodeAs(Range.at(p1, p3)); + assertThat(range1to3.equals(Range.at(p1, p3))).isTrue(); + assertThat(range1to3).hasSameHashCodeAs(Range.at(p1, p3)); - assertThat(range_1_3.equals(range_1_3)).isTrue(); - assertThat(range_1_3.equals(Range.at(p1, p2))).isFalse(); - assertThat(range_1_3.equals(Range.at(p2, p3))).isFalse(); - assertThat(range_1_3.equals(null)).isFalse(); - assertThat(range_1_3.equals(new Object())).isFalse(); + assertThat(range1to3.equals(range1to3)).isTrue(); + assertThat(range1to3.equals(Range.at(p1, p2))).isFalse(); + assertThat(range1to3.equals(Range.at(p2, p3))).isFalse(); + assertThat(range1to3.equals(null)).isFalse(); + assertThat(range1to3.equals(new Object())).isFalse(); } diff --git a/java-frontend/src/test/java/org/sonar/java/model/statement/ContinueStatementTreeImplTest.java b/java-frontend/src/test/java/org/sonar/java/model/statement/ContinueStatementTreeImplTest.java index 67f4abe2906..695ad9f3046 100644 --- a/java-frontend/src/test/java/org/sonar/java/model/statement/ContinueStatementTreeImplTest.java +++ b/java-frontend/src/test/java/org/sonar/java/model/statement/ContinueStatementTreeImplTest.java @@ -19,20 +19,19 @@ */ package org.sonar.java.model.statement; +import java.util.ArrayList; import org.junit.jupiter.api.Test; import org.sonar.java.ast.api.JavaKeyword; import org.sonar.java.model.InternalSyntaxToken; import org.sonar.java.model.expression.IdentifierTreeImpl; import org.sonar.plugins.java.api.tree.Tree; -import java.util.ArrayList; - import static org.assertj.core.api.Assertions.assertThat; class ContinueStatementTreeImplTest { - private static InternalSyntaxToken CONTINUE_TOKEN = createToken(JavaKeyword.CONTINUE.getValue()); - private static InternalSyntaxToken SEMICOLON_TOKEN = createToken(":"); + private static final InternalSyntaxToken CONTINUE_TOKEN = createToken(JavaKeyword.CONTINUE.getValue()); + private static final InternalSyntaxToken SEMICOLON_TOKEN = createToken(":"); @Test void test_no_label() { diff --git a/java-frontend/src/test/java/org/sonar/java/regex/RegexCheckTest.java b/java-frontend/src/test/java/org/sonar/java/regex/RegexCheckTest.java index e0fdcd8df52..e0665b2c6fd 100644 --- a/java-frontend/src/test/java/org/sonar/java/regex/RegexCheckTest.java +++ b/java-frontend/src/test/java/org/sonar/java/regex/RegexCheckTest.java @@ -64,34 +64,34 @@ void testTextSpansBetweenRegexSyntaxElement() { List items = ((SequenceTree) regex).getItems(); assertThat(items).hasSize(4); - RegexTree A = items.get(0); - RegexTree B = items.get(1); - RegexTree C = items.get(2); - RegexTree D = items.get(3); - - List AB = correspondingTextSpans(Arrays.asList(A,B)); - assertThat(AB).hasSize(1); - TextSpan ABTestSpan = AB.get(0); - - assertThat(ABTestSpan.startCharacter).isEqualTo(1); - assertThat(ABTestSpan.endCharacter).isEqualTo(3); - - List BCD = correspondingTextSpans(Arrays.asList(B, C, D)); - assertThat(BCD).hasSize(1); - TextSpan BCDTestSpan = BCD.get(0); - - assertThat(BCDTestSpan.startCharacter).isEqualTo(2); - assertThat(BCDTestSpan.endCharacter).isEqualTo(5); - - List BD = correspondingTextSpans(Arrays.asList(B, D)); - assertThat(BD).hasSize(2); - TextSpan BTestSpan = BD.get(0); - TextSpan DTestSpan = BD.get(1); - - assertThat(BTestSpan.startCharacter).isEqualTo(2); - assertThat(BTestSpan.endCharacter).isEqualTo(3); - assertThat(DTestSpan.startCharacter).isEqualTo(4); - assertThat(DTestSpan.endCharacter).isEqualTo(5); + RegexTree regexTreeA = items.get(0); + RegexTree regexTreeB = items.get(1); + RegexTree regexTreeC = items.get(2); + RegexTree regexTreeD = items.get(3); + + List textSpans = correspondingTextSpans(Arrays.asList(regexTreeA,regexTreeB)); + assertThat(textSpans).hasSize(1); + TextSpan aBTextSpan = textSpans.get(0); + + assertThat(aBTextSpan.startCharacter).isEqualTo(1); + assertThat(aBTextSpan.endCharacter).isEqualTo(3); + + List textSpans2 = correspondingTextSpans(Arrays.asList(regexTreeB, regexTreeC, regexTreeD)); + assertThat(textSpans2).hasSize(1); + TextSpan bCDTextSpan = textSpans2.get(0); + + assertThat(bCDTextSpan.startCharacter).isEqualTo(2); + assertThat(bCDTextSpan.endCharacter).isEqualTo(5); + + List textSpans3 = correspondingTextSpans(Arrays.asList(regexTreeB, regexTreeD)); + assertThat(textSpans3).hasSize(2); + TextSpan bTestSpan = textSpans3.get(0); + TextSpan dTestSpan = textSpans3.get(1); + + assertThat(bTestSpan.startCharacter).isEqualTo(2); + assertThat(bTestSpan.endCharacter).isEqualTo(3); + assertThat(dTestSpan.startCharacter).isEqualTo(4); + assertThat(dTestSpan.endCharacter).isEqualTo(5); } diff --git a/java-frontend/src/test/java/org/sonar/java/testing/VisitorsBridgeForTestsTest.java b/java-frontend/src/test/java/org/sonar/java/testing/VisitorsBridgeForTestsTest.java index 2ecce90b9da..54959f502a1 100644 --- a/java-frontend/src/test/java/org/sonar/java/testing/VisitorsBridgeForTestsTest.java +++ b/java-frontend/src/test/java/org/sonar/java/testing/VisitorsBridgeForTestsTest.java @@ -118,6 +118,7 @@ void lastCreatedModuleContext_returns_last_created_module_context() { private static class DummyVisitor implements JavaFileScanner { @Override public void scanFile(JavaFileScannerContext context) { + // empty implementation } } } diff --git a/java-symbolic-execution/java-symbolic-execution-plugin/src/test/files/model/SEExpressionUtilsTestSample.java b/java-symbolic-execution/java-symbolic-execution-plugin/src/test/files/model/SEExpressionUtilsTestSample.java new file mode 100644 index 00000000000..20234cf6004 --- /dev/null +++ b/java-symbolic-execution/java-symbolic-execution-plugin/src/test/files/model/SEExpressionUtilsTestSample.java @@ -0,0 +1,24 @@ +class SEExpressionUtilsTestSample { + + private boolean parenthesis(boolean b1, boolean b2) { + return (((b1 && (b2)))); + } + + private void simpleAssignment() { + int x; + x = 14; + (x) = 14; + x += 1; + + int[] y = new int[5]; + y[x] = 42; + } + + class MethodName { + public void foo() { + foo(); + this.foo(); + } + } + +} diff --git a/java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/model/SEExpressionUtilsTest.java b/java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/model/SEExpressionUtilsTest.java index bc49de8216b..45598b2d70c 100644 --- a/java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/model/SEExpressionUtilsTest.java +++ b/java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/model/SEExpressionUtilsTest.java @@ -45,28 +45,7 @@ class SEExpressionUtilsTest { - private boolean parenthesis(boolean b1, boolean b2) { - return (((b1 && (b2)))); - } - - private void simpleAssignment() { - int x; - x = 14; - (x) = 14; - x += 1; - - int[] y = new int[5]; - y[x] = 42; - } - - class MethodName { - public void foo() { - foo(); - this.foo(); - } - } - - CompilationUnitTree classTree = JParserTestUtils.parse(new File("src/test/java/org/sonar/java/model/SEExpressionUtilsTest.java")); + CompilationUnitTree classTree = JParserTestUtils.parse(new File("src/test/files/model/SEExpressionUtilsTestSample.java")); @Test void test_skip_parenthesis() { diff --git a/java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/se/xproc/HappyPathYieldTest.java b/java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/se/xproc/HappyPathYieldTest.java index 9dfd7dd6e7e..edd393c9803 100644 --- a/java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/se/xproc/HappyPathYieldTest.java +++ b/java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/se/xproc/HappyPathYieldTest.java @@ -19,16 +19,14 @@ */ package org.sonar.java.se.xproc; +import java.util.Set; +import java.util.stream.Collectors; import org.junit.jupiter.api.Test; - import org.sonar.java.se.SymbolicExecutionVisitor; import org.sonar.java.se.checks.NullDereferenceCheck; import org.sonar.java.se.constraint.ConstraintsByDomain; import org.sonar.java.se.constraint.ObjectConstraint; -import java.util.Set; -import java.util.stream.Collectors; - import static org.assertj.core.api.Assertions.assertThat; import static org.sonar.java.se.utils.SETestUtils.createSymbolicExecutionVisitor; import static org.sonar.java.se.utils.SETestUtils.getMethodBehavior; @@ -36,7 +34,7 @@ class HappyPathYieldTest { - ConstraintsByDomain NOT_NULL_CONSTRAINT = ConstraintsByDomain.empty().put(ObjectConstraint.NOT_NULL); + private static final ConstraintsByDomain NOT_NULL_CONSTRAINT = ConstraintsByDomain.empty().put(ObjectConstraint.NOT_NULL); @Test void test_equals() { diff --git a/java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/se/xproc/MethodBehaviorTest.java b/java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/se/xproc/MethodBehaviorTest.java index 4edb767460b..69e6ae57ae5 100644 --- a/java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/se/xproc/MethodBehaviorTest.java +++ b/java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/se/xproc/MethodBehaviorTest.java @@ -184,9 +184,7 @@ void equality() { addYield(sameYields, ObjectConstraint.NOT_NULL); addYield(sameYields, ObjectConstraint.NULL); - MethodBehavior differentType = new MethodBehavior("foo()Ljava/lang/Object;", false) { - private Object o = new Object(); - }; + MethodBehavior differentType = new MethodBehavior("foo()Ljava/lang/Object;", false) {}; addYield(differentType, ObjectConstraint.NOT_NULL); addYield(differentType, ObjectConstraint.NULL);