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: 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:c771dcee-6e73-5822-8d38-3e70da5ceef2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D7AA:13F309:2B1E33:3903A5:6AFBB798 |
| html-safe-nonce | 49d217e1e4180d684a7f8f4dd51f9cfa68045b25620b2de13be3524e5d12425f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEN0FBOjEzRjMwOToyQjFFMzM6MzkwM0E1OjZBRkJCNzk4IiwidmlzaXRvcl9pZCI6Ijg4MjcxMjE4MzA1NDkyMzk3MDQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | ddc57c2f5a2dda920dcb34b7c9d2a7cdac344dc47e649c00db7e2e682b46914e |
| 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 | 2b2ef9c1578c18d8ed27027940544c958743213cf4461659f14d3ccdf51e162c |
| 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 | e4cce0e99cf61481a318ff12c2e8580153a6c7c6 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width