Skip to content

test: improve SourceRoot coverage and apply spotless formatting #4795#4881

Merged
jlerbsc merged 5 commits intojavaparser:masterfrom
Joyce-5:fix/source-root-tests
Oct 22, 2025
Merged

test: improve SourceRoot coverage and apply spotless formatting #4795#4881
jlerbsc merged 5 commits intojavaparser:masterfrom
Joyce-5:fix/source-root-tests

Conversation

@Joyce-5
Copy link
Copy Markdown
Contributor

@Joyce-5 Joyce-5 commented Oct 22, 2025

Summary
Improves test coverage for SourceRoot by adding more unit tests covering path resolution and saveAll behavior.
These additions help ensure correct handling of both relative and absolute paths during file saving and normalization.

Details

Added new test cases in SourceRootTest.java to increase branch and path coverage

Verified that saveAll() preserves absolute paths correctly

Applied ./mvnw spotless:apply for consistent formatting

Related issue
#4795

@Joyce-5
Copy link
Copy Markdown
Contributor Author

Joyce-5 commented Oct 22, 2025

Hi!
I’ve followed your feedback carefully and updated the patch accordingly, I’ve added dedicated tests to improve coverage for more relevant cases.
Thank you so much for your detailed guidance earlier, it really helped me understand the expected behavior more clearly.
When you have a moment, could you please take another look and let me know if there’s anything else I should adjust?
Really appreciate your time and patience!


@Test
void saveAllPreservesAbsolutePaths() throws Exception {
Path tmp = Files.createTempDirectory("jp-core-");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not advisable to create temporary directories if they are not deleted after the test.

Files.createDirectories(oldRoot);

SourceRoot sr = new SourceRoot(oldRoot);
CompilationUnit cuRel = new CompilationUnit();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be clearer to parse a string to create your class.

@Joyce-5
Copy link
Copy Markdown
Contributor Author

Joyce-5 commented Oct 22, 2025

Thanks a lot for your suggestion! I’ve updated the test to parse a string when creating the class. Really appreciate your careful review.

Path oldRoot = tmp.resolve("old");
Path newRoot = tmp.resolve("new");

Files.createDirectories(oldRoot);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also a directory created here that is not deleted.

@Joyce-5
Copy link
Copy Markdown
Contributor Author

Joyce-5 commented Oct 22, 2025

Thanks a lot for your suggestion! I’ve fixed the issue and updated the test accordingly. Really appreciate your careful review.

@codecov
Copy link
Copy Markdown

codecov bot commented Oct 22, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.401%. Comparing base (9852c2b) to head (a4b612b).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@               Coverage Diff               @@
##              master     #4881       +/-   ##
===============================================
+ Coverage     58.333%   58.401%   +0.067%     
  Complexity      2535      2535               
===============================================
  Files            677       677               
  Lines          39041     39047        +6     
  Branches        7089      7089               
===============================================
+ Hits           22774     22804       +30     
+ Misses         13368     13343       -25     
- Partials        2899      2900        +1     
Flag Coverage Δ
AlsoSlowTests 58.401% <100.000%> (+0.067%) ⬆️
javaparser-core 58.401% <100.000%> (+0.067%) ⬆️
javaparser-symbol-solver 58.401% <100.000%> (+0.067%) ⬆️
jdk-10 57.966% <100.000%> (+0.067%) ⬆️
jdk-11 57.964% <100.000%> (+0.070%) ⬆️
jdk-12 57.962% <100.000%> (+0.065%) ⬆️
jdk-13 57.964% <100.000%> (+0.067%) ⬆️
jdk-14 58.200% <100.000%> (+0.065%) ⬆️
jdk-15 58.203% <100.000%> (+0.067%) ⬆️
jdk-16 58.177% <100.000%> (+0.070%) ⬆️
jdk-17 58.331% <100.000%> (+0.067%) ⬆️
jdk-18 58.331% <100.000%> (+0.067%) ⬆️
jdk-8 57.965% <100.000%> (+0.067%) ⬆️
jdk-9 57.963% <100.000%> (+0.070%) ⬆️
macos-latest 58.393% <100.000%> (+0.067%) ⬆️
ubuntu-latest 58.388% <100.000%> (+0.067%) ⬆️
windows-latest 58.383% <100.000%> (+0.067%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...n/java/com/github/javaparser/utils/SourceRoot.java 71.782% <100.000%> (+13.108%) ⬆️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 184b05a...a4b612b. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Joyce-5
Copy link
Copy Markdown
Contributor Author

Joyce-5 commented Oct 22, 2025

Hi, I noticed that the Spotless check still failed in CI.
I’ve already run the following commands locally before committing:

./mvnw spotless:apply
./mvnw -DskipITs -Dmaven.compiler.release=11 clean verify

Both commands completed successfully on my side, and no formatting differences were shown afterwards.
Could you please advise why the Spotless check might still be failing on CI?
Maybe there’s a line ending or environment difference between my local setup and the CI runner.

Thanks a lot for your time and help!

@jlerbsc
Copy link
Copy Markdown
Collaborator

jlerbsc commented Oct 22, 2025

You can view the details by clicking on the task in error.

image

@Joyce-5
Copy link
Copy Markdown
Contributor Author

Joyce-5 commented Oct 22, 2025

Thanks a lot for pointing that out!
I’ve fixed the Spotless formatting issue and pushed the update. Really appreciate your help and review

@jlerbsc jlerbsc merged commit b36c8b2 into javaparser:master Oct 22, 2025
35 checks passed
@jlerbsc jlerbsc added this to the next release milestone Oct 22, 2025
@jlerbsc jlerbsc added the PR: Fixed A PR that offers a fix or correction label Oct 22, 2025
@jlerbsc
Copy link
Copy Markdown
Collaborator

jlerbsc commented Oct 22, 2025

Thank you for this contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: Fixed A PR that offers a fix or correction

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants