Title: Tests pin the formatter's pieces, not the routes users run · Issue #225 · openjavaformat/open-java-format · GitHub
Open Graph Title: Tests pin the formatter's pieces, not the routes users run · Issue #225 · openjavaformat/open-java-format
X Title: Tests pin the formatter's pieces, not the routes users run · Issue #225 · openjavaformat/open-java-format
Description: What happens The tests that pin what the formatter writes call pieces of it, not the routes users run, so two routes could drift apart without a test failing (#219). Tests What they call What users run FormatterCasesTest, 915 cases Forma...
Open Graph Description: What happens The tests that pin what the formatter writes call pieces of it, not the routes users run, so two routes could drift apart without a test failing (#219). Tests What they call What users...
X Description: What happens The tests that pin what the formatter writes call pieces of it, not the routes users run, so two routes could drift apart without a test failing (#219). Tests What they call What users...
Opengraph URL: https://github.com/openjavaformat/open-java-format/issues/225
X: @github
Domain: redirect.github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Tests pin the formatter's pieces, not the routes users run","articleBody":"### What happens\n\nThe tests that pin what the formatter writes call pieces of it, not the routes users run, so two routes could drift apart without a test failing (#219).\n\n| Tests | What they call | What users run |\n|---|---|---|\n| `FormatterCasesTest`, 915 cases | `Formatter.formatSourceAndFixImports` | the Maven plugin and the Spotless step; the command line, the native binary and the GitHub Action go through `FormatFileCallable.formatFile`, a second implementation of the same steps |\n| `PartialFormattingTest`, 60 tests | `Main --lines` without `--output-replacements`, and `Formatter.getFormatReplacements` | IntelliJ IDEA and `formatDiff` use `--output-replacements` and `FormatterService.getFormatReplacements`; before #220 no test ran `--output-replacements` |\n| `FormatterIntegrationTest`, 2 pairs left | `formatSource` and then `StringWrapper.wrap`, put together in the test | no route |\n\nThe cases also never reach the places where the routes differ: all 915 give their expected output with the imports fixed before formatting and after it. The one test that did, `ModuleImportTest.keepsACommentBetweenThePartsOfTheModuleName`, pinned what `formatSourceAndFixImports` wrote, which the command line never printed.\n\nAnd the tests that need a newer JDK are skipped on JDK 21, where a local build runs: 14 skipped there against 2 on JDK 25. The first push of #220 passed locally and failed CI's JDK 25 to 28 builds on that `ModuleImportTest`.\n\n### Proposal\n\n1. **One implementation.** `FormatFileCallable.formatFile` calls the same method as `formatSourceAndFixImports`, with the flags of the command line, as google-java-format now does with one `Formatter.formatSource(input, ranges, removeUnusedImports, sortImports, reflowLongStrings)`. Then the 915 cases test the command line.\n2. **Cases for the seams.** Four cases are ready for `test-cases/imports`: `commentOfARemovedImportGoesWithTheImportAboveIt`, `commentOfARemovedOwnPackageImportGoesWithTheImportAboveIt`, `commentUnderARemovedImportStaysOnTheClass` and `semicolonAfterTheLastImportStaysOnALineOfItsOwn`. Each passes with #220 and fails with the imports fixed first. What a case file cannot say yet, a failure, a JDK it needs, a range, stays in `FormatterServiceImplTest` and `ModuleImportTest`.\n3. **Cases through the routes.** `FormatterCasesTest` runs each case through `Main`, through `FormatterServiceImpl`, and in CI's native jobs through the native binary.\n4. **Ranges on the cases.** For each case, the lines where the code before and after differ are formatted as a range, as `formatDiff` does, through `--output-replacements` and through the in-process service, and the two compared; and formatting any range of the expected output leaves it as it is.\n5. **A rule and a task.** CLAUDE.md says that a test which pins the output users get goes through `Main` or `FormatterService`, while `ImportOrderer`, `RemoveUnusedImports` and `StringWrapper` keep their unit tests. A mise task runs the tests as CI's JDK 25 and 27 builds do, with their TestKit Gradle versions.\n","author":{"url":"https://github.com/abashev","@type":"Person","name":"abashev"},"datePublished":"2026-11-13T20:36:27Z","url":"https://github.com/openjavaformat/open-java-format/issues/225"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a50b0682-a56e-c828-b6e4-bd22671dbf1f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9D58:363B1C:25F7D:320C7:6AFBD805 |
| html-safe-nonce | 237f736397dd63ee9af42221607a6cedf99e999c2b3b05e61001ff35ff390862 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RDU4OjM2M0IxQzoyNUY3RDozMjBDNzo2QUZCRDgwNSIsInZpc2l0b3JfaWQiOiI3ODI5Njc1MzYzMjEzNzYwNTE3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | b70f1d9d0964db904d6454d6b74bdd6adcb669cbcd1f41bf67ce98b37f710061 |
| hovercard-subject-tag | issue:6379516442 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/openjavaformat/open-java-format/225/issue_layout |
| twitter:image | https://opengraph.githubassets.com/003618937ef49d331dcaefbb2bf5a0e9c3160dc814a7788c2df0a05d6904a09f/openjavaformat/open-java-format/issues/225 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/003618937ef49d331dcaefbb2bf5a0e9c3160dc814a7788c2df0a05d6904a09f/openjavaformat/open-java-format/issues/225 |
| og:image:alt | What happens The tests that pin what the formatter writes call pieces of it, not the routes users run, so two routes could drift apart without a test failing (#219). Tests What they call What users... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | abashev |
| hostname | github.com |
| expected-hostname | github.com |
| None | 18742cb872ec73544356e60359266b67aafece70c4ce008042e06227924cdd07 |
| turbo-cache-control | no-preview |
| go-import | github.com/openjavaformat/open-java-format git https://github.com/openjavaformat/open-java-format.git |
| octolytics-dimension-user_id | 325177626 |
| octolytics-dimension-user_login | openjavaformat |
| octolytics-dimension-repository_id | 1288055459 |
| octolytics-dimension-repository_nwo | openjavaformat/open-java-format |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | true |
| octolytics-dimension-repository_parent_id | 214273098 |
| octolytics-dimension-repository_parent_nwo | palantir/palantir-java-format |
| octolytics-dimension-repository_network_root_id | 214273098 |
| octolytics-dimension-repository_network_root_nwo | palantir/palantir-java-format |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 820be804f18e1ef3940bd74a00d41d73d02e2b91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width