fix: simplify AssertJ File assertions in FileLocationTest#409
fix: simplify AssertJ File assertions in FileLocationTest#409sonarqube-agent[bot] wants to merge 1 commit into
Conversation
Fixed issues: - AZl2kM_eTJNPgjOVPf12 for java:S5838 rule - AZl2kM_eTJNPgjOVPf13 for java:S5838 rule - AZl2kM_eTJNPgjOVPf14 for java:S5838 rule - AZl2kM_eTJNPgjOVPf10 for java:S5838 rule - AZl2kM_eTJNPgjOVPf11 for java:S5838 rule Generated by SonarQube Agent (task: 06f732a7-85e1-4c17-bb45-7a7e8c04b430)
Summary
This PR replaces 5 generic AssertJ assertions with dedicated File assertion methods across two test methods in FileLocationTest (lines 80–81 and 89–91). The changes are mechanical refactoring with identical semantics—no test logic is altered. Specifically:
These simplifications leverage AssertJ's File-specific APIs for clearer, more maintainable test code. What reviewers should knowVerification is straightforward: Each change replaces a property extraction + generic assertion with a single dedicated method. The behavior is identical in all cases—just using the right AssertJ API. Two test methods affected:
Note: Line 79 in the second test method uses
|
| @@ -77,18 +77,18 @@ public void ofSharedWithEnv() throws URISyntaxException { | |||
|
|
|||
| FileLocation location = FileLocation.ofShared("abap/foo.txt"); | |||
| assertThat(location.getFile().isFile()).isTrue(); | |||
There was a problem hiding this comment.
This line still uses the old pattern (assertThat(file.isFile()).isTrue()) that this PR is explicitly fixing. The identical assertion on line 89 in the second test method was migrated to assertThat(location.getFile()).isFile(), but this one was skipped. The fix is incomplete and leaves a live S5838 issue behind.
| assertThat(location.getFile().isFile()).isTrue(); | |
| assertThat(location.getFile()).isFile(); |
|





Refactored File-related assertions in FileLocationTest to use AssertJ's dedicated File assertion methods instead of extracting properties and comparing with generic assertions. This improves code readability and follows AssertJ best practices by using specialized assertions like exists(), isFile(), and hasName() instead of chaining method calls with isTrue() and isEqualTo().
View Project in SonarCloud
Fixed Issues
java:S5838 - Use assertThat(actual).exists() instead. • MINOR • View issue
Location:
orchestrator-parent:sonar-orchestrator-locators/src/test/java/com/sonar/orchestrator/locator/FileLocationTest.java:80Why is this an issue?
AssertJ contains many assertions methods specific to common types. Both versions will test the same things, but the dedicated one will provide a better error message, simplifying the debugging process.
What changed
This hunk fixes two AssertJ assertion simplification issues at lines 80-81. First, it replaces
assertThat(location.getFile().exists()).isTrue()withassertThat(location.getFile()).exists(), using the dedicated File assertion method instead of checking the boolean result. Second, it replacesassertThat(location.getFile().getName()).isEqualTo("foo.txt")withassertThat(location.getFile()).hasName("foo.txt"), using the dedicatedhasName()assertion instead of extracting the name and comparing withisEqualTo().java:S5838 - Use assertThat(actual).hasName(expected) instead. • MINOR • View issue
Location:
orchestrator-parent:sonar-orchestrator-locators/src/test/java/com/sonar/orchestrator/locator/FileLocationTest.java:81Why is this an issue?
AssertJ contains many assertions methods specific to common types. Both versions will test the same things, but the dedicated one will provide a better error message, simplifying the debugging process.
What changed
This hunk fixes two AssertJ assertion simplification issues at lines 80-81. First, it replaces
assertThat(location.getFile().exists()).isTrue()withassertThat(location.getFile()).exists(), using the dedicated File assertion method instead of checking the boolean result. Second, it replacesassertThat(location.getFile().getName()).isEqualTo("foo.txt")withassertThat(location.getFile()).hasName("foo.txt"), using the dedicatedhasName()assertion instead of extracting the name and comparing withisEqualTo().java:S5838 - Use assertThat(actual).isFile() instead. • MINOR • View issue
Location:
orchestrator-parent:sonar-orchestrator-locators/src/test/java/com/sonar/orchestrator/locator/FileLocationTest.java:89Why is this an issue?
AssertJ contains many assertions methods specific to common types. Both versions will test the same things, but the dedicated one will provide a better error message, simplifying the debugging process.
What changed
This hunk fixes three AssertJ assertion simplification issues at lines 89-91. First, it replaces
assertThat(location.getFile().isFile()).isTrue()withassertThat(location.getFile()).isFile(), using the dedicated File assertion. Second, it replacesassertThat(location.getFile().exists()).isTrue()withassertThat(location.getFile()).exists(), using the dedicated existence assertion. Third, it replacesassertThat(location.getFile().getName()).isEqualTo("foo.txt")withassertThat(location.getFile()).hasName("foo.txt"), using the dedicatedhasName()assertion instead of extracting the name and comparing withisEqualTo().java:S5838 - Use assertThat(actual).exists() instead. • MINOR • View issue
Location:
orchestrator-parent:sonar-orchestrator-locators/src/test/java/com/sonar/orchestrator/locator/FileLocationTest.java:90Why is this an issue?
AssertJ contains many assertions methods specific to common types. Both versions will test the same things, but the dedicated one will provide a better error message, simplifying the debugging process.
What changed
This hunk fixes three AssertJ assertion simplification issues at lines 89-91. First, it replaces
assertThat(location.getFile().isFile()).isTrue()withassertThat(location.getFile()).isFile(), using the dedicated File assertion. Second, it replacesassertThat(location.getFile().exists()).isTrue()withassertThat(location.getFile()).exists(), using the dedicated existence assertion. Third, it replacesassertThat(location.getFile().getName()).isEqualTo("foo.txt")withassertThat(location.getFile()).hasName("foo.txt"), using the dedicatedhasName()assertion instead of extracting the name and comparing withisEqualTo().java:S5838 - Use assertThat(actual).hasName(expected) instead. • MINOR • View issue
Location:
orchestrator-parent:sonar-orchestrator-locators/src/test/java/com/sonar/orchestrator/locator/FileLocationTest.java:91Why is this an issue?
AssertJ contains many assertions methods specific to common types. Both versions will test the same things, but the dedicated one will provide a better error message, simplifying the debugging process.
What changed
This hunk fixes three AssertJ assertion simplification issues at lines 89-91. First, it replaces
assertThat(location.getFile().isFile()).isTrue()withassertThat(location.getFile()).isFile(), using the dedicated File assertion. Second, it replacesassertThat(location.getFile().exists()).isTrue()withassertThat(location.getFile()).exists(), using the dedicated existence assertion. Third, it replacesassertThat(location.getFile().getName()).isEqualTo("foo.txt")withassertThat(location.getFile()).hasName("foo.txt"), using the dedicatedhasName()assertion instead of extracting the name and comparing withisEqualTo().SonarQube Remediation Agent uses AI. Check for mistakes.