Skip to content

Cover commented AssertJ tests: array length, Comparable & BigDecimal compareTo#1039

Merged
timtebeek merged 3 commits into
mainfrom
tim/assertj-commented-tests-coverage
Jun 20, 2026
Merged

Cover commented AssertJ tests: array length, Comparable & BigDecimal compareTo#1039
timtebeek merged 3 commits into
mainfrom
tim/assertj-commented-tests-coverage

Conversation

@timtebeek

Copy link
Copy Markdown
Member

Un-comments the disabled cases in AssertJBestPracticesTest and closes the coverage gaps they represented. The Comparable relational operators (>, >=, <, <=) were already handled by AssertJPrimitiveRules and were only disabled because the parameterized test template emitted an invalid import int; for primitive types, which this fixes. A new SimplifyArrayLengthAssertion recipe converts assertThat(array.length) size assertions to dedicated array assertions (isEmpty, hasSize, hasSameSizeAs, hasSize{Less,Greater}Than[OrEqualTo]) for both object and primitive arrays, ordered before AssertJNumberRules to avoid the isGreaterThanOrEqualTo(1)isPositive() collision. A declarative SimplifyChainedAssertJAssertion entry also maps BigDecimal compareTo(y).isZero() to isEqualByComparingTo(y).

Un-comments the disabled cases in AssertJBestPracticesTest and closes the
coverage gaps they represented:

- Comparable relational operators (>, >=, <, <=) were already handled by
  AssertJPrimitiveRules; the cases were only disabled because the test
  template emitted an invalid `import int;` for primitive types. Fix the
  template to skip imports for primitives and strip array brackets.
- Add a SimplifyChainedAssertJAssertion entry mapping BigDecimal
  `compareTo(y).isZero()` to `isEqualByComparingTo(y)`.
- Add SimplifyArrayLengthAssertion to convert `assertThat(array.length)`
  size assertions to dedicated array assertions (isEmpty, hasSize,
  hasSameSizeAs, hasSize{Less,Greater}Than[OrEqualTo]), for both object
  and primitive arrays. Ordered before AssertJNumberRules to avoid the
  `isGreaterThanOrEqualTo(1)` -> `isPositive()` collision.
@timtebeek timtebeek changed the title Cover previously-commented AssertJ best-practice tests Cover commented AssertJ tests: array length, Comparable & BigDecimal compareTo Jun 20, 2026
@timtebeek timtebeek merged commit db78ffd into main Jun 20, 2026
1 check passed
@timtebeek timtebeek deleted the tim/assertj-commented-tests-coverage branch June 20, 2026 14:01
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Jun 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant