Skip to content

UseAssertSame changes numeric equality to object identity equality #991

@protocol7

Description

@protocol7

What version of OpenRewrite are you using?

  • rewrite-core 8.81.4
  • rewrite-testing-frameworks 3.35.2

What is the smallest, simplest way to reproduce the problem?

@Test
void useAssertSameChangesBoxedNumericValueEquality() {
  rewriteRun(
      spec -> spec.recipe(new UseAssertSame()),
      java(
          """
          package com.helloworld;

          import static org.junit.jupiter.api.Assertions.assertTrue;

          class ExampleTest {
            void test() {
              assertTrue(123L == 123);
            }
          }
          """));
}

What did you expect to see?

No change. The original assertion uses Java numeric equality:

assertTrue(123L == 123);

This evaluates to true.

What did you see instead?

The recipe changes numeric value equality into object identity equality:

assertSame(123L, 123);

This assertion fails because the arguments are boxed as Long and Integer, which are different object types.

What is the full stack trace of any errors you encountered?

When the rewritten test is executed, JUnit fails with an assertion error like:

org.opentest4j.AssertionFailedError: expected: java.lang.Long<123> but was: java.lang.Integer<123>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions