-
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-5111 S5838 Improve quickfix directly to isEmpty()
- Loading branch information
1 parent
9bfb7e6
commit 8333a7d
Showing
5 changed files
with
86 additions
and
6 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
its/autoscan/src/test/resources/autoscan/diffs/diff_S5838.json
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": "S5838", | ||
"hasTruePositives": false, | ||
"falseNegatives": 274, | ||
"falseNegatives": 280, | ||
"falsePositives": 0 | ||
} | ||
} |
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
46 changes: 46 additions & 0 deletions
46
.../default/src/test/java/checks/tests/AssertJChainSimplificationCheckTest_ListQuickFix.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,46 @@ | ||
package checks.tests; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class AssertJChainSimplificationCheckTest_ListQuickFix { | ||
|
||
List<String> stringsList = new ArrayList<>(); | ||
String[] stringArray = new String[0]; | ||
String string = new String(); | ||
|
||
// test https://sonarsource.atlassian.net/browse/SONARJAVA-5111 | ||
void contextFreeQuickFixes() { | ||
|
||
assertThat(stringsList).isEmpty(); // Compliant | ||
assertThat(stringsList.hashCode()).isEqualTo(0); // Noncompliant {{Use isZero() instead.}} | ||
|
||
assertThat(stringsList.size()).isEqualTo(0); // Noncompliant {{Use assertThat(actual).isEmpty() instead.}} [[quickfixes=qf_context1]] | ||
// ^^^^^^^^^ | ||
// fix@qf_context1 {{Use "assertThat(actual).isEmpty()"}} | ||
// edit@qf_context1 [[sc=27;ec=34]] {{}} | ||
// edit@qf_context1 [[sc=36;ec=48]] {{isEmpty()}} | ||
|
||
assertThat(string).isEmpty(); // Compliant | ||
assertThat(string.hashCode()).isEqualTo(0); // Noncompliant {{Use isZero() instead.}} | ||
|
||
assertThat(string.length()).isEqualTo(0); // Noncompliant {{Use assertThat(actual).isEmpty() instead.}} [[quickfixes=qf_context2]] | ||
// ^^^^^^^^^ | ||
// fix@qf_context2 {{Use "assertThat(actual).isEmpty()"}} | ||
// edit@qf_context2 [[sc=22;ec=31]] {{}} | ||
// edit@qf_context2 [[sc=33;ec=45]] {{isEmpty()}} | ||
|
||
assertThat(stringArray).isEmpty(); // Compliant | ||
assertThat(stringArray.hashCode()).isEqualTo(0); // Noncompliant {{Use isZero() instead.}} | ||
|
||
assertThat(stringArray.length).isEqualTo(0); // Noncompliant {{Use assertThat(actual).isEmpty() instead.}} [[quickfixes=qf_context3]] | ||
// ^^^^^^^^^ | ||
// fix@qf_context3 {{Use "assertThat(actual).isEmpty()"}} | ||
// edit@qf_context3 [[sc=27;ec=34]] {{}} | ||
// edit@qf_context3 [[sc=36;ec=48]] {{isEmpty()}} | ||
|
||
} | ||
|
||
} |
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
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