-
Notifications
You must be signed in to change notification settings - Fork 688
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONARJAVA-5256 Generalize the pattern for AssertJ assertions
The previous conditions were too restrictive and there are many assertion methods in AssertJ. They generally follow the patterns that are described here. Note that this introduces a false negative in autoscan tests. Co-authored-by: Alban Auzeill <alban.auzeill@sonarsource.com>
- Loading branch information
1 parent
5218f3a
commit 90e6217
Showing
3 changed files
with
49 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"ruleKey": "S2699", | ||
"hasTruePositives": true, | ||
"falseNegatives": 151, | ||
"falseNegatives": 152, | ||
"falsePositives": 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
java-checks/src/test/java/org/sonar/java/checks/helpers/UnitTestUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* SonarQube Java | ||
* Copyright (C) 2012-2025 SonarSource SA | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource SA. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the Sonar Source-Available License for more details. | ||
* | ||
* You should have received a copy of the Sonar Source-Available License | ||
* along with this program; if not, see https://sonarsource.com/license/ssal/ | ||
*/ | ||
package org.sonar.java.checks.helpers; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.function.Predicate; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
|
||
class UnitTestUtilsTest { | ||
|
||
@Test | ||
void testAssertJAssertionMethodPattern() { | ||
Predicate<String> predicate = UnitTestUtils.ASSERTJ_ASSERTION_METHODS_PATTERN.asMatchPredicate(); | ||
assertTrue(predicate.test("returns")); | ||
assertTrue(predicate.test("contains")); | ||
assertFalse(predicate.test("doesNot")); | ||
assertTrue(predicate.test("containsAString")); | ||
assertTrue(predicate.test("doesNotThrow")); | ||
assertFalse(predicate.test("allMatchFoo")); | ||
assertFalse(predicate.test("hasten")); | ||
} | ||
} |